* [PATCH net 0/1] switchdev: fix deferred item flex-array allocation size
@ 2026-11-27 6:20 Ren Wei
2026-11-27 6:20 ` [PATCH net 1/1] " Ren Wei
0 siblings, 1 reply; 2+ messages in thread
From: Ren Wei @ 2026-11-27 6:20 UTC (permalink / raw)
To: netdev
Cc: jiri, ivecera, davem, edumazet, kuba, pabeni, willemb, horms,
chi.minghao, vega, caoruide123, weir
From: Ruide Cao <caoruide123@gmail.com>
Hi Linux kernel maintainers,
We found and validated an issue in net/switchdev/switchdev.c. The bug
is reachable by root with CAP_NET_ADMIN. We've tested it, and it should
not affect any other functionality.
This bug is tracked at: https://bugtracker.nebusec.ai/f/10431
We will provide detailed information about the bug in this email.
---- details below ----
Bug details:
switchdev_deferred_enqueue() stores a byte payload in the deferred item
flexible array, and data_len is a byte count. The array is declared as
unsigned long data[], and kmalloc_flex() treats data_len as an element
count, so every deferred attr or object item is allocated
sizeof(unsigned long) times larger than intended (8x on 64-bit). The
subsequent memcpy() copies only data_len bytes, so this is not an
out-of-bounds write; it is an 8x GFP_ATOMIC over-allocation that makes
those atomic allocations more likely to fail.
This patch declares the payload as u8 data[] __aligned(sizeof(unsigned
long)). The offset of data does not change, because the preceding
members are pointers (or an empty tracker). The aligned attribute
documents the existing alignment contract.
Reproducer:
The issue is reachable as root with CAP_NET_ADMIN. Create a VLAN-aware
multicast-snooping bridge, attach veth ports, add several bridge VLANs
on the bridge itself, and add a host MDB entry without a VID. Leaving
the VID unspecified makes the bridge replicate the join across every
bridge VLAN, and br_switchdev_host_mdb() then defers one HOST_MDB
object per lower port into switchdev_deferred_enqueue(). With a modest
setup, for example four veth ports and bridge VLANs 1-11, a single
bridge mdb add dev br0 port br0 grp 239.1.1.10
is enough to observe the oversized GFP_ATOMIC allocations.
We ran the PoC in a 2 GB RAM x86 QEMU environment.
------BEGIN PoC------
#!/bin/sh
set -eu
if [ "$(id -u)" -ne 0 ]; then
echo "run as root" >&2
exit 1
fi
ip link del br0 2>/dev/null || true
for i in 0 1 2 3; do
ip link del "v$i" 2>/dev/null || true
ip link del "p$i" 2>/dev/null || true
done
ip link add br0 type bridge vlan_filtering 1 mcast_snooping 1
ip link set br0 up
for i in 0 1 2 3; do
ip link add "v$i" type veth peer name "p$i"
ip link set "v$i" master br0
ip link set "v$i" up
ip link set "p$i" up
done
# VID 1 is the default PVID; add 2-11 on the bridge itself.
bridge vlan add dev br0 vid 2-11 self
bridge mdb add dev br0 port br0 grp 239.1.1.10
------END PoC--------
----BEGIN crash log----
On the Linux 6.12.94 x86_64 guest, pahole reported
sizeof(struct switchdev_deferred_item) = 32 (empty netdevice_tracker)
and sizeof(struct switchdev_obj_port_mdb) = 56, so a deferred HOST_MDB
item requested 32 + 56 * 8 = 480 bytes instead of 32 + 56 = 88. With
CONFIG_SLUB_DEBUG=y, kmem:kmalloc traces at switchdev_deferred_enqueue
showed:
call_site=switchdev_deferred_enqueue+0x2b/0xf0
bytes_req=480
bytes_alloc=1536
A deferred attr item is the same error by type math on the same pahole
sizes (32 + 48 * 8 = 416 bytes instead of 80); that figure is not from
a separate slab trace. After-fix bytes_req and bytes_alloc were not
measured on this setup.
-----END crash log-----
Best regards,
Ruide Cao
Ruide Cao (1):
switchdev: fix deferred item flex-array allocation size
net/switchdev/switchdev.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
base-commit: 32756b82fde8f6cc98b174fdcd02c2a61033e263
--
2.47.3
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH net 1/1] switchdev: fix deferred item flex-array allocation size
2026-11-27 6:20 [PATCH net 0/1] switchdev: fix deferred item flex-array allocation size Ren Wei
@ 2026-11-27 6:20 ` Ren Wei
0 siblings, 0 replies; 2+ messages in thread
From: Ren Wei @ 2026-11-27 6:20 UTC (permalink / raw)
To: netdev
Cc: jiri, ivecera, davem, edumazet, kuba, pabeni, willemb, horms,
chi.minghao, vega, caoruide123, weir
From: Ruide Cao <caoruide123@gmail.com>
switchdev_deferred_enqueue() passes data_len, a byte count, to
kmalloc_flex() for the flexible array in struct switchdev_deferred_item.
That array is declared as unsigned long data[], so the allocator treats
data_len as an element count and over-allocates every deferred attr or
object item by sizeof(unsigned long) (8x on 64-bit). The following
memcpy() copies only data_len bytes, so this is not an overflow; it
wastes GFP_ATOMIC memory and makes those atomic allocations more likely
to fail.
This was found with LLM assistance on the Vega platform and reproduced
with the platform PoC in QEMU. On that x86_64 6.12.94 guest, pahole
reported sizeof(struct switchdev_deferred_item) = 32 and
sizeof(struct switchdev_obj_port_mdb) = 56. A deferred HOST_MDB item
therefore requested 32 + 56 * sizeof(unsigned long) = 480 bytes instead
of 32 + 56 = 88. kmem:kmalloc traces from switchdev_deferred_enqueue
showed bytes_req=480 and bytes_alloc=1536 (CONFIG_SLUB_DEBUG=y). A
deferred attr item has the same class of error: 32 + 48 * 8 = 416 bytes
instead of 80.
Declare the payload as u8 data[] __aligned(sizeof(unsigned long)). The
members before data are all pointers, or an empty tracker, so the offset
of data is unchanged and the payload already has long alignment; the
attribute documents that contract. The old unsigned long[] array did not
provide 8-byte alignment on 32-bit either.
Fixes: d8c2858181cc ("net/switchdev: use struct_size over open coded arithmetic")
Cc: stable@vger.kernel.org
Reported-by: Vega <vega@nebusec.ai>
Signed-off-by: Ruide Cao <caoruide123@gmail.com>
Signed-off-by: Ren Wei <weir@nebusec.ai>
---
net/switchdev/switchdev.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/switchdev/switchdev.c b/net/switchdev/switchdev.c
index 474df25e96a0..fbfb25cdfa80 100644
--- a/net/switchdev/switchdev.c
+++ b/net/switchdev/switchdev.c
@@ -59,7 +59,7 @@ struct switchdev_deferred_item {
struct net_device *dev;
netdevice_tracker dev_tracker;
switchdev_deferred_func_t *func;
- unsigned long data[];
+ u8 data[] __aligned(sizeof(unsigned long));
};
static struct switchdev_deferred_item *switchdev_deferred_dequeue(void)
--
2.47.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-27 6:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 6:20 [PATCH net 0/1] switchdev: fix deferred item flex-array allocation size Ren Wei
2026-11-27 6:20 ` [PATCH net 1/1] " Ren Wei
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox