Skip to content

Commit 8ecd062

Browse files
Jozsef Kadlecsikummakynes
authored andcommitted
netfilter: ipset: Fix suspicious rcu_dereference_protected()
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]>
1 parent a876346 commit 8ecd062

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
@@ -53,12 +53,13 @@ MODULE_DESCRIPTION("core IP set support");
5353
MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_IPSET);
5454

5555
/* When the nfnl mutex or ip_set_ref_lock is held: */
56-
#define ip_set_dereference(p) \
57-
rcu_dereference_protected(p, \
56+
#define ip_set_dereference(inst) \
57+
rcu_dereference_protected((inst)->ip_set_list, \
5858
lockdep_nfnl_is_held(NFNL_SUBSYS_IPSET) || \
59-
lockdep_is_held(&ip_set_ref_lock))
59+
lockdep_is_held(&ip_set_ref_lock) || \
60+
(inst)->is_deleted)
6061
#define ip_set(inst, id) \
61-
ip_set_dereference((inst)->ip_set_list)[id]
62+
ip_set_dereference(inst)[id]
6263
#define ip_set_ref_netlink(inst,id) \
6364
rcu_dereference_raw((inst)->ip_set_list)[id]
6465
#define ip_set_dereference_nfnl(p) \
@@ -1133,7 +1134,7 @@ static int ip_set_create(struct sk_buff *skb, const struct nfnl_info *info,
11331134
if (!list)
11341135
goto cleanup;
11351136
/* nfnl mutex is held, both lists are valid */
1136-
tmp = ip_set_dereference(inst->ip_set_list);
1137+
tmp = ip_set_dereference(inst);
11371138
memcpy(list, tmp, sizeof(struct ip_set *) * inst->ip_set_max);
11381139
rcu_assign_pointer(inst->ip_set_list, list);
11391140
/* Make sure all current packets have passed through */

0 commit comments

Comments
 (0)