Skip to content

Commit

Permalink
netfilter: fix use-after-free in NF_HOOK_LIST
Browse files Browse the repository at this point in the history
nf_hook() can free the skb, so we need to remove it from the list before
 calling, and add passed skbs to a sublist afterwards.

Fixes: 17266ee ("net: ipv4: listified version of ip_rcv")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Edward Cree <ecree@solarflare.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Edward Cree authored and David S. Miller committed Jul 9, 2018
1 parent 8c057ef commit 9f17dbf
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions include/linux/netfilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,16 @@ NF_HOOK_LIST(uint8_t pf, unsigned int hook, struct net *net, struct sock *sk,
int (*okfn)(struct net *, struct sock *, struct sk_buff *))
{
struct sk_buff *skb, *next;
struct list_head sublist;

INIT_LIST_HEAD(&sublist);
list_for_each_entry_safe(skb, next, head, list) {
int ret = nf_hook(pf, hook, net, sk, skb, in, out, okfn);
if (ret != 1)
list_del(&skb->list);
list_del(&skb->list);
if (nf_hook(pf, hook, net, sk, skb, in, out, okfn) == 1)
list_add_tail(&skb->list, &sublist);
}
/* Put passed packets back on main list */
list_splice(&sublist, head);
}

/* Call setsockopt() */
Expand Down

0 comments on commit 9f17dbf

Please sign in to comment.