Skip to content

Commit

Permalink
netfilter: ipset: Fix suspicious rcu_dereference_protected()
Browse files Browse the repository at this point in the history
[ Upstream 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]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
Jozsef Kadlecsik authored and gregkh committed Jun 27, 2024
1 parent ff6bc8c commit 3fc09e1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions net/netfilter/ipset/ip_set_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ MODULE_DESCRIPTION("core IP set support");
MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_IPSET);

/* When the nfnl mutex or ip_set_ref_lock is held: */
#define ip_set_dereference(p) \
rcu_dereference_protected(p, \
#define ip_set_dereference(inst) \
rcu_dereference_protected((inst)->ip_set_list, \
lockdep_nfnl_is_held(NFNL_SUBSYS_IPSET) || \
lockdep_is_held(&ip_set_ref_lock))
lockdep_is_held(&ip_set_ref_lock) || \
(inst)->is_deleted)
#define ip_set(inst, id) \
ip_set_dereference((inst)->ip_set_list)[id]
ip_set_dereference(inst)[id]
#define ip_set_ref_netlink(inst,id) \
rcu_dereference_raw((inst)->ip_set_list)[id]
#define ip_set_dereference_nfnl(p) \
Expand Down Expand Up @@ -1133,7 +1134,7 @@ static int ip_set_create(struct sk_buff *skb, const struct nfnl_info *info,
if (!list)
goto cleanup;
/* nfnl mutex is held, both lists are valid */
tmp = ip_set_dereference(inst->ip_set_list);
tmp = ip_set_dereference(inst);
memcpy(list, tmp, sizeof(struct ip_set *) * inst->ip_set_max);
rcu_assign_pointer(inst->ip_set_list, list);
/* Make sure all current packets have passed through */
Expand Down

0 comments on commit 3fc09e1

Please sign in to comment.