From: Sechang Lim <rhkrqnwk98@gmail.com>
To: netdev@vger.kernel.org
Cc: bpf@vger.kernel.org, davem@davemloft.net, edumazet@kernel.org,
kuba@kernel.org, pabeni@redhat.com, willemb@google.com,
horms@kernel.org, ast@kernel.org, daniel@iogearbox.net,
hawk@kernel.org, john.fastabend@gmail.com, sdf@fomichev.me,
tehnerd@tehnerd.com
Subject: [PATCH net] net: xdp: Fix skb->tail after bpf_xdp_adjust_tail() in generic mode
Date: Thu, 26 Nov 2026 12:55:56 +0000 [thread overview]
Message-ID: <20261126125558.2032158-1-rhkrqnwk98@gmail.com> (raw)
In generic XDP the program sees a frame starting at the MAC header,
mac_len bytes before skb->data. After bpf_xdp_adjust_tail(), skb->tail
is set to skb->data + (xdp->data_end - xdp->data), which is mac_len
bytes beyond the new end of the frame and can be beyond skb->end.
When a tc program then calls bpf_skb_change_tail(), __skb_grow()
compares the negative skb_tailroom() as unsigned and does not expand
the head, so zeroing the new bytes runs past the end of the buffer:
BUG: KASAN: slab-out-of-bounds in bpf_skb_grow_rcsum+0x1cc/0x460
Write of size 4096 at addr ffff888108e84ec0 by task xg/365
Call Trace:
bpf_skb_grow_rcsum+0x1cc/0x460
bpf_skb_change_tail+0x50b/0x800
bpf_prog_f9246b7887bf521b_tail+0x53/0x67
__netif_receive_skb_core.constprop.0+0x132f/0x2e60
Subtract mac_len from the offset.
Fixes: 198d83bb3bec ("bpf: make generic xdp compatible w/ bpf_xdp_adjust_tail")
Signed-off-by: Sechang Lim <rhkrqnwk98@gmail.com>
---
net/core/dev.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/core/dev.c b/net/core/dev.c
index cd0796a1dbfd..1934e11c4401 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -5737,7 +5737,7 @@ u32 bpf_prog_run_generic_xdp(struct sk_buff *skb, struct xdp_buff *xdp,
/* check if bpf_xdp_adjust_tail was used */
off = xdp->data_end - orig_data_end;
if (off != 0) {
- skb_set_tail_pointer(skb, xdp->data_end - xdp->data);
+ skb_set_tail_pointer(skb, xdp->data_end - xdp->data - mac_len);
skb->len += off; /* positive on grow, negative on shrink */
}
--
2.56.1
next reply other threads:[~2026-11-26 12:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 12:55 Sechang Lim [this message]
2026-11-26 12:58 ` [PATCH net] net: xdp: Fix skb->tail after bpf_xdp_adjust_tail() in generic mode netdev-bot+sinfo
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=20261126125558.2032158-1-rhkrqnwk98@gmail.com \
--to=rhkrqnwk98@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=hawk@kernel.org \
--cc=horms@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
--cc=tehnerd@tehnerd.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