]> 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)
committerFlorian Westphal <fw@strlen.de>
Wed, 17 May 2023 12:18:28 +0000 (14:18 +0200)
commit61ae320a29b0540c16931816299eb86bf2b66c08
tree48e5506841851da08ed0dec596b74dca8b6c2c87
parente3c361b8acd636f5fe80c02849ca175201edf10c
netfilter: nft_set_rbtree: fix null deref on element insertion

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>
net/netfilter/nft_set_rbtree.c