Netdev List
 help / color / mirror / Atom feed
From: Ren Wei <weir@nebusec.ai>
To: netdev@vger.kernel.org
Cc: jiri@resnulli.us, ivecera@redhat.com, davem@davemloft.net,
	edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
	willemb@google.com, horms@kernel.org, chi.minghao@zte.com.cn,
	vega@nebusec.ai, caoruide123@gmail.com, weir@nebusec.ai
Subject: [PATCH net 0/1] switchdev: fix deferred item flex-array allocation size
Date: Fri, 27 Nov 2026 14:20:50 +0800	[thread overview]
Message-ID: <cover.1795576931.git.caoruide123@gmail.com> (raw)

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


             reply	other threads:[~2026-11-27  6:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27  6:20 Ren Wei [this message]
2026-11-27  6:20 ` [PATCH net 1/1] switchdev: fix deferred item flex-array allocation size Ren Wei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover.1795576931.git.caoruide123@gmail.com \
    --to=weir@nebusec.ai \
    --cc=caoruide123@gmail.com \
    --cc=chi.minghao@zte.com.cn \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=ivecera@redhat.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=vega@nebusec.ai \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox