From mboxrd@z Thu Jan 1 00:00:00 1970 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=1796387180; b=LyHPU5fd8HirDJzVs6PujbwYPVvb6VvWGeZHBZBCc4q55NBr5txPfQHlaPMnpnW94Vxd Q51VhqfdWTDmTEIzQlaUm8m11Nf2u1YnZJjNwRkvuIgM6H6krvIMkLU946e/DHeC32vnj 5t88SE6ME6/nipO3Fg/fZteyJoH7xrKWjcjzUtCkwUPXWxr8nGKO5TCrAG6FxZaPISen2 RLsM1peZKR9fQbnP4O2uFXvWl032Vvh51rZHw7yCjJSoQh8nnG8hByScT/TIVkRV8KFBy 9aGWIvDFOqLeSW/4VLwLTGKpiuB0U4I2qYl0QT+H0mOryfRx7xHGRF+W9V11hetqkAw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387180; 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=oE0olNYKX65VP7FYFwMDZOjn2PvHLBwTuMOsceZjf8U=; b=cxeQ+fopD3hg6eMmOA39Eu7LEAEkgGwfuHJECHC2Rvdn53osbT9zofoNmWhtFK5HhATZ X4zo80IQnbk8RDaRt+2I/OZTSU9B9k7i/DVwZnUf7YVzvaVDLN1M2rya4gzpeDctOujKg mk6ukJf7xIiYHin0+tNcnYSefwT5zw1ZKC5lpOtePXk9cINHUPFne9WY5woW9cnBlxVPa lB5ZadH1isIWCNoRwHXszp4RMb+TtNIY8pn7QxzlAWL/b+6/P3TGsBPTr0nDZz3ZBZ5pY YNOhgcQfdSgN5WPuDltr0TqHPJ5nVA9yKLjUfCZ0UDOOJa3Z1MR5oRZcY7bI/FxgrNg== 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=lqRMKi3j; 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 AECF1606A32F; Fri, 4 Dec 2026 12:26:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=lqRMKi3j Received: by smtp.kernel.org (Postfix) with ESMTPSA id 296F91F000CE; Fri, 4 Dec 2026 12:26:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387180; bh=oE0olNYKX65VP7FYFwMDZOjn2PvHLBwTuMOsceZjf8U=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=lqRMKi3jvhnU+Nq0CDeH7r2hw4+0DA/NqoncR4tB3ucXslP+cqWmPWGGp93mJZpD7 1YGql7nhG8A0J8aT4b9M+Zxvb3oaLKdqH8EdYnh0LhhD0AnO2OVC5rCt2KAr37/pXs 4oo2bFDR1ggRCOU7JgZbeBKPvlf8wIUhfDsDuS4A= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Xingyuan Mo , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 6.1 0135/1059] netfilter: nf_tables: fix memleak when rule deletion fails with hardware offload Date: Fri, 4 Dec 2026 18:54:26 +0900 Message-ID: <20261204100647.717315236@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@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 e95b3be75ae0652d40a48a210f0cf5197b3b3783 ] Allocate flow rule object after transaction has been allocation and rule deactivation has been performed, otherwise memleak is possible. Let the transaction unwind the existing rule deactivation from the abort path, this needs to update nft_flow_rule_destroy() to skip release if flow_rule is null. While at this, remove check for non-null flow_rule in newrule error path now that nft_flow_rule_destroy() is skipped if flow_rule is null. Fixes: 63b48c73ff56 ("netfilter: nf_tables_offload: undo updates if transaction fails") Reported-by: Xingyuan Mo Link: https://patch.msgid.link/20261028062204.1079089-1-hdthky0@gmail.com/ Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/nf_tables_api.c | 21 +++++++++------------ net/netfilter/nf_tables_offload.c | 3 +++ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index 99fba693ab4f6..1bf44559e00fd 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -519,16 +519,6 @@ static int nft_delrule(struct nft_ctx *ctx, struct nft_rule *rule) if (trans == NULL) return -ENOMEM; - if (ctx->chain->flags & NFT_CHAIN_HW_OFFLOAD) { - flow = nft_flow_rule_create(ctx->net, rule); - if (IS_ERR(flow)) { - nft_trans_destroy(trans); - return PTR_ERR(flow); - } - - nft_trans_flow_rule(trans) = flow; - } - err = nf_tables_delrule_deactivate(ctx, rule); if (err < 0) { nft_trans_destroy(trans); @@ -536,6 +526,14 @@ static int nft_delrule(struct nft_ctx *ctx, struct nft_rule *rule) } nft_rule_expr_deactivate(ctx, rule, NFT_TRANS_PREPARE); + if (ctx->chain->flags & NFT_CHAIN_HW_OFFLOAD) { + flow = nft_flow_rule_create(ctx->net, rule); + if (IS_ERR(flow)) + return PTR_ERR(flow); + + nft_trans_flow_rule(trans) = flow; + } + return 0; } @@ -3884,8 +3882,7 @@ static int nf_tables_newrule(struct sk_buff *skb, const struct nfnl_info *info, err_destroy_flow_rule: nft_use_dec_restore(&chain->use); err_destroy_flow: - if (flow) - nft_flow_rule_destroy(flow); + nft_flow_rule_destroy(flow); err_release_rule: nft_rule_expr_deactivate(&ctx, rule, NFT_TRANS_PREPARE_ERROR); nf_tables_rule_destroy(&ctx, rule); diff --git a/net/netfilter/nf_tables_offload.c b/net/netfilter/nf_tables_offload.c index 27907fa6f1571..6c91cba23d13e 100644 --- a/net/netfilter/nf_tables_offload.c +++ b/net/netfilter/nf_tables_offload.c @@ -147,6 +147,9 @@ void nft_flow_rule_destroy(struct nft_flow_rule *flow) struct flow_action_entry *entry; int i; + if (!flow) + return; + flow_action_for_each(i, entry, &flow->rule->action) { switch (entry->id) { case FLOW_ACTION_REDIRECT: -- 2.53.0