mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH nf] netfilter: nfnetlink_queue: unclone skb before writing NFQA_L2HDR
@ 2026-11-07 16:05 Tamaki Yanagawa
  2026-11-07 16:17 ` Florian Westphal
  0 siblings, 1 reply; 3+ messages in thread
From: Tamaki Yanagawa @ 2026-11-07 16:05 UTC (permalink / raw)
  To: netfilter-devel; +Cc: pablo, fw, phil, coreteam, linux-kernel, ty

nfqa_parse_bridge() copies the NFQA_L2HDR attribute over the mac header
of the queued skb in place. Bridge flooding queues clones that share
their data with the copies sent to the other ports, so the rewritten
header also shows up on frames that never went through the queue, and
is changed while those may already be in transmission. Unclone the skb
before the copy, as nfqnl_mangle() does for NFQA_PAYLOAD via
skb_ensure_writable().

Fixes: 8d45ff22f1b4 ("netfilter: bridge: nf queue verdict to use NFQA_VLAN and NFQA_L2HDR")
Signed-off-by: Tamaki Yanagawa <ty@000ty.net>
Assisted-by: Claude:claude-opus-5-5
---
 net/netfilter/nfnetlink_queue.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c
index 90d887546f..146211fd03 100644
--- a/net/netfilter/nfnetlink_queue.c
+++ b/net/netfilter/nfnetlink_queue.c
@@ -1819,10 +1819,15 @@ static int nfqa_parse_bridge(struct nf_queue_entry *entry,
 
 		if (mac_header_len != nla_len(nfqa[NFQA_L2HDR]))
 			return -EINVAL;
-		else if (mac_header_len > 0)
+
+		if (mac_header_len > 0) {
+			if (skb_unclone(entry->skb, GFP_ATOMIC))
+				return -ENOMEM;
+
 			memcpy(skb_mac_header(entry->skb),
 			       nla_data(nfqa[NFQA_L2HDR]),
 			       mac_header_len);
+		}
 	}
 
 	return 0;

base-commit: 734bef548a96e8774d6eef5dfa2026c6edc4e80b
-- 
2.52.0



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH nf] netfilter: nfnetlink_queue: unclone skb before writing NFQA_L2HDR
  2026-11-07 16:05 [PATCH nf] netfilter: nfnetlink_queue: unclone skb before writing NFQA_L2HDR Tamaki Yanagawa
@ 2026-11-07 16:17 ` Florian Westphal
  2026-11-07 16:32   ` Tamaki Yanagawa
  0 siblings, 1 reply; 3+ messages in thread
From: Florian Westphal @ 2026-11-07 16:17 UTC (permalink / raw)
  To: Tamaki Yanagawa; +Cc: netfilter-devel, pablo, phil, coreteam, linux-kernel

Tamaki Yanagawa <ty@000ty.net> wrote:
> nfqa_parse_bridge() copies the NFQA_L2HDR attribute over the mac header
> of the queued skb in place. Bridge flooding queues clones that share
> their data with the copies sent to the other ports, so the rewritten
> header also shows up on frames that never went through the queue, and
> is changed while those may already be in transmission. Unclone the skb
> before the copy, as nfqnl_mangle() does for NFQA_PAYLOAD via
> skb_ensure_writable().

Can you explain in changelog why full unclone is needed rather than
skb_ensure_writable()?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH nf] netfilter: nfnetlink_queue: unclone skb before writing NFQA_L2HDR
  2026-11-07 16:17 ` Florian Westphal
@ 2026-11-07 16:32   ` Tamaki Yanagawa
  0 siblings, 0 replies; 3+ messages in thread
From: Tamaki Yanagawa @ 2026-11-07 16:32 UTC (permalink / raw)
  To: fw; +Cc: netfilter-devel, pablo, phil, coreteam, linux-kernel, ty

Florian Westphal <fw@strlen.de> wrote:
> Can you explain in changelog why full unclone is needed rather than
> skb_ensure_writable()?

It isn't. At the bridge hooks skb->data points to the network header, so
the mac header is in the headroom, and skb_clone_writable() already
checks headroom against hdr_len. skb_ensure_writable(skb, 0) is enough
and also avoids copying clones that own their header area. I'll send a
v2 using it and saying so in the changelog. I re-ran the bridge flood
test with it: the frame on the other port keeps its original header.

Thanks,
Tamaki


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-07 16:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-07 16:05 [PATCH nf] netfilter: nfnetlink_queue: unclone skb before writing NFQA_L2HDR Tamaki Yanagawa
2026-11-07 16:17 ` Florian Westphal
2026-11-07 16:32   ` Tamaki Yanagawa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®