netfilter: nf_queue: hold reference on skb->dev
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH 1/1 netfilter: nf_queue: hold reference on skb->dev
Before NF_BR_LOCAL_IN, skb->dev is mangled in a way that results in state->in != skb->dev, which can result in UaF when accessing the bridge device if removed while in the queue.
Reported-by Ren Wei <[email protected]>
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- net/netfilter/nf_queue.c | 6 ++++++ net/netfilter/nfnetlink_queue.c | 3 +++ 2 files changed, 9 insertions(+)
net/netfilter/nf_queue.c +6 -0
@@ -59,8 +59,11 @@ static void nf_queue_sock_put(struct sock *sk)static void nf_queue_entry_release_refs (struct nf_queue_entry *entry) {struct nf_hook_state *state = &entry->state; +struct sk_buff *skb = entry->skb;/* Release those devices we held, or Alexey will kill me. */ +if (skb->dev) +dev_put (skb->dev);dev_put (state->in);dev_put (state->out);if (state->sk)
@@ -98,10 +101,13 @@ static void __nf_queue_entry_init_physdevs(struct nf_queue_entry *entry)bool nf_queue_entry_get_refs (struct nf_queue_entry *entry) {struct nf_hook_state *state = &entry->state; +struct sk_buff *skb = entry->skb;if (state->sk && !refcount_inc_not_zero (&state->sk->sk_refcnt))return false; +if (skb->dev) +dev_hold (skb->dev);dev_hold (state->in);dev_hold (state->out);
net/netfilter/nfnetlink_queue.c +3 -0
@@ -1212,6 +1212,9 @@ dev_cmp(struct nf_queue_entry *entry, unsigned long ifindex)if (physinif == ifindex || physoutif == ifindex)return 1 ;#endif +if (entry->skb->dev) +if (entry->skb->dev->ifindex == ifindex) +return 1 ;if (entry->state.in)if (entry->state.in->ifindex == ifindex)return 1 ;
Signature · 1 line
2.47.3
Florian Westphal
maintainerQuoted 16 lines · Pablo Neira Ayuso
Before
NF_BR_LOCAL_IN,skb->devis mangled in a way that results instate->in!=skb->dev, which can result in UaF when accessing the bridge device if removed while in the queue.Reported-by Ren Wei <[email protected]>Signed-off-by Pablo Neira Ayuso <[email protected]>--- net/netfilter/nf_queue.c | 6 ++++++ net/netfilter/nfnetlink_queue.c | 3 +++ 2 files changed, 9 insertions(+)net/netfilter/nf_queue.c +0
-0
net/netfilter/nf_queue.c static void nf_queue_sock_put(struct sock *sk) · line 66
Quoted 8 lines
net/netfilter/nf_queue.c +3
-0@@ -59,8 +59,11 @@ static void nf_queue_sock_put(struct sock *sk)static void nf_queue_entry_release_refs (struct nf_queue_entry *entry) {struct nf_hook_state *state = &entry->state; +struct sk_buff *skb = entry->skb;/* Release those devices we held, or Alexey will kill me. */ +if (skb->dev) +dev_put (skb->dev);
dev_hold/put(NULL) is safe, no need for NULL guard (and no need to resend).
Thanks for making a patch. I'll make a patch for the pptp/gre bug in case reporter remains silent.