From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97B4A146A64; Tue, 23 Apr 2024 21:42:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713908579; cv=none; b=JeZc1NPi7I3TXlKp/6wtCWMcg+RFQ0Y6l3/SJ5Opw9Wmx499qgie8sZ1YhhwRz+1dPNXpmO2YTUHKsvameEJCGTxdApdOoFZNKtAu1OUbIdFlMZJaXcU5eg0HFhbYgk1lc0+q+K6MLk0v04tQAXUPXLooViLBAyV2SjAPqiIAu0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713908579; c=relaxed/simple; bh=3RwblOGXyXYwO2x2Qj8VedqnRCZk32FGvJXtvLKP/M8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T5Xf08fSg1gb6UJ7M81rTQkJAZVPgwC49P2V/ksVJdBcf2QF9IbcUnuypzM86O4pYqmM/kMCXyS1xc9HBWcJIwTfECBYGL0nQmbX68fNtWjwqmVPRqviv8vZBhSFLkMsCimVY4x0YG3GecMtMKap6gLX1keBmA0e1mcgseG5MCk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=n3mdhOBT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="n3mdhOBT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64091C3277B; Tue, 23 Apr 2024 21:42:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1713908579; bh=3RwblOGXyXYwO2x2Qj8VedqnRCZk32FGvJXtvLKP/M8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n3mdhOBTWIp7Dq5myGFAg8n0QHlHBINHdXhvoCffRwOGnQ8/nqY+gmIY2qYMmEG8d Zg9r1OIpkCztL3C3fQbzT17m7+dMj4BRlObZ9Cl2O2ma2upvSDWnI3Plgx/ZahQ+ar tpJ+J6WlE4Eo3kG3NHINcjTDMkvxufIHSU0EqEE8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ziyang Xuan , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 6.6 034/158] netfilter: nf_tables: Fix potential data-race in __nft_obj_type_get() Date: Tue, 23 Apr 2024 14:37:51 -0700 Message-ID: <20240423213856.852129497@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240423213855.696477232@linuxfoundation.org> References: <20240423213855.696477232@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ziyang Xuan [ Upstream commit d78d867dcea69c328db30df665be5be7d0148484 ] nft_unregister_obj() can concurrent with __nft_obj_type_get(), and there is not any protection when iterate over nf_tables_objects list in __nft_obj_type_get(). Therefore, there is potential data-race of nf_tables_objects list entry. Use list_for_each_entry_rcu() to iterate over nf_tables_objects list in __nft_obj_type_get(), and use rcu_read_lock() in the caller nft_obj_type_get() to protect the entire type query process. Fixes: e50092404c1b ("netfilter: nf_tables: add stateful objects") Signed-off-by: Ziyang Xuan Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/nf_tables_api.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index fe6ee16e2dbf4..387eee416b0bf 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -7468,7 +7468,7 @@ static const struct nft_object_type *__nft_obj_type_get(u32 objtype, u8 family) { const struct nft_object_type *type; - list_for_each_entry(type, &nf_tables_objects, list) { + list_for_each_entry_rcu(type, &nf_tables_objects, list) { if (type->family != NFPROTO_UNSPEC && type->family != family) continue; @@ -7484,9 +7484,13 @@ nft_obj_type_get(struct net *net, u32 objtype, u8 family) { const struct nft_object_type *type; + rcu_read_lock(); type = __nft_obj_type_get(objtype, family); - if (type != NULL && try_module_get(type->owner)) + if (type != NULL && try_module_get(type->owner)) { + rcu_read_unlock(); return type; + } + rcu_read_unlock(); lockdep_nfnl_nft_mutex_not_held(); #ifdef CONFIG_MODULES -- 2.43.0