Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793215057; b=C9YVRmvpATfQg6sUuuyF7QGypD2CpUvW0yMnEr3pPc2JX/7k2neYZxm1p4LCjnI5/pnv Dd+aFnnl1j/FWScQfLawLptpLWH3vEVcWIIxDa4ISzPmdchTBnyrLMztk08vhEiNwDizk svZ0e5FGpuma52AS4w6rNtL8/C/wnNt/TDC13Behd7WPLtn1MogvOcgMOAa2/BetIeZM9 S3C6EyiRbVGS6XHDEtCbLM71B6xx6HEJxfCabGisJpYiA+M45kjJCqtqEi6HKrurQdASN Juh2nVW5h/2aU134huHD244cpVhPUAmtKoer0EZdtQjja1sul6Q5fockk36AgXmL7Fg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793215057; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=QR6vMzcJQgHUnAzRyu/7UHECvb0iK/Tlpn3sqlPJFPQ=; b=acN0A0rWIz2jRCry3dBntcRC85i+S+VI2kF8xYvNldeb+in4+PdqJ9KjDUib9pXVnBHx ppjub23ko/+dJLeCZ2qoSJcQ3MfEZz/68QC5wom11VHd2epYWy0Xhv6vgHRC2X+eNB4k8 N66uJeVgGZlcDZvCqOtG/7xxUTlAFZlKpi0Cq/ia9BOJ4DOZ1U4ZqKcAgu63D1WZjWAbn xbKImnfaOOL7XFHzTFbl6J41O3E5OwFlsRyPM7IMCpHahFl40h95a83rrczVTyIBRIg4R Z4nxFuYx1mYlnYZkT/P50S/o7BD0Rt/6VR4sk8YoCurD4LAiZJLwZ+Rh8JqYvvh07cw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=x401TdOk; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4000A606A31C; Wed, 28 Oct 2026 19:17:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=x401TdOk Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91EFE1F01825; Wed, 28 Oct 2026 19:17:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1793215057; bh=QR6vMzcJQgHUnAzRyu/7UHECvb0iK/Tlpn3sqlPJFPQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=x401TdOkUX/woUNW3VmElRYI2G7LONMjAMnMena3KQ6wtNzlV3Kvv1h2m8vxTYhrZ 2TH80N+at+chcaoTztQVIaMt4W8rfHw254IALFNpP1seJcWeBN7HI6y++wTG2JuxIt Fmkyzd+NIN8E1Vau6WhM+ATWR/Xk5c/Pc8/YYcnM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 6.1 1076/1887] netfilter: nat: use kfree_rcu to release ops Date: Wed, 28 Oct 2026 17:52:52 +0100 Message-ID: <20261028170523.892687528@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261028170459.200466217@linuxfoundation.org> References: <20261028170459.200466217@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Pablo Neira Ayuso [ Upstream commit 6eda0d771f94267f73f57c94630aa47e90957915 ] Florian Westphal says: "Historically this is not an issue, even for normal base hooks: the data path doesn't use the original nf_hook_ops that are used to register the callbacks. However, in v5.14 I added the ability to dump the active netfilter hooks from userspace. This code will peek back into the nf_hook_ops that are available at the tail of the pointer-array blob used by the datapath. The nat hooks are special, because they are called indirectly from the central nat dispatcher hook. They are currently invisible to the nfnl hook dump subsystem though. But once that changes the nat ops structures have to be deferred too." Update nf_nat_register_fn() to deal with partial exposition of the hooks from error path which can be also an issue for nfnetlink_hook. Fixes: e2cf17d3774c ("netfilter: add new hook nfnl subsystem") Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- include/linux/netfilter.h | 2 ++ net/ipv4/netfilter/iptable_nat.c | 4 ++-- net/ipv6/netfilter/ip6table_nat.c | 4 ++-- net/netfilter/nf_nat_core.c | 10 ++++++---- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h index e5f4b6f8d1c09..caa775ec9ac94 100644 --- a/include/linux/netfilter.h +++ b/include/linux/netfilter.h @@ -83,6 +83,8 @@ enum nf_hook_ops_type { }; struct nf_hook_ops { + struct rcu_head rcu; + /* User fills in from here down. */ nf_hookfn *hook; struct net_device *dev; diff --git a/net/ipv4/netfilter/iptable_nat.c b/net/ipv4/netfilter/iptable_nat.c index 12ca666d6e2c1..a8fe357bc6ecc 100644 --- a/net/ipv4/netfilter/iptable_nat.c +++ b/net/ipv4/netfilter/iptable_nat.c @@ -79,7 +79,7 @@ static int ipt_nat_register_lookups(struct net *net) while (i) nf_nat_ipv4_unregister_fn(net, &ops[--i]); - kfree(ops); + kfree_rcu(ops, rcu); return ret; } } @@ -100,7 +100,7 @@ static void ipt_nat_unregister_lookups(struct net *net) for (i = 0; i < ARRAY_SIZE(nf_nat_ipv4_ops); i++) nf_nat_ipv4_unregister_fn(net, &ops[i]); - kfree(ops); + kfree_rcu(ops, rcu); } static int iptable_nat_table_init(struct net *net) diff --git a/net/ipv6/netfilter/ip6table_nat.c b/net/ipv6/netfilter/ip6table_nat.c index 52d597b16b658..21957d53e9c95 100644 --- a/net/ipv6/netfilter/ip6table_nat.c +++ b/net/ipv6/netfilter/ip6table_nat.c @@ -81,7 +81,7 @@ static int ip6t_nat_register_lookups(struct net *net) while (i) nf_nat_ipv6_unregister_fn(net, &ops[--i]); - kfree(ops); + kfree_rcu(ops, rcu); return ret; } } @@ -102,7 +102,7 @@ static void ip6t_nat_unregister_lookups(struct net *net) for (i = 0; i < ARRAY_SIZE(nf_nat_ipv6_ops); i++) nf_nat_ipv6_unregister_fn(net, &ops[i]); - kfree(ops); + kfree_rcu(ops, rcu); } static int ip6table_nat_table_init(struct net *net) diff --git a/net/netfilter/nf_nat_core.c b/net/netfilter/nf_nat_core.c index 6586cce471eb6..47416bafd2c05 100644 --- a/net/netfilter/nf_nat_core.c +++ b/net/netfilter/nf_nat_core.c @@ -1050,9 +1050,11 @@ int nf_nat_register_fn(struct net *net, u8 pf, const struct nf_hook_ops *ops, ret = nf_register_net_hooks(net, nat_ops, ops_count); if (ret < 0) { mutex_unlock(&nf_nat_proto_mutex); - for (i = 0; i < ops_count; i++) - kfree(nat_ops[i].priv); - kfree(nat_ops); + for (i = 0; i < ops_count; i++) { + priv = nat_ops[i].priv; + kfree_rcu(priv, rcu_head); + } + kfree_rcu(nat_ops, rcu); return ret; } @@ -1116,7 +1118,7 @@ void nf_nat_unregister_fn(struct net *net, u8 pf, const struct nf_hook_ops *ops, } nat_proto_net->nat_hook_ops = NULL; - kfree(nat_ops); + kfree_rcu(nat_ops, rcu); } unlock: mutex_unlock(&nf_nat_proto_mutex); -- 2.53.0