Skip to content

Commit 5911169

Browse files
committed
netfilter: nf_tables: don't fail inserts if duplicate has expired
JIRA: https://issues.redhat.com/browse/RHEL-1720 JIRA: https://issues.redhat.com/browse/RHEL-1721 Upstream Status: commit 7845914 commit 7845914 Author: Florian Westphal <fw@strlen.de> Date: Sat Aug 12 20:03:57 2023 +0200 netfilter: nf_tables: don't fail inserts if duplicate has expired nftables selftests fail: run-tests.sh testcases/sets/0044interval_overlap_0 Expected: 0-2 . 0-3, got: W: [FAILED] ./testcases/sets/0044interval_overlap_0: got 1 Insertion must ignore duplicate but expired entries. Moreover, there is a strange asymmetry in nft_pipapo_activate: It refetches the current element, whereas the other ->activate callbacks (bitmap, hash, rhash, rbtree) use elem->priv. Same for .remove: other set implementations take elem->priv, nft_pipapo_remove fetches elem->priv, then does a relookup, remove this. I suspect this was the reason for the change that prompted the removal of the expired check in pipapo_get() in the first place, but skipping exired elements there makes no sense to me, this helper is used for normal get requests, insertions (duplicate check) and deactivate callback. In first two cases expired elements must be skipped. For ->deactivate(), this gets called for DELSETELEM, so it seems to me that expired elements should be skipped as well, i.e. delete request should fail with -ENOENT error. Fixes: 2413893 ("netfilter: nf_tables: don't skip expired elements during walk") Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Florian Westphal <fwestpha@redhat.com>
1 parent 94d514d commit 5911169

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

net/netfilter/nft_set_pipapo.c

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,8 @@ static struct nft_pipapo_elem *pipapo_get(const struct net *net,
566566
goto out;
567567

568568
if (last) {
569+
if (nft_set_elem_expired(&f->mt[b].e->ext))
570+
goto next_match;
569571
if ((genmask &&
570572
!nft_set_elem_active(&f->mt[b].e->ext, genmask)))
571573
goto next_match;
@@ -600,17 +602,8 @@ static struct nft_pipapo_elem *pipapo_get(const struct net *net,
600602
static void *nft_pipapo_get(const struct net *net, const struct nft_set *set,
601603
const struct nft_set_elem *elem, unsigned int flags)
602604
{
603-
struct nft_pipapo_elem *ret;
604-
605-
ret = pipapo_get(net, set, (const u8 *)elem->key.val.data,
605+
return pipapo_get(net, set, (const u8 *)elem->key.val.data,
606606
nft_genmask_cur(net));
607-
if (IS_ERR(ret))
608-
return ret;
609-
610-
if (nft_set_elem_expired(&ret->ext))
611-
return ERR_PTR(-ENOENT);
612-
613-
return ret;
614607
}
615608

616609
/**
@@ -1744,11 +1737,7 @@ static void nft_pipapo_activate(const struct net *net,
17441737
const struct nft_set *set,
17451738
const struct nft_set_elem *elem)
17461739
{
1747-
struct nft_pipapo_elem *e;
1748-
1749-
e = pipapo_get(net, set, (const u8 *)elem->key.val.data, 0);
1750-
if (IS_ERR(e))
1751-
return;
1740+
struct nft_pipapo_elem *e = elem->priv;
17521741

17531742
nft_set_elem_change_active(net, set, &e->ext);
17541743
}
@@ -1962,10 +1951,6 @@ static void nft_pipapo_remove(const struct net *net, const struct nft_set *set,
19621951

19631952
data = (const u8 *)nft_set_ext_key(&e->ext);
19641953

1965-
e = pipapo_get(net, set, data, 0);
1966-
if (IS_ERR(e))
1967-
return;
1968-
19691954
while ((rules_f0 = pipapo_rules_same_key(m->f, first_rule))) {
19701955
union nft_pipapo_map_bucket rulemap[NFT_PIPAPO_MAX_FIELDS];
19711956
const u8 *match_start, *match_end;

0 commit comments

Comments
 (0)