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 7AB73143899; Tue, 23 Apr 2024 21:40:55 +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=1713908455; cv=none; b=tjX2vNOrkC7EYNZlXgemDvP7d6EGQN7sG2d7XZ9ZMdZh6ckCWHL5VNq1PGFB+Q/5NRzhxci96r6mDLQl8quQey4H+Xa5QsTjmuPFMXjwaw6H+jkHRVrh0vuzGjiR4a/926DFrp8mOzhkWiSFCyslHXTy9HwkVA+gcu7f0RGSvc4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713908455; c=relaxed/simple; bh=56HRluF1cyyfMlQwRGWdHSfpHpetGL0NEqZ9Vp91oYo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CRWXgbC0a3MZ2nllZoI0sE1xJ8UO+8GVvFjLHJOEwuDLk9diVK12+ert+BzlqyscR2RfbNfDaU2G/MOBJ5vFYxXdUEGL/WzoZdXLqSPskWmyjJ1xYojwELR5K2Kn09DvdkJMMzvlK5Z0wgH0B5MsDHfdXejt+vbF+ejUwhlzWL0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ndzR0/5+; 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="ndzR0/5+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44CE8C3277B; Tue, 23 Apr 2024 21:40:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1713908455; bh=56HRluF1cyyfMlQwRGWdHSfpHpetGL0NEqZ9Vp91oYo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ndzR0/5+e3lZZ7NzQQPyGqxyFwI5Qzz8mC2lzoTr+4CE/xakDrWRLwzke7tVRqHJ3 6FwO8gu2P12mZI7khNqi4Wh6U5xDOM1NjMgBJ1H3sz01MuGdVnD8YpLOfw4SIjRezz tPYJXquOHweWAloUqoFh3GYcxo/SMMVdEjfXK2H4= 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.8 014/158] netfilter: nf_tables: Fix potential data-race in __nft_expr_type_get() Date: Tue, 23 Apr 2024 14:37:16 -0700 Message-ID: <20240423213856.311244326@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240423213855.824778126@linuxfoundation.org> References: <20240423213855.824778126@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.8-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ziyang Xuan [ Upstream commit f969eb84ce482331a991079ab7a5c4dc3b7f89bf ] nft_unregister_expr() can concurrent with __nft_expr_type_get(), and there is not any protection when iterate over nf_tables_expressions list in __nft_expr_type_get(). Therefore, there is potential data-race of nf_tables_expressions list entry. Use list_for_each_entry_rcu() to iterate over nf_tables_expressions list in __nft_expr_type_get(), and use rcu_read_lock() in the caller nft_expr_type_get() to protect the entire type query process. Fixes: ef1f7df9170d ("netfilter: nf_tables: expression ops overloading") 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 21581bae700c4..a1cf875e5d35f 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -3048,7 +3048,7 @@ static const struct nft_expr_type *__nft_expr_type_get(u8 family, { const struct nft_expr_type *type, *candidate = NULL; - list_for_each_entry(type, &nf_tables_expressions, list) { + list_for_each_entry_rcu(type, &nf_tables_expressions, list) { if (!nla_strcmp(nla, type->name)) { if (!type->family && !candidate) candidate = type; @@ -3080,9 +3080,13 @@ static const struct nft_expr_type *nft_expr_type_get(struct net *net, if (nla == NULL) return ERR_PTR(-EINVAL); + rcu_read_lock(); type = __nft_expr_type_get(family, nla); - 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