]> git.itanic.dy.fi Git - linux-stable/commitdiff
netfilter: nf_tables: always increment set element count
authorFlorian Westphal <fw@strlen.de>
Thu, 11 May 2023 20:45:35 +0000 (22:45 +0200)
committerFlorian Westphal <fw@strlen.de>
Thu, 18 May 2023 06:48:54 +0000 (08:48 +0200)
At this time, set->nelems counter only increments when the set has
a maximum size.

All set elements decrement the counter unconditionally, this is
confusing.

Increment the counter unconditionally to make this symmetrical.
This would also allow changing the set maximum size after set creation
in a later patch.

Signed-off-by: Florian Westphal <fw@strlen.de>
net/netfilter/nf_tables_api.c

index 59fb8320ab4d7745ca08e5ffe58cf18c8c196487..7a61de80a8d1ecf93f52f9b315abf2d19a33c98f 100644 (file)
@@ -6541,10 +6541,13 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,
                goto err_element_clash;
        }
 
-       if (!(flags & NFT_SET_ELEM_CATCHALL) && set->size &&
-           !atomic_add_unless(&set->nelems, 1, set->size + set->ndeact)) {
-               err = -ENFILE;
-               goto err_set_full;
+       if (!(flags & NFT_SET_ELEM_CATCHALL)) {
+               unsigned int max = set->size ? set->size + set->ndeact : UINT_MAX;
+
+               if (!atomic_add_unless(&set->nelems, 1, max)) {
+                       err = -ENFILE;
+                       goto err_set_full;
+               }
        }
 
        nft_trans_elem(trans) = elem;