CVE-2026-99980: netdev: Hide the netdev_priv() origin from GCC in netdev_from_priv()
In the Linux kernel, the following vulnerability has been resolved:
netdev: Hide the netdevpriv() origin from GCC in netdevfrompriv()
GCC 15.1 and later can compute an object size of 0 for a pointer that containerof() derives from a pointer into a countedby flexible array member[1]; Clang gets it right. netdevfrompriv() does this with struct netdevice's "priv" array, so when GCC can see that its argument came from netdevpriv(), FORTIFYSOURCE sees a zero-sized netdevice. Since commit 9027497a25e3c ("team: use netdevfrompriv()"), adding a port of another type to a team device can then fail the memcpy() to "dev->broadcast" in teamsetupbyport(), which GCC sees through after inlining teamportadd() into teamaddslave():
memcpy: detected buffer overflow: 4 byte write of buffer size 0 ... kernel BUG at lib/stringhelpers.c:1044! ... Call Trace: <TASK> teamaddslave.cold+0x88/0x201 dosetmaster+0x11c/0x180 dosetlink.isra.0+0x3a4/0x1410
Whether GCC inlines that far depends on the architecture and the configuration. It does on ppc64le, where this was reported, and on x8664 with defconfig plus hardening.config or with Debian's configuration, but not with allmodconfig.
Hide where "priv" came from with OPTIMIZERHIDEVAR(), so GCC sees a netdevice of unknown size whose members have their declared sizes. (An "unknown" size is considered uncheckable by FORTIFY.) FORTIFY still bounds writes to members; only the whole-object size becomes unknown, as it already is for any netdevice pointer GCC can't trace to its allocation. In an extracted PoC, the builtindynamicobjectsize() of "dev->broadcast" for the two types FORTIFY sees, before and after this patch:
GCC 16.2.0 Clang 22 and 24 before after plain pointer, whole object unknown unknown 44 containerof(), whole object 0 unknown 44 containerof(), member 0 32 32
In addition to getting the bogus "0" fixed in GCC, I'll be following up to solve the whole-object visiblity disparity as well.
Build tested with GCC 16.2.0: ARCH=x8664 defconfig with hardening.config, CONFIGNETTEAM=y, and CONFIGNETIPGRE=y; ARCH=arm64 defconfig with hardening.config, CONFIGNETTEAM=y, CONFIGPPP=y, and CONFIGNETAIROHA=m; and drivers/net/team/, drivers/net/ppp/, and drivers/net/ethernet/airoha/ in ARCH=x8664 allmodconfig. Under QEMU, the x8664 kernel hits the BUG above when adding the GRE fallback device "gre0" as a port of a new team device without this patch, and adds it with the patch.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Compensating control
In `netdev_from_priv()`, use `OPTIMIZER_HIDE_VAR()` to hide the origin of `priv` from GCC.