netfilter: nft_dynset: restore set element counter when failing to update
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH 1/1 netfilter: nft_dynset: restore set element counter when failing to update
This patch fixes a race condition.
nft_rhash_update() might fail for two reasons:
- Element already exists in the hashtable.
- Another packet won race to insert an entry in the hashtable.
In both cases, new() has already bumped the counter via atomic_add_unless(). Decrement the set element counter in this case.
Fixes 22fe54d5fefc ("netfilter: nf_tables: add support for dynamic set updates")
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- net/netfilter/nft_set_hash.c | 2 ++ 1 file changed, 2 insertions(+)
net/netfilter/nft_set_hash.c +2 -0
@@ -143,6 +143,7 @@ static bool nft_rhash_update(struct nft_set *set, const u32 *key,/* Another cpu may race to insert the element with the same key */ if (prev) {nft_set_elem_destroy (set, he, true); +atomic_dec (&set->nelems); he = prev; }
@@ -151,6 +152,7 @@ static bool nft_rhash_update(struct nft_set *set, const u32 *key,return true; err2: +atomic_dec (&set->nelems);nft_set_elem_destroy (set, he, true); err1:return false;
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerQuoted 9 lines · Pablo Neira Ayuso
This patch fixes a race condition.
nft_rhash_update()might fail for two reasons:- Element already exists in the hashtable.
- Another packet won race to insert an entry in the hashtable.In both cases,
new()has already bumped the counter viaatomic_add_unless(). Decrement the set element counter in this case.
For the record: I'll place this in nf.git.