netfilter: ipset: Fix race between namespace cleanup and gc in the list:set type
authorJozsef Kadlecsik <kadlec@netfilter.org>
Tue, 4 Jun 2024 13:58:03 +0000 (15:58 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 11 Jun 2024 16:46:04 +0000 (18:46 +0200)
commit4e7aaa6b82d63e8ddcbfb56b4fd3d014ca586f10
tree36eb78cbe6d417fb885d8571bc649b7674df98bc
parentc4ab9da85b9df3692f861512fe6c9812f38b7471
netfilter: ipset: Fix race between namespace cleanup and gc in the list:set type

Lion Ackermann reported that there is a race condition between namespace cleanup
in ipset and the garbage collection of the list:set type. The namespace
cleanup can destroy the list:set type of sets while the gc of the set type is
waiting to run in rcu cleanup. The latter uses data from the destroyed set which
thus leads use after free. The patch contains the following parts:

- When destroying all sets, first remove the garbage collectors, then wait
  if needed and then destroy the sets.
- Fix the badly ordered "wait then remove gc" for the destroy a single set
  case.
- Fix the missing rcu locking in the list:set type in the userspace test
  case.
- Use proper RCU list handlings in the list:set type.

The patch depends on c1193d9bbbd3 (netfilter: ipset: Add list flush to cancel_gc).

Fixes: 97f7cf1cd80e (netfilter: ipset: fix performance regression in swap operation)
Reported-by: Lion Ackermann <nnamrec@gmail.com>
Tested-by: Lion Ackermann <nnamrec@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
net/netfilter/ipset/ip_set_core.c
net/netfilter/ipset/ip_set_list_set.c