All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH nf] netfilter: nfnetlink_queue: keep socket ownership when expanding skb
@ 2026-10-30 13:57 Fernando Fernandez Mancera
  2026-10-30 14:35 ` Florian Westphal
  0 siblings, 1 reply; 8+ messages in thread
From: Fernando Fernandez Mancera @ 2026-10-30 13:57 UTC (permalink / raw)
  To: netfilter-devel
  Cc: coreteam, pablo, phil, fw, Fernando Fernandez Mancera, VEGA

nfqnl_mangle() replaces the skb with skb_copy_expand() when a verdict
grows a packet beyond its tailroom. skb_copy_expand() does not copy
skb->sk, so the replacement is unowned and freeing the original drops
its socket memory charge.

The expanded packet is no longer associated with the process that sent
it. Therefore xt_owner or xt_cgroup and other socket based matches in
later rules no longer matches and a later NFQUEUE reports no uid/gid. In
addition, the expanded packet's memory is not counted towards the
sender's SO_SNDBUF limit, so the sender can keep producing them while
they sit in a queue.

Fix this by transferring ownership before freeing the original as
skb_cow_data() an skb_expand_head() do.

Fixes: e2b58a67b91d ("[NETFILTER]: {ip,ip6,nfnetlink}_queue: fix SKB_LINEAR_ASSERT when mangling packet data")
Reported-by: VEGA <vega@nebusec.ai>
Signed-off-by: Fernando Fernandez Mancera <fmancera@suse.de>
---
 net/netfilter/nfnetlink_queue.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c
index 90d887546f7d..fe3b9ce7acb0 100644
--- a/net/netfilter/nfnetlink_queue.c
+++ b/net/netfilter/nfnetlink_queue.c
@@ -1459,6 +1459,8 @@ nfqnl_mangle(void *data, unsigned int data_len, struct nf_queue_entry *e, int di
 					       diff, GFP_ATOMIC);
 			if (!nskb)
 				return -ENOMEM;
+			if (e->skb->sk)
+				skb_set_owner_w(nskb, e->skb->sk);
 			kfree_skb(e->skb);
 			e->skb = nskb;
 		}
-- 
2.56.0


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

end of thread, other threads:[~2026-10-30 15:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-30 13:57 [PATCH nf] netfilter: nfnetlink_queue: keep socket ownership when expanding skb Fernando Fernandez Mancera
2026-10-30 14:35 ` Florian Westphal
2026-10-30 14:40   ` Fernando Fernandez Mancera
2026-10-30 14:53     ` Florian Westphal
2026-10-30 14:57       ` Fernando Fernandez Mancera
2026-10-30 15:07         ` Florian Westphal
2026-10-30 15:12           ` Fernando Fernandez Mancera
2026-10-30 15:28             ` Florian Westphal

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.