Skip to contentSkip to conversation

netfilter: nfnetlink_queue: make skb writable before writing NFQA_L2HDR

PATCH New Tamaki Yanagawa 1 participant 1 message Nov 7

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 netfilter: nfnetlink_queue: make skb writable before writing NFQA_L2HDR

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. Call skb_ensure_writable() before the copy. At the bridge hooks skb->data points to the network header, so the mac header sits in the headroom, which skb_clone_writable() already takes into account: a write length of zero is enough, and a clone that owns its header area (nohdr) is left alone instead of being copied.

Fixes 8d45ff22f1b4 ("netfilter: bridge: nf queue verdict to use NFQA_VLAN and NFQA_L2HDR")
Assisted-by Claude:claude-opus-5-5

---

Notes:
v2: use skb_ensure_writable() instead of skb_unclone(), as suggested by Florian Westphal

v1: https://lore.kernel.org/netfilter-devel/[email protected]/

 net/netfilter/nfnetlink_queue.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
net/netfilter/nfnetlink_queue.c +9 -1
index 90d887546f..7d0980286f 100644
@@ -1819,10 +1819,18 @@ 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) {
+			/* the mac header is in the headroom, which
+			 * skb_clone_writable() accounts for
+			 */
+			if (skb_ensure_writable(entry->skb, 0))
+				return -ENOMEM;
+
 			memcpy(skb_mac_header(entry->skb),
 			       nla_data(nfqa[NFQA_L2HDR]),
 			       mac_header_len);
+		}
 	}
 
 	return 0;

base-commit: 734bef548a96e8774d6eef5dfa2026c6edc4e80b

Signature · 1 line
2.52.0