* [PATCH net v2 0/2] net: do not point a pskb copy's mac header into uninitialised headroom
@ 2026-11-17 17:58 Theodor Arsenij Larionov Trichkine
2026-11-17 17:58 ` [PATCH net v2 1/2] netfilter: nfnetlink_queue: only adjust bridged skbs that have a mac header Theodor Arsenij Larionov Trichkine
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Theodor Arsenij Larionov Trichkine @ 2026-11-17 17:58 UTC (permalink / raw)
To: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Simon Horman, Pablo Neira Ayuso, Florian Westphal, Phil Sutter,
netdev, netfilter-devel, coreteam,
Theodor Arsenij Larionov Trichkine
A pskb copy keeps the mac_header offset but not the headroom, so a copy
of a received packet has its mac header in uninitialised bytes, which
nft dup can return to userspace. Patch 2 unsets the mac header of such a
copy, as Florian suggested on v1. Patch 1 makes the nfnetlink_queue
bridge adjustment check the mac header first; without it, patch 2 turns
a queued GSO copy of a bridged packet into an out-of-bounds push.
v2: fix in __pskb_copy_fclone() instead of nf_dup; add patch 1.
v1: https://lore.kernel.org/netfilter-devel/20261116105113.128791-1-theodorlarionov@gmail.com/
Theodor Arsenij Larionov Trichkine (2):
netfilter: nfnetlink_queue: only adjust bridged skbs that have a mac
header
net: unset the mac header of a pskb copy that points into headroom
net/core/skbuff.c | 2 ++
net/netfilter/nfnetlink_queue.c | 4 ++--
2 files changed, 4 insertions(+), 2 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH net v2 1/2] netfilter: nfnetlink_queue: only adjust bridged skbs that have a mac header 2026-11-17 17:58 [PATCH net v2 0/2] net: do not point a pskb copy's mac header into uninitialised headroom Theodor Arsenij Larionov Trichkine @ 2026-11-17 17:58 ` Theodor Arsenij Larionov Trichkine 2026-11-19 6:00 ` netdev-bot+sashiko 2026-11-17 17:58 ` [PATCH net v2 2/2] net: unset the mac header of a pskb copy that points into headroom Theodor Arsenij Larionov Trichkine 2026-11-17 18:03 ` [PATCH net v2 0/2] net: do not point a pskb copy's mac header into uninitialised headroom netdev-bot+sinfo 2 siblings, 1 reply; 7+ messages in thread From: Theodor Arsenij Larionov Trichkine @ 2026-11-17 17:58 UTC (permalink / raw) To: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni Cc: Simon Horman, Pablo Neira Ayuso, Florian Westphal, Phil Sutter, netdev, netfilter-devel, coreteam, Theodor Arsenij Larionov Trichkine nf_bridge_adjust_skb_data() and nf_bridge_adjust_segmented_data() push and pull skb_mac_header_len() bytes for any skb with bridge netfilter info. A pskb copy of a bridged packet, such as one made by nft dup, keeps that info, and the next patch unsets its mac header. With the mac header unset, skb_mac_header_len() underflows and the push moves skb->data out of the buffer before skb_gso_segment(): BUG: KASAN: slab-out-of-bounds in inet_gso_segment+0xd5f/0x1370 Only adjust skbs that have a mac header. Fixes: a5fedd43d5f6 ("netfilter: move skb_gso_segment into nfnetlink_queue module") Cc: stable@vger.kernel.org Signed-off-by: Theodor Arsenij Larionov Trichkine <theodorlarionov@gmail.com> --- net/netfilter/nfnetlink_queue.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c index a8aa7ad832c3..fafadd9057cf 100644 --- a/net/netfilter/nfnetlink_queue.c +++ b/net/netfilter/nfnetlink_queue.c @@ -1084,13 +1084,13 @@ nf_queue_entry_dup(struct nf_queue_entry *e) */ static void nf_bridge_adjust_skb_data(struct sk_buff *skb) { - if (nf_bridge_info_get(skb)) + if (nf_bridge_info_get(skb) && skb_mac_header_was_set(skb)) __skb_push(skb, skb_mac_header_len(skb)); } static void nf_bridge_adjust_segmented_data(struct sk_buff *skb) { - if (nf_bridge_info_get(skb)) + if (nf_bridge_info_get(skb) && skb_mac_header_was_set(skb)) __skb_pull(skb, skb_mac_header_len(skb)); } #else -- 2.34.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH net v2 1/2] netfilter: nfnetlink_queue: only adjust bridged skbs that have a mac header 2026-11-17 17:58 ` [PATCH net v2 1/2] netfilter: nfnetlink_queue: only adjust bridged skbs that have a mac header Theodor Arsenij Larionov Trichkine @ 2026-11-19 6:00 ` netdev-bot+sashiko 0 siblings, 0 replies; 7+ messages in thread From: netdev-bot+sashiko @ 2026-11-19 6:00 UTC (permalink / raw) To: theodorlarionov Cc: davem, edumazet, kuba, pabeni, horms, pablo, fw, phil, netdev, netfilter-devel, coreteam Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider. Critical: 0 · High: 1 · Medium: 0 · Low: 1 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [High] The series leaves an out-of-bounds read in nf_send_reset() and nf_send_reset6(). - [Low] The commit message and tags present this as a standalone fix for a live KASAN slab-out-of-bounds bug, with `Fixes: a5fedd43d5f6` and… -- netfilter: nfnetlink_queue: only adjust bridged skbs that have a mac header This patch makes nf_bridge_adjust_skb_data() and nf_bridge_adjust_segmented_data() skip the push/pull of skb_mac_header_len() bytes when the skb has no mac header set. It is groundwork for the next patch in the series, which unsets the mac header of a pskb copy that points into headroom. > Fixes: a5fedd43d5f6 ("netfilter: move skb_gso_segment into nfnetlink_queue module") > Cc: stable@vger.kernel.org [Severity: Low] Is this Fixes tag accurate for this patch on its own? The commit message says the trigger only shows up once the next patch is applied: > A pskb copy of a bridged packet, such as one made by nft dup, > keeps that info, and the next patch unsets its mac header. Before that patch, a pskb copy keeps the original mac_header offset. So skb_mac_header_was_set() is true and skb_mac_header_len() does not underflow in nf_bridge_adjust_skb_data(). The next patch ("net: unset the mac header of a pskb copy that points into headroom") has Fixes: 1da177e4c3f4 and no dependency note. A backport of that patch alone would bring in the KASAN splat this patch prevents. Could the commit message say this is a prerequisite for the following patch? Or could the stable tag on the next patch list this one as a dependency? > diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c > index a8aa7ad832c3f..fafadd9057cf7 100644 > --- a/net/netfilter/nfnetlink_queue.c > +++ b/net/netfilter/nfnetlink_queue.c > @@ -1084,13 +1084,13 @@ nf_queue_entry_dup(struct nf_queue_entry *e) > */ > static void nf_bridge_adjust_skb_data(struct sk_buff *skb) > { > - if (nf_bridge_info_get(skb)) > + if (nf_bridge_info_get(skb) && skb_mac_header_was_set(skb)) > __skb_push(skb, skb_mac_header_len(skb)); > } > > static void nf_bridge_adjust_segmented_data(struct sk_buff *skb) > { > - if (nf_bridge_info_get(skb)) > + if (nf_bridge_info_get(skb) && skb_mac_header_was_set(skb)) > __skb_pull(skb, skb_mac_header_len(skb)); > } [Severity: High] This patch only guards these two nfnetlink_queue helpers. Do other users also trust the mac header whenever nf_bridge info is present? nf_send_reset() in net/ipv4/netfilter/nf_reject_ipv4.c does this: if (nf_bridge_info_exists(oldskb)) { struct ethhdr *oeth = eth_hdr(oldskb); ... if (dev_hard_header(nskb, nskb->dev, ntohs(nskb->protocol), oeth->h_source, oeth->h_dest, nskb->len) < 0) It never calls skb_mac_header_was_set(). nf_send_reset6() in net/ipv6/netfilter/nf_reject_ipv6.c has the same code. With the next patch applied, it looks like this path can be reached: 1. Bridged IPv4 or IPv6 traffic passes ip/ip6 PREROUTING or FORWARD through br_netfilter. At that point skb->data is at the network header, so skb_mac_offset() < 0. 2. A TEE or nft dup rule calls nf_dup_ipv4() or nf_dup_ipv6(), which call pskb_copy(). Then __copy_skb_header()->__skb_ext_copy() keeps SKB_EXT_BRIDGE_NF on the copy, and after the next patch the copy's mac_header is 0xffff. 3. The copy goes through ip_local_out() or ip6_local_out() and the LOCAL_OUT hook. 4. An OUTPUT rule "REJECT --reject-with tcp-reset" (or nft "reject with tcp reset") matches the copy. nf_reject_ip_tcphdr_get() only checks frag offset, protocol, RST and checksum, so the copy passes. 5. nf_bridge_info_exists() is true, so eth_hdr(oldskb) returns skb->head + 65535. dev_hard_header() then copies 12 bytes from that address into the RST's Ethernet header. The RST goes out the physical input port. Can this read past the buffer and send those kernel bytes onto the wire? Before the series this path read uninitialized headroom inside the buffer. With the series applied, it reads past the end of the buffer. Would it be more robust to drop SKB_EXT_BRIDGE_NF from the copy in the dup path? For example, call skb_ext_del(skb, SKB_EXT_BRIDGE_NF) after pskb_copy() in nf_dup_ipv4() and nf_dup_ipv6(). The copy is a locally routed L3 packet, so its br_netfilter state has no meaning there. That would cover every user and make the per-user guards unnecessary. If not, nf_send_reset() and nf_send_reset6() would need the same skb_mac_header_was_set() check. -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117175835.745796-1-theodorlarionov%40gmail.com ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH net v2 2/2] net: unset the mac header of a pskb copy that points into headroom 2026-11-17 17:58 [PATCH net v2 0/2] net: do not point a pskb copy's mac header into uninitialised headroom Theodor Arsenij Larionov Trichkine 2026-11-17 17:58 ` [PATCH net v2 1/2] netfilter: nfnetlink_queue: only adjust bridged skbs that have a mac header Theodor Arsenij Larionov Trichkine @ 2026-11-17 17:58 ` Theodor Arsenij Larionov Trichkine 2026-11-19 6:00 ` netdev-bot+sashiko 2026-11-17 18:03 ` [PATCH net v2 0/2] net: do not point a pskb copy's mac header into uninitialised headroom netdev-bot+sinfo 2 siblings, 1 reply; 7+ messages in thread From: Theodor Arsenij Larionov Trichkine @ 2026-11-17 17:58 UTC (permalink / raw) To: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni Cc: Simon Horman, Pablo Neira Ayuso, Florian Westphal, Phil Sutter, netdev, netfilter-devel, coreteam, Theodor Arsenij Larionov Trichkine __pskb_copy_fclone() copies the data from skb->data onwards, while skb_copy_header() keeps the mac_header offset. When the link-layer header was pulled, the copy's mac header points into uninitialised headroom. nft dup is one such caller: a link-layer payload read of the duplicated packet on LOCAL_OUT or POST_ROUTING loads those bytes, and a set element returns them to userspace: BUG: KMSAN: kernel-infoleak in _copy_to_iter Unset the mac header of the copy in that case. Callers that need it, such as the bridge, push the link-layer header before copying. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Suggested-by: Florian Westphal <fw@strlen.de> Cc: stable@vger.kernel.org Signed-off-by: Theodor Arsenij Larionov Trichkine <theodorlarionov@gmail.com> --- net/core/skbuff.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 1ac1e327ac4c..7f6d0344efa6 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -2278,6 +2278,8 @@ struct sk_buff *__pskb_copy_fclone(struct sk_buff *skb, int headroom, } skb_copy_header(n, skb); + if (skb_mac_header_was_set(n) && skb_mac_offset(n) < 0) + skb_unset_mac_header(n); out: return n; } -- 2.34.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH net v2 2/2] net: unset the mac header of a pskb copy that points into headroom 2026-11-17 17:58 ` [PATCH net v2 2/2] net: unset the mac header of a pskb copy that points into headroom Theodor Arsenij Larionov Trichkine @ 2026-11-19 6:00 ` netdev-bot+sashiko 2026-11-19 8:48 ` Florian Westphal 0 siblings, 1 reply; 7+ messages in thread From: netdev-bot+sashiko @ 2026-11-19 6:00 UTC (permalink / raw) To: theodorlarionov Cc: davem, edumazet, kuba, pabeni, horms, pablo, fw, phil, netdev, netfilter-devel, coreteam Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider. Critical: 0 · High: 1 · Medium: 0 · Low: 0 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [High] net: out-of-bounds read in nf_send_reset() after __pskb_copy_fclone() -- > diff --git a/net/core/skbuff.c b/net/core/skbuff.c > --- a/net/core/skbuff.c > +++ b/net/core/skbuff.c > @@ -2278,6 +2278,8 @@ struct sk_buff *__pskb_copy_fclone(struct sk_buff *skb, int headroom, > } > > skb_copy_header(n, skb); > + if (skb_mac_header_was_set(n) && skb_mac_offset(n) < 0) > + skb_unset_mac_header(n); > out: > return n; > } [Severity: High] Does this turn the uninitialised read into an out-of-bounds read for bridged packets? The copy still carries SKB_EXT_BRIDGE_NF, because skb_copy_header() -> __copy_skb_header() -> __skb_ext_copy() duplicates the extensions. After this change, though, n->mac_header is ~0U. nf_dup_ipv4() and nf_dup_ipv6() hand that copy to ip_local_out() and ip6_local_out(), so it goes through NF_INET_LOCAL_OUT before any link-layer header is pushed. Suppose a reject with tcp reset rule matches there. nf_send_reset() and nf_send_reset6() only test nf_bridge_info_exists(oldskb) before calling eth_hdr(oldskb). They then pass oeth->h_source and oeth->h_dest to dev_hard_header(). With the mac header unset, that trips the DEBUG_NET_WARN_ON_ONCE() in skb_mac_header(). It then reads 12 bytes at oldskb->head + 0xffff, well past the end of the head buffer. Those bytes end up in the Ethernet header of the RST sent out the bridge port, or the access faults if the address is unmapped. Before this patch the same path read uninitialised headroom inside the buffer, which is the leak being fixed here. So the reject helpers probably need a skb_mac_header_was_set() check, the same way nf_bridge_adjust_skb_data() in nfnetlink_queue.c has one. Or would you rather drop the bridge extension on the dup path? Either way, it looks like that has to go in together with this change, especially with the stable tag. -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117175835.745796-1-theodorlarionov%40gmail.com ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net v2 2/2] net: unset the mac header of a pskb copy that points into headroom 2026-11-19 6:00 ` netdev-bot+sashiko @ 2026-11-19 8:48 ` Florian Westphal 0 siblings, 0 replies; 7+ messages in thread From: Florian Westphal @ 2026-11-19 8:48 UTC (permalink / raw) To: netdev-bot+sashiko Cc: theodorlarionov, davem, edumazet, kuba, pabeni, horms, pablo, phil, netdev, netfilter-devel, coreteam netdev-bot+sashiko@kernel.org <netdev-bot+sashiko@kernel.org> wrote: > [Severity: High] > Does this turn the uninitialised read into an out-of-bounds read for > bridged packets? The copy still carries SKB_EXT_BRIDGE_NF, because > skb_copy_header() -> __copy_skb_header() -> __skb_ext_copy() duplicates > the extensions. After this change, though, n->mac_header is ~0U. > nf_dup_ipv4() and nf_dup_ipv6() hand that copy to ip_local_out() and > ip6_local_out(), so it goes through NF_INET_LOCAL_OUT before any > link-layer header is pushed. Suppose a reject with tcp reset rule > matches there. nf_send_reset() and nf_send_reset6() only test > nf_bridge_info_exists(oldskb) before calling eth_hdr(oldskb). They then > pass oeth->h_source and oeth->h_dest to dev_hard_header(). > > With the mac header unset, that trips the DEBUG_NET_WARN_ON_ONCE() in > skb_mac_header(). It then reads 12 bytes at oldskb->head + 0xffff, > well past the end of the head buffer. Those bytes end up in the > Ethernet header of the RST sent out the bridge port, or the access > faults if the address is unmapped. > > Before this patch the same path read uninitialised headroom inside the > buffer, which is the leak being fixed here. So the reject helpers > probably need a skb_mac_header_was_set() check, the same way > nf_bridge_adjust_skb_data() in nfnetlink_queue.c has one. Or would you > rather drop the bridge extension on the dup path? Either way, it looks > like that has to go in together with this change, especially with the > stable tag. I think we should disable dup or fwd of skbs coming from br_netfilter (i.e. with SKB_EXT_BRIDGE_NF extension set). It would also make sense to disable/remove nf_queue support for br_netfilter in nf-next (this is independent of this work). ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net v2 0/2] net: do not point a pskb copy's mac header into uninitialised headroom 2026-11-17 17:58 [PATCH net v2 0/2] net: do not point a pskb copy's mac header into uninitialised headroom Theodor Arsenij Larionov Trichkine 2026-11-17 17:58 ` [PATCH net v2 1/2] netfilter: nfnetlink_queue: only adjust bridged skbs that have a mac header Theodor Arsenij Larionov Trichkine 2026-11-17 17:58 ` [PATCH net v2 2/2] net: unset the mac header of a pskb copy that points into headroom Theodor Arsenij Larionov Trichkine @ 2026-11-17 18:03 ` netdev-bot+sinfo 2 siblings, 0 replies; 7+ messages in thread From: netdev-bot+sinfo @ 2026-11-17 18:03 UTC (permalink / raw) To: Theodor Arsenij Larionov Trichkine Cc: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman, Pablo Neira Ayuso, Florian Westphal, Phil Sutter, netdev, netfilter-devel, coreteam Hi! This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information: - How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan. Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. *IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages. -- The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain. ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-19 8:48 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-17 17:58 [PATCH net v2 0/2] net: do not point a pskb copy's mac header into uninitialised headroom Theodor Arsenij Larionov Trichkine 2026-11-17 17:58 ` [PATCH net v2 1/2] netfilter: nfnetlink_queue: only adjust bridged skbs that have a mac header Theodor Arsenij Larionov Trichkine 2026-11-19 6:00 ` netdev-bot+sashiko 2026-11-17 17:58 ` [PATCH net v2 2/2] net: unset the mac header of a pskb copy that points into headroom Theodor Arsenij Larionov Trichkine 2026-11-19 6:00 ` netdev-bot+sashiko 2026-11-19 8:48 ` Florian Westphal 2026-11-17 18:03 ` [PATCH net v2 0/2] net: do not point a pskb copy's mac header into uninitialised headroom netdev-bot+sinfo
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox