Skip to content

Commit 79846fd

Browse files
tnqnSasha Levin
authored and
Sasha Levin
committed
netfilter: nf_tables: Fix a memory leak in nf_tables_updchain
[ Upstream commit 7eaf837 ] 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]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 16f55ac commit 79846fd

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

net/netfilter/nf_tables_api.c

+14-13
Original file line numberDiff line numberDiff line change
@@ -2621,19 +2621,6 @@ static int nf_tables_updchain(struct nft_ctx *ctx, u8 genmask, u8 policy,
26212621
}
26222622
}
26232623

2624-
if (nla[NFTA_CHAIN_COUNTERS]) {
2625-
if (!nft_is_base_chain(chain)) {
2626-
err = -EOPNOTSUPP;
2627-
goto err_hooks;
2628-
}
2629-
2630-
stats = nft_stats_alloc(nla[NFTA_CHAIN_COUNTERS]);
2631-
if (IS_ERR(stats)) {
2632-
err = PTR_ERR(stats);
2633-
goto err_hooks;
2634-
}
2635-
}
2636-
26372624
if (!(table->flags & NFT_TABLE_F_DORMANT) &&
26382625
nft_is_base_chain(chain) &&
26392626
!list_empty(&hook.list)) {
@@ -2648,6 +2635,20 @@ static int nf_tables_updchain(struct nft_ctx *ctx, u8 genmask, u8 policy,
26482635
}
26492636

26502637
unregister = true;
2638+
2639+
if (nla[NFTA_CHAIN_COUNTERS]) {
2640+
if (!nft_is_base_chain(chain)) {
2641+
err = -EOPNOTSUPP;
2642+
goto err_hooks;
2643+
}
2644+
2645+
stats = nft_stats_alloc(nla[NFTA_CHAIN_COUNTERS]);
2646+
if (IS_ERR(stats)) {
2647+
err = PTR_ERR(stats);
2648+
goto err_hooks;
2649+
}
2650+
}
2651+
26512652
err = -ENOMEM;
26522653
trans = nft_trans_alloc(ctx, NFT_MSG_NEWCHAIN,
26532654
sizeof(struct nft_trans_chain));

0 commit comments

Comments
 (0)