Skip to content

Commit 7845914

Browse files
author
Florian Westphal
committed
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>
1 parent 90e5b34 commit 7845914

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
/**
@@ -1743,11 +1736,7 @@ static void nft_pipapo_activate(const struct net *net,
17431736
const struct nft_set *set,
17441737
const struct nft_set_elem *elem)
17451738
{
1746-
struct nft_pipapo_elem *e;
1747-
1748-
e = pipapo_get(net, set, (const u8 *)elem->key.val.data, 0);
1749-
if (IS_ERR(e))
1750-
return;
1739+
struct nft_pipapo_elem *e = elem->priv;
17511740

17521741
nft_set_elem_change_active(net, set, &e->ext);
17531742
}
@@ -1961,10 +1950,6 @@ static void nft_pipapo_remove(const struct net *net, const struct nft_set *set,
19611950

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

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

0 commit comments

Comments
 (0)