Skip to content

Commit 04db0a5

Browse files
committed
netfilter: ipset: Fix suspicious rcu_dereference_protected()
jira LE-3201 cve CVE-2024-39503 Rebuild_History Non-Buildable kernel-rt-4.18.0-553.27.1.rt7.368.el8_10 commit-author Jozsef Kadlecsik <[email protected]> commit 8ecd062 When destroying all sets, we are either in pernet exit phase or are executing a "destroy all sets command" from userspace. The latter was taken into account in ip_set_dereference() (nfnetlink mutex is held), but the former was not. The patch adds the required check to rcu_dereference_protected() in ip_set_dereference(). Fixes: 4e7aaa6 ("netfilter: ipset: Fix race between namespace cleanup and gc in the list:set type") Reported-by: [email protected] Reported-by: [email protected] Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-lkp/[email protected] Signed-off-by: Jozsef Kadlecsik <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]> (cherry picked from commit 8ecd062) Signed-off-by: Jonathan Maple <[email protected]>
1 parent 9ac5742 commit 04db0a5

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

net/netfilter/ipset/ip_set_core.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@ MODULE_DESCRIPTION("core IP set support");
5656
MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_IPSET);
5757

5858
/* When the nfnl mutex or ip_set_ref_lock is held: */
59-
#define ip_set_dereference(p) \
60-
rcu_dereference_protected(p, \
59+
#define ip_set_dereference(inst) \
60+
rcu_dereference_protected((inst)->ip_set_list, \
6161
lockdep_nfnl_is_held(NFNL_SUBSYS_IPSET) || \
62-
lockdep_is_held(&ip_set_ref_lock))
62+
lockdep_is_held(&ip_set_ref_lock) || \
63+
(inst)->is_deleted)
6364
#define ip_set(inst, id) \
64-
ip_set_dereference((inst)->ip_set_list)[id]
65+
ip_set_dereference(inst)[id]
6566
#define ip_set_ref_netlink(inst,id) \
6667
rcu_dereference_raw((inst)->ip_set_list)[id]
6768
#define ip_set_dereference_nfnl(p) \
@@ -986,7 +987,7 @@ static int ip_set_create(struct net *net, struct sock *ctnl,
986987
if (!list)
987988
goto cleanup;
988989
/* nfnl mutex is held, both lists are valid */
989-
tmp = ip_set_dereference(inst->ip_set_list);
990+
tmp = ip_set_dereference(inst);
990991
memcpy(list, tmp, sizeof(struct ip_set *) * inst->ip_set_max);
991992
rcu_assign_pointer(inst->ip_set_list, list);
992993
/* Make sure all current packets have passed through */

0 commit comments

Comments
 (0)