From: Cong Wang Date: Sat, 21 Nov 2020 03:43:17 +0000 (-0800) Subject: netfilter: clear skb->next in NF_HOOK_LIST() X-Git-Tag: v4.19.161~56 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=5460d62d661c0fc53bfe83493821b1dc3dc969f4;p=users%2Fdwmw2%2Flinux.git netfilter: clear skb->next in NF_HOOK_LIST() NF_HOOK_LIST() uses list_del() to remove skb from the linked list, however, it is not sufficient as skb->next still points to other skb. We should just call skb_list_del_init() to clear skb->next, like the rest places which using skb list. This has been fixed in upstream by commit ca58fbe06c54 ("netfilter: add and use nf_hook_slow_list()"). Fixes: 9f17dbf04ddf ("netfilter: fix use-after-free in NF_HOOK_LIST") Reported-by: liuzx@knownsec.com Tested-by: liuzx@knownsec.com Cc: Florian Westphal Cc: Edward Cree Cc: stable@vger.kernel.org # between 4.19 and 5.4 Signed-off-by: Cong Wang Signed-off-by: Greg Kroah-Hartman --- diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h index 72cb19c3db6aa..9460a5635c90b 100644 --- a/include/linux/netfilter.h +++ b/include/linux/netfilter.h @@ -300,7 +300,7 @@ NF_HOOK_LIST(uint8_t pf, unsigned int hook, struct net *net, struct sock *sk, INIT_LIST_HEAD(&sublist); list_for_each_entry_safe(skb, next, head, list) { - list_del(&skb->list); + skb_list_del_init(skb); if (nf_hook(pf, hook, net, sk, skb, in, out, okfn) == 1) list_add_tail(&skb->list, &sublist); }