Skip to content

Commit 031561c

Browse files
ummakynesgregkh
authored andcommitted
netfilter: nft_dynset: restore set element counter when failing to update
commit 05907f1 upstream. 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(), therefore, decrement the set element counter. Fixes: 22fe54d ("netfilter: nf_tables: add support for dynamic set updates") Signed-off-by: Pablo Neira Ayuso <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent a6c5c65 commit 031561c

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

net/netfilter/nft_set_hash.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ static bool nft_rhash_update(struct nft_set *set, const u32 *key,
143143
/* Another cpu may race to insert the element with the same key */
144144
if (prev) {
145145
nft_set_elem_destroy(set, he, true);
146+
atomic_dec(&set->nelems);
146147
he = prev;
147148
}
148149

@@ -152,6 +153,7 @@ static bool nft_rhash_update(struct nft_set *set, const u32 *key,
152153

153154
err2:
154155
nft_set_elem_destroy(set, he, true);
156+
atomic_dec(&set->nelems);
155157
err1:
156158
return false;
157159
}

0 commit comments

Comments
 (0)