diff mbox series

netfilter: nf_tables: fix percpu memory leak at nf_tables_addchain()

Message ID 41e415f2-3ca4-8e8a-a4b5-5044e7043131@I-love.SAKURA.ne.jp (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series netfilter: nf_tables: fix percpu memory leak at nf_tables_addchain() | expand

Checks

Context Check Description
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Tetsuo Handa Sept. 12, 2022, 1:58 p.m. UTC
It seems to me that percpu memory for chain stats started leaking since
commit 3bc158f8d0330f0a ("netfilter: nf_tables: map basechain priority to
hardware priority") when nft_chain_offload_priority() returned an error.

Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Fixes: 3bc158f8d0330f0a ("netfilter: nf_tables: map basechain priority to hardware priority")
---
The "netfilter: nf_tables: fix nft_counters_enabled underflow at nf_tables_addchain()" made
me wonder where free_percpu() is called when nft_basechain_init() returned an error. But I
don't know whether this patch is correct. Please check carefully.

 net/netfilter/nf_tables_api.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Pablo Neira Ayuso Sept. 12, 2022, 2:17 p.m. UTC | #1
On Mon, Sep 12, 2022 at 10:58:51PM +0900, Tetsuo Handa wrote:
> It seems to me that percpu memory for chain stats started leaking since
> commit 3bc158f8d0330f0a ("netfilter: nf_tables: map basechain priority to
> hardware priority") when nft_chain_offload_priority() returned an error.

Patch also LGTM. Thanks.

> Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> Fixes: 3bc158f8d0330f0a ("netfilter: nf_tables: map basechain priority to hardware priority")
> ---
> The "netfilter: nf_tables: fix nft_counters_enabled underflow at nf_tables_addchain()" made
> me wonder where free_percpu() is called when nft_basechain_init() returned an error. But I
> don't know whether this patch is correct. Please check carefully.
>
>  net/netfilter/nf_tables_api.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
> index e062754dc6cc..63c70141b3e5 100644
> --- a/net/netfilter/nf_tables_api.c
> +++ b/net/netfilter/nf_tables_api.c
> @@ -2243,6 +2243,7 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
>  		if (err < 0) {
>  			nft_chain_release_hook(&hook);
>  			kfree(basechain);
> +			free_percpu(stats);
>  			return err;
>  		}
>  		if (stats)
> -- 
> 2.18.4
Florian Westphal Sept. 15, 2022, 8:20 p.m. UTC | #2
Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> wrote:
> It seems to me that percpu memory for chain stats started leaking since
> commit 3bc158f8d0330f0a ("netfilter: nf_tables: map basechain priority to
> hardware priority") when nft_chain_offload_priority() returned an error.

Also applied, thanks.
diff mbox series

Patch

diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index e062754dc6cc..63c70141b3e5 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -2243,6 +2243,7 @@  static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
 		if (err < 0) {
 			nft_chain_release_hook(&hook);
 			kfree(basechain);
+			free_percpu(stats);
 			return err;
 		}
 		if (stats)