xp_assign_dev() and xp_disable_drv_zc() declare a struct netdev_bpf on
the stack, set command, xsk.pool and xsk.queue_id, and pass it to the
driver's ndo_bpf. Nothing else in the struct is initialized. That
includes extack, which belongs to the XDP_SETUP_PROG member of the
union and lies past the end of the xsk member, so a driver that reads
xdp->extack on this path gets whatever was on the stack.
gve and idpf read it. Since commit 091a3b6ff2b9 ("gve: Use extack to
log xdp config verification errors") gve_xdp() passes xdp->extack to
gve_verify_xdp_configuration() on the pool path, and that function
stores an error message through it whenever the configuration is
refused, for example when a zero-copy socket is bound while the RX and
TX queue counts do not allow XDP. Since commit 3d57b2c00f09 ("idpf: add
XSk pool initialization") idpf_xsk_pool_setup() passes it to
NL_SET_ERR_MSG_FMT_MOD() on its error paths. With
CONFIG_INIT_STACK_ALL_ZERO the pointer is NULL and the message is
skipped; otherwise the driver writes to wherever the uninitialized
pointer points.
Initialize the struct in both functions, so that extack is NULL on this
path for every driver. dev_xdp_install() already clears the struct it
passes to ndo_bpf with memset(), and the BPF offload code uses an empty
initializer.
This was discovered by an AI code review agent reading gve_xdp() while
preparing "gve: do not verify the XDP configuration on program or pool
removal". It was reproduced on gve, with that fix applied, on gVNIC in
GQI-QPL mode (GCE n2-standard-4) on net at
commit ef3e21c61baa ("net/tcp-ao: fix reset key lookup for IPv4
segments on IPv6 listeners"), built with
CONFIG_INIT_STACK_ALL_PATTERN, by binding a zero-copy AF_XDP socket at
the default queue counts and MTU 1460 with repro/xsk/xsk_trigger.c from
the Link below:
# ./xsk_trigger eth0 0
Oops: general protection fault, probably for non-canonical address 0xfefefefefefefefe: 0000 [#1] SMP NOPTI
RIP: 0010:gve_verify_xdp_configuration.cold+0x1d/0x2e [gve]
Call Trace:
gve_xdp+0x47/0x4d0 [gve]
xp_assign_dev+0x2c8/0x350
xsk_bind+0x1ba/0x4e0
With this patch the same bind is refused with -EINVAL and no fault.
The idpf case was found by reading the code and was not run.
Link: https://github.com/AmaanC/sticky-xdp
Fixes: 3d57b2c00f09 ("idpf: add XSk pool initialization")
Fixes: 091a3b6ff2b9 ("gve: Use extack to log xdp config verification errors")
Cc: stab…@vger.kernel.org
Signed-off-by: Amaan Cheval <amaa…@gmail.com>
---
v2: new; replaces "gve: do not pass extack to the XDP check on XSK pool
setup" from v1, as Maciej asked.
net/xdp/xsk_buff_pool.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c
index 5ec092f7cb6f..ac2a188b2839 100644
--- a/net/xdp/xsk_buff_pool.c
+++ b/net/xdp/xsk_buff_pool.c
@@ -144,7 +144,7 @@ EXPORT_SYMBOL(xp_fill_cb);
static void xp_disable_drv_zc(struct xsk_buff_pool *pool)
{
- struct netdev_bpf bpf;
+ struct netdev_bpf bpf = {};
int err;
ASSERT_RTNL();
@@ -169,7 +169,7 @@ int xp_assign_dev(struct xsk_buff_pool *pool,
u8 umem_flags = pool->umem->flags;
bool mbuf = flags & XDP_USE_SG;
bool force_zc, force_copy;
- struct netdev_bpf bpf;
+ struct netdev_bpf bpf = {};
u32 frame_size;
int err = 0;
--
2.47.3