From: Pablo Neira Ayuso Date: Tue, 21 Jun 2022 12:01:41 +0000 (+0200) Subject: netfilter: nft_dynset: restore set element counter when failing to update X-Git-Tag: v5.15.73~2656 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=031561caa38a67cbf3084c38b8ebed52bbc1e602;p=platform%2Fkernel%2Flinux-rpi.git netfilter: nft_dynset: restore set element counter when failing to update commit 05907f10e235680cc7fb196810e4ad3215d5e648 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: 22fe54d5fefc ("netfilter: nf_tables: add support for dynamic set updates") Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman --- diff --git a/net/netfilter/nft_set_hash.c b/net/netfilter/nft_set_hash.c index df40314d..76de6c8 100644 --- a/net/netfilter/nft_set_hash.c +++ b/net/netfilter/nft_set_hash.c @@ -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; } @@ -152,6 +153,7 @@ out: err2: nft_set_elem_destroy(set, he, true); + atomic_dec(&set->nelems); err1: return false; }