Skip to content

Commit 51210ad

Browse files
Florian Westphaldavem330
authored andcommitted
inet: do not call sublist_rcv on empty list
syzbot triggered struct net NULL deref in NF_HOOK_LIST: RIP: 0010:NF_HOOK_LIST include/linux/netfilter.h:331 [inline] RIP: 0010:ip6_sublist_rcv+0x5c9/0x930 net/ipv6/ip6_input.c:292 ipv6_list_rcv+0x373/0x4b0 net/ipv6/ip6_input.c:328 __netif_receive_skb_list_ptype net/core/dev.c:5274 [inline] Reason: void ipv6_list_rcv(struct list_head *head, struct packet_type *pt, struct net_device *orig_dev) [..] list_for_each_entry_safe(skb, next, head, list) { /* iterates list */ skb = ip6_rcv_core(skb, dev, net); /* ip6_rcv_core drops skb -> NULL is returned */ if (skb == NULL) continue; [..] } /* sublist is empty -> curr_net is NULL */ ip6_sublist_rcv(&sublist, curr_dev, curr_net); Before the recent change NF_HOOK_LIST did a list iteration before struct net deref, i.e. it was a no-op in the empty list case. List iteration now happens after *net deref, causing crash. Follow the same pattern as the ip(v6)_list_rcv loop and add a list_empty test for the final sublist dispatch too. Cc: Edward Cree <[email protected]> Reported-by: [email protected] Fixes: ca58fbe ("netfilter: add and use nf_hook_slow_list()") Signed-off-by: Florian Westphal <[email protected]> Tested-by: Leon Romanovsky <[email protected]> Tested-by: Nikolay Aleksandrov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent acda618 commit 51210ad

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

net/ipv4/ip_input.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,5 +611,6 @@ void ip_list_rcv(struct list_head *head, struct packet_type *pt,
611611
list_add_tail(&skb->list, &sublist);
612612
}
613613
/* dispatch final sublist */
614-
ip_sublist_rcv(&sublist, curr_dev, curr_net);
614+
if (!list_empty(&sublist))
615+
ip_sublist_rcv(&sublist, curr_dev, curr_net);
615616
}

net/ipv6/ip6_input.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ void ipv6_list_rcv(struct list_head *head, struct packet_type *pt,
325325
list_add_tail(&skb->list, &sublist);
326326
}
327327
/* dispatch final sublist */
328-
ip6_sublist_rcv(&sublist, curr_dev, curr_net);
328+
if (!list_empty(&sublist))
329+
ip6_sublist_rcv(&sublist, curr_dev, curr_net);
329330
}
330331

331332
INDIRECT_CALLABLE_DECLARE(int udpv6_rcv(struct sk_buff *));

0 commit comments

Comments
 (0)