Skip to content

Commit 7eaf837

Browse files
tnqnummakynes
authored andcommitted
netfilter: nf_tables: Fix a memory leak in nf_tables_updchain
If nft_netdev_register_hooks() fails, the memory associated with nft_stats is not freed, causing a memory leak. This patch fixes it by moving nft_stats_alloc() down after nft_netdev_register_hooks() succeeds. Fixes: b9703ed ("netfilter: nf_tables: support for adding new devices to an existing netdev chain") Signed-off-by: Quan Tian <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 4a0e7f2 commit 7eaf837

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2631,19 +2631,6 @@ static int nf_tables_updchain(struct nft_ctx *ctx, u8 genmask, u8 policy,
26312631
}
26322632
}
26332633

2634-
if (nla[NFTA_CHAIN_COUNTERS]) {
2635-
if (!nft_is_base_chain(chain)) {
2636-
err = -EOPNOTSUPP;
2637-
goto err_hooks;
2638-
}
2639-
2640-
stats = nft_stats_alloc(nla[NFTA_CHAIN_COUNTERS]);
2641-
if (IS_ERR(stats)) {
2642-
err = PTR_ERR(stats);
2643-
goto err_hooks;
2644-
}
2645-
}
2646-
26472634
if (!(table->flags & NFT_TABLE_F_DORMANT) &&
26482635
nft_is_base_chain(chain) &&
26492636
!list_empty(&hook.list)) {
@@ -2658,6 +2645,20 @@ static int nf_tables_updchain(struct nft_ctx *ctx, u8 genmask, u8 policy,
26582645
}
26592646

26602647
unregister = true;
2648+
2649+
if (nla[NFTA_CHAIN_COUNTERS]) {
2650+
if (!nft_is_base_chain(chain)) {
2651+
err = -EOPNOTSUPP;
2652+
goto err_hooks;
2653+
}
2654+
2655+
stats = nft_stats_alloc(nla[NFTA_CHAIN_COUNTERS]);
2656+
if (IS_ERR(stats)) {
2657+
err = PTR_ERR(stats);
2658+
goto err_hooks;
2659+
}
2660+
}
2661+
26612662
err = -ENOMEM;
26622663
trans = nft_trans_alloc(ctx, NFT_MSG_NEWCHAIN,
26632664
sizeof(struct nft_trans_chain));

0 commit comments

Comments
 (0)