From: Amaan Cheval <amaan.cheval@gmail.com>
To: netdev@vger.kernel.org
Cc: joshwash@google.com, hramamurthy@google.com,
andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
kuba@kernel.org, pabeni@redhat.com, ast@kernel.org,
daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com,
sdf@fomichev.me, bpf@vger.kernel.org, willemb@google.com,
jeroendb@google.com, pkaligineedi@google.com, nktgrg@google.com,
jordanrhee@google.com, przemyslaw.kitszel@intel.com,
debarghyak@google.com, treapking@google.com,
magnus.karlsson@intel.com, maciej.fijalkowski@intel.com,
horms@kernel.org, michal.kubiak@intel.com,
anthony.l.nguyen@intel.com, aleksander.lobakin@intel.com,
Amaan Cheval <amaan.cheval@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH net v2 2/2] xsk: initialize the struct netdev_bpf passed to ndo_bpf
Date: Fri, 4 Dec 2026 11:58:57 +0530 [thread overview]
Message-ID: <20261204062857.730993-3-amaan.cheval@gmail.com> (raw)
In-Reply-To: <20261204062857.730993-1-amaan.cheval@gmail.com>
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: stable@vger.kernel.org
Signed-off-by: Amaan Cheval <amaan.cheval@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
prev parent reply other threads:[~2026-12-04 6:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 6:28 [PATCH net v2 0/2] gve, xsk: fix XDP removal after a config change and an uninitialized extack Amaan Cheval
2026-12-04 6:28 ` [PATCH net v2 1/2] gve: do not verify the XDP configuration on program or pool removal Amaan Cheval
2026-12-04 6:28 ` Amaan Cheval [this message]
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=20261204062857.730993-3-amaan.cheval@gmail.com \
--to=amaan.cheval@gmail.com \
--cc=aleksander.lobakin@intel.com \
--cc=andrew+netdev@lunn.ch \
--cc=anthony.l.nguyen@intel.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=debarghyak@google.com \
--cc=edumazet@kernel.org \
--cc=hawk@kernel.org \
--cc=horms@kernel.org \
--cc=hramamurthy@google.com \
--cc=jeroendb@google.com \
--cc=john.fastabend@gmail.com \
--cc=jordanrhee@google.com \
--cc=joshwash@google.com \
--cc=kuba@kernel.org \
--cc=maciej.fijalkowski@intel.com \
--cc=magnus.karlsson@intel.com \
--cc=michal.kubiak@intel.com \
--cc=netdev@vger.kernel.org \
--cc=nktgrg@google.com \
--cc=pabeni@redhat.com \
--cc=pkaligineedi@google.com \
--cc=przemyslaw.kitszel@intel.com \
--cc=sdf@fomichev.me \
--cc=stable@vger.kernel.org \
--cc=treapking@google.com \
--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