netfilter: fix nf_queue handling
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH 1/1 netfilter: fix nf_queue handling
nf_queue handling is broken since e3b37f11e6e4 ("netfilter: replace list_head with single linked list") for two reasons:
1) If the bypass flag is set on, there are no userspace listeners and we still have more hook entries to iterate over, then jump to the next hook. Otherwise accept the packet. On nf_reinject() path, the okfn() needs to be invoked.
2) We should not re-enter the same hook on packet reinjection. If the packet is accepted, we have to skip the current hook from where the packet was enqueued, otherwise the packets gets enqueued over and over again.
This restores the previous list_for_each_entry_continue() behaviour happening from nf_iterate() that was dealing with these two cases. This patch introduces a new nf_queue() wrapper function so this fix becomes simpler.
--- net/netfilter/core.c | 13 +++--------- net/netfilter/nf_internals.h | 2 +- net/netfilter/nf_queue.c | 48 +++++++++++++++++++++++++++++--------------- 3 files changed, 36 insertions(+), 27 deletions(-)
net/netfilter/core.c +3 -10
@@ -361,16 +361,9 @@ int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state)if (ret ==0 ) ret = -EPERM ; }else if ((verdict &NF_VERDICT_MASK ) ==NF_QUEUE ) { -int err; - -RCU_INIT_POINTER (state->hook_entries, entry); - err =nf_queue (skb, state, verdict >>NF_VERDICT_QBITS ); -if (err <0 ) { -if (err == -ESRCH && - (verdict &NF_VERDICT_FLAG_QUEUE_BYPASS )) - goto next_hook; -kfree_skb (skb); - } + ret =nf_queue (skb, state, &entry, verdict); +if (ret ==1 && entry) + goto next_hook; }return ret; }
net/netfilter/nf_internals.h +1 -1
@@ -18,7 +18,7 @@ unsigned int nf_iterate(struct sk_buff *skb, struct nf_hook_state *state,/* nf_queue.c */ int nf_queue (struct sk_buff *skb,struct nf_hook_state *state, -unsigned int queuenum); +struct nf_hook_entry **entryp,unsigned int verdict);void nf_queue_nf_hook_drop (struct net *net,const struct nf_hook_entry *entry);int __init netfilter_queue_init (void );
net/netfilter/nf_queue.c +32 -16
77 lines not on this page · raw message
Signature · 1 line
2.1.4