All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH nf,v7 1/6] netfilter: nfnetlink_queue: add helper function to retrieve hook entries
@ 2026-11-12 22:11 Pablo Neira Ayuso
  2026-11-12 22:11 ` [PATCH nf,v7 2/6] netfilter: nfnetlink_queue: consolidate access to hook entries on reinjection Pablo Neira Ayuso
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-12 22:11 UTC (permalink / raw)
  To: netfilter-devel

Add nf_queue_hook_entry() and nf_queue_hook_entries() helper functions
to retrieve hook entries and use them.

This comes in preparation for a fix to restrict expectation creation to
nfnetlink_cthelper.

No functional changes are intended.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
v7: no changes

 net/netfilter/nfnetlink_queue.c | 40 +++++++++++++++++++++++++--------
 1 file changed, 31 insertions(+), 9 deletions(-)

diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c
index a8aa7ad832c3..09af8faf8675 100644
--- a/net/netfilter/nfnetlink_queue.c
+++ b/net/netfilter/nfnetlink_queue.c
@@ -360,6 +360,27 @@ static int nf_reroute(struct sk_buff *skb, struct nf_queue_entry *entry)
 	return ret;
 }
 
+static const struct nf_hook_entries *
+nf_queue_hook_entries(struct nf_queue_entry *entry)
+{
+	const struct net *net = entry->state.net;
+	u8 pf = entry->state.pf;
+
+	return nf_hook_entries_head(net, pf, entry->state.hook);
+}
+
+static const struct nf_hook_entry *
+nf_queue_hook_entry(const struct nf_hook_entries *hooks,
+		    struct nf_queue_entry *entry)
+{
+	unsigned int i = entry->hook_index;
+
+	if (i >= hooks->num_hook_entries)
+		return NULL;
+
+	return &hooks->hooks[i];
+}
+
 /* caller must hold rcu read-side lock */
 static void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict)
 {
@@ -367,10 +388,8 @@ static void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict)
 	const struct nf_hook_entries *hooks;
 	struct sk_buff *skb = entry->skb;
 	bool old_in_nf_duplicate;
-	const struct net *net;
 	unsigned int i;
 	int err;
-	u8 pf;
 
 	DEBUG_NET_WARN_ONCE(current->in_nf_duplicate &&
 			    !entry->in_nf_duplicate,
@@ -379,20 +398,23 @@ static void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict)
 	local_bh_disable();
 	old_in_nf_duplicate = current->in_nf_duplicate;
 
-	net = entry->state.net;
-	pf = entry->state.pf;
-
 	current->in_nf_duplicate = entry->in_nf_duplicate;
-	hooks = nf_hook_entries_head(net, pf, entry->state.hook);
 
-	i = entry->hook_index;
-	if (!hooks || i >= hooks->num_hook_entries) {
+	hooks = nf_queue_hook_entries(entry);
+	if (!hooks) {
 		kfree_skb_reason(skb, SKB_DROP_REASON_NETFILTER_DROP);
 		nf_queue_entry_free(entry);
 		goto out;
 	}
 
-	hook_entry = &hooks->hooks[i];
+	hook_entry = nf_queue_hook_entry(hooks, entry);
+	if (!hook_entry) {
+		kfree_skb_reason(skb, SKB_DROP_REASON_NETFILTER_DROP);
+		nf_queue_entry_free(entry);
+		goto out;
+	}
+
+	i = entry->hook_index;
 
 	/* Continue traversal iff userspace said ok... */
 	if (verdict == NF_REPEAT)
-- 
2.47.3


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

end of thread, other threads:[~2026-11-13 20:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-12 22:11 [PATCH nf,v7 1/6] netfilter: nfnetlink_queue: add helper function to retrieve hook entries Pablo Neira Ayuso
2026-11-12 22:11 ` [PATCH nf,v7 2/6] netfilter: nfnetlink_queue: consolidate access to hook entries on reinjection Pablo Neira Ayuso
2026-11-12 22:11 ` [PATCH nf,v7 3/6] netfilter: ctnetlink: restrict expectation creation glue to userspace helpers Pablo Neira Ayuso
2026-11-12 22:11 ` [PATCH nf,v7 4/6] netfilter: nfnetlink_queue: restrict NFQA_EXP " Pablo Neira Ayuso
2026-11-13 18:47   ` kernel test robot
2026-11-13 20:24   ` kernel test robot
2026-11-12 22:11 ` [PATCH nf,v7 5/6] netfilter: nfnetlink_queue: restrict upper verdict bitmask to queue and drop Pablo Neira Ayuso
2026-11-12 22:11 ` [PATCH nf,v7 6/6] netfilter: nfnetlink_queue: do not skip ct confirmation with userspace ct helpers Pablo Neira Ayuso

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.