]> git.itanic.dy.fi Git - linux-stable/commit
netfilter: nft_set_rbtree: fix null deref on element insertion
authorFlorian Westphal <fw@strlen.de>
Thu, 11 May 2023 20:39:30 +0000 (22:39 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 24 May 2023 16:30:19 +0000 (17:30 +0100)
commita337706c1fb35aac3f26b48aca80421bdbe1d33a
treece7d4b66e5169e746ed0471d0d31583d805a07fc
parent110f8f59a822713ca5b4aa590f035c99c7b4900c
netfilter: nft_set_rbtree: fix null deref on element insertion

[ Upstream commit 61ae320a29b0540c16931816299eb86bf2b66c08 ]

There is no guarantee that rb_prev() will not return NULL in nft_rbtree_gc_elem():

general protection fault, probably for non-canonical address 0xdffffc0000000003: 0000 [#1] PREEMPT SMP KASAN
KASAN: null-ptr-deref in range [0x0000000000000018-0x000000000000001f]
 nft_add_set_elem+0x14b0/0x2990
  nf_tables_newsetelem+0x528/0xb30

Furthermore, there is a possible use-after-free while iterating,
'node' can be free'd so we need to cache the next value to use.

Fixes: c9e6978e2725 ("netfilter: nft_set_rbtree: Switch to node list walk for overlap detection")
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/netfilter/nft_set_rbtree.c