linux/net/ncsi
Binbin Deng 9c7e89fc1b ncsi: Fix use-after-free in the VLAN id list removal
ncsi_vlan_rx_kill_vid() removes an entry from the NCSI VLAN list with:

	list_for_each_entry_safe(vlan, tmp, &ndp->vlan_vids, list)
		if (vlan->vid == vid) {
			list_del_rcu(&vlan->list);
			found = true;
			kfree(vlan);
		}

The list is published with list_add_rcu(), so readers traverse it
under rcu_read_lock().  The writer holds only the RTNL, which does not
exclude those readers.  list_for_each_entry_safe() protects the writer
iteration itself, not concurrent readers.

The reader is set_one_vid(), invoked from the NCSI channel
configuration state machine (ndp->work) while sending the "Set VLAN
Filter" command:

	rcu_read_lock();
	list_for_each_entry_rcu(vlan, &ndp->vlan_vids, list) {
		vid = vlan->vid;
		...
	}
	rcu_read_unlock();

An RCU read-side critical section only protects objects released via
call_rcu()/kfree_rcu(); it does not protect against the immediate
kfree() above.  If the state machine work has already obtained the
list entry pointer and is then scheduled out while another CPU removes
the VLAN id, the resumed iteration reads the freed node and follows
the ->next pointer of reused memory.

This is reachable on BMC systems using NCSI when a VLAN id is deleted
(ip link / rtnetlink) concurrently with an NCSI configuration cycle.

Fix this by adding an rcu_head to struct vlan_vid and releasing the
node with kfree_rcu().

Found during a static-analysis-assisted audit: candidate sites were
surfaced by a Coccinelle rule, and the reader/writer paths were
confirmed by LLM-assisted (GLM-5.3) code inspection.  The issue was
not observed at runtime; it is identified by code inspection only.

Cc: stable+noautosel@kernel.org # LLM report + LLM fix, not seen in real life
Fixes: 21acf63013 ("net/ncsi: Configure VLAN tag filter")
Signed-off-by: Binbin Deng <18983559317@163.com>
Link: https://patch.msgid.link/20261010030820.91563-1-18983559317@163.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2026-10-15 18:51:28 -07:00
..
internal.h ncsi: Fix use-after-free in the VLAN id list removal 2026-10-15 18:51:28 -07:00
Kconfig net/ncsi: add NCSI Intel OEM command to keep PHY up 2021-07-08 14:16:39 -07:00
Makefile treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
ncsi-aen.c net: ncsi: fix skb leak in error paths 2026-03-06 17:34:48 -08:00
ncsi-cmd.c net/ncsi: Add NC-SI 1.2 Get MC MAC Address command 2023-11-18 15:00:51 +00:00
ncsi-manage.c ncsi: Fix use-after-free in the VLAN id list removal 2026-10-15 18:51:28 -07:00
ncsi-netlink.c net/ncsi: fix heap OOB read in NCSI_CMD_SEND_CMD payload length 2026-08-05 17:24:57 -07:00
ncsi-netlink.h genetlink: make genl_info->nlhdr const 2023-08-15 14:54:44 -07:00
ncsi-pkt.h net: ncsi: Fix GCPS 64-bit member variables 2025-04-15 15:19:55 +02:00
ncsi-rsp.c net: protocol: use assign_bit() where applicable 2026-09-21 17:18:54 -07:00