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 9F7A0143C5F; Tue, 23 Apr 2024 21:46:12 +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=1713908772; cv=none; b=mgIK4M2rAGLsnZGuirYhFQkFwoRoJlYsXlwz3Nwa9Mj8u713NNZTagNJ5z3xQ/w4rRvyPomL1SPGyuVTQSewgygKm8kTl7H94aySzgB4aoOvzPThZCj9Ry0eIE7BFk1TCQrHZs7s1EucEEJ2R2Gg0u2ItVYB5POWzi6E5sUK8QA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713908772; c=relaxed/simple; bh=MEKoaoS4AUBlCekRU48cV3ataNuJdfCIXuSOOr5vvMM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pRNpminf1WmKRohSyN3qKqffODWRFbclklx4lEk4wlL8LB9eRzzox8XOVWb2LhmHzTaNQP+EAGEI86BhUmVmAYULCbCBofstpCGbTQoYGvU2M1XiNP+i+okzuk/1ixkfhK+jjYnSXbOkXq7gTgaJkzqp8bZUgtKlJ0nZmY+IgHs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=xh5R8gaN; 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="xh5R8gaN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C5C3C32781; Tue, 23 Apr 2024 21:46:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1713908772; bh=MEKoaoS4AUBlCekRU48cV3ataNuJdfCIXuSOOr5vvMM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xh5R8gaNtKDmTGXkxGD6t9bkk+0yTLTT0KZ+/b7hB9TpkfMixuwNwpSl8gM4EG8pM h1l1zBY57s4dL5SosfE7YD/DXfTf+FwmpgjPIVCnnTpOHmYeTJUBQY4GLbYLmLt1eR PqcOsTxibW1r3onrNu19w1pEM0u7ktWFa8/R6Np4= 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 5.15 16/71] netfilter: nf_tables: Fix potential data-race in __nft_obj_type_get() Date: Tue, 23 Apr 2024 14:39:29 -0700 Message-ID: <20240423213844.677895832@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240423213844.122920086@linuxfoundation.org> References: <20240423213844.122920086@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 5.15-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 d0712553d2b06..3999b89793fce 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -7045,7 +7045,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; @@ -7061,9 +7061,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