Skip to content

Commit a40a6f6

Browse files
committed
Merge: netfilter: ipset: Fix race between IPSET_CMD_CREATE and IPSET_CMD_SWAP
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/3400 JIRA: https://issues.redhat.com/browse/RHEL-5434 Upstream Status: commit 7433b6d CVE: CVE-2023-42756 commit 7433b6d Author: Jozsef Kadlecsik <kadlec@netfilter.org> Date: Tue Sep 19 20:04:45 2023 +0200 netfilter: ipset: Fix race between IPSET_CMD_CREATE and IPSET_CMD_SWAP Kyle Zeng reported that there is a race between IPSET_CMD_ADD and IPSET_CMD_SWAP in netfilter/ip_set, which can lead to the invocation of `__ip_set_put` on a wrong `set`, triggering the `BUG_ON(set->ref == 0);` check in it. The race is caused by using the wrong reference counter, i.e. the ref counter instead of ref_netlink. Fixes: 24e2278 ("netfilter: ipset: Add schedule point in call_ad().") Reported-by: Kyle Zeng <zengyhkyle@gmail.com> Closes: https://lore.kernel.org/netfilter-devel/ZPZqetxOmH+w%2Fmyc@westworld/#r Tested-by: Kyle Zeng <zengyhkyle@gmail.com> Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org> Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Phil Sutter <psutter@redhat.com> Approved-by: Antoine Tenart <atenart@redhat.com> Approved-by: Michal Schmidt <mschmidt@redhat.com> Signed-off-by: Scott Weaver <scweaver@redhat.com>
2 parents 543563e + 5579e1e commit a40a6f6

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

net/netfilter/ipset/ip_set_core.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,14 @@ __ip_set_put(struct ip_set *set)
684684
/* set->ref can be swapped out by ip_set_swap, netlink events (like dump) need
685685
* a separate reference counter
686686
*/
687+
static void
688+
__ip_set_get_netlink(struct ip_set *set)
689+
{
690+
write_lock_bh(&ip_set_ref_lock);
691+
set->ref_netlink++;
692+
write_unlock_bh(&ip_set_ref_lock);
693+
}
694+
687695
static void
688696
__ip_set_put_netlink(struct ip_set *set)
689697
{
@@ -1697,11 +1705,11 @@ call_ad(struct net *net, struct sock *ctnl, struct sk_buff *skb,
16971705

16981706
do {
16991707
if (retried) {
1700-
__ip_set_get(set);
1708+
__ip_set_get_netlink(set);
17011709
nfnl_unlock(NFNL_SUBSYS_IPSET);
17021710
cond_resched();
17031711
nfnl_lock(NFNL_SUBSYS_IPSET);
1704-
__ip_set_put(set);
1712+
__ip_set_put_netlink(set);
17051713
}
17061714

17071715
ip_set_lock(set);

0 commit comments

Comments
 (0)