Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: pablo@netfilter.org
Cc: netfilter-devel@vger.kernel.org, davem@davemloft.net,
	netdev@vger.kernel.org, kuba@kernel.org, pabeni@redhat.com,
	edumazet@kernel.org, horms@kernel.org, fw@strlen.de, ja@ssi.bg
Subject: Re: [PATCH net 13/15] netfilter: nf_tables: fix memleak when rule deletion fails with hardware offload
Date: Wed, 04 Nov 2026 14:29:27 +0000	[thread overview]
Message-ID: <179380256708.488856.2178919556830092736@kernel.org> (raw)
In-Reply-To: <20261103140308.591690-15-pablo@netfilter.org>

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit message calls the bug fixed in nft_delrule()
  (net/netfilter/nf_tables_api.c) a plain "memleak", but the old error…

--

netfilter: nf_tables: fix memleak when rule deletion fails with hardware offload

The patch moves the flow rule allocation in nft_delrule() so it runs after
the rule has been deactivated. This means the -ENOENT error path no longer
drops an already built flow rule. nft_flow_rule_destroy() now accepts a
NULL flow, and the NULL check in the nf_tables_newrule() error path is
removed.

Link: https://patch.msgid.link/20261028062204.1079089-1-hdthky0@gmail.com/

> Allocate flow rule object after transaction has been allocation and rule
> deactivation has been performed, otherwise memleak is possible.  Let the

[Severity: Low]

The code change looks correct. Should the commit message also mention the
net_device reference leak?

Before this patch, when nf_tables_delrule_deactivate() returned -ENOENT in
nft_delrule(), only the transaction was freed:

	err = nf_tables_delrule_deactivate(ctx, rule);
	if (err < 0) {
		nft_trans_destroy(trans);
		return err;
	}

nft_trans_destroy() only does kfree(trans). The flow rule already stored
in nft_trans_flow_rule(trans) never reached nft_flow_rule_destroy().

Take a rule in an NFT_CHAIN_HW_OFFLOAD chain that uses fwd or dup to a
device. For that rule, nft_fwd_dup_netdev_offload() in
net/netfilter/nf_dup_netdev.c holds a device reference that only
nft_flow_rule_destroy() drops:

	dev = dev_get_by_index(ctx->net, oif);
	...
	/* nft_flow_rule_destroy() releases the reference on this device. */
	entry->dev = dev;

So each failed delete leaked a netdev refcount as well as the memory. A
leaked refcount can leave unregister_netdevice() waiting for the device to
become free, and that blocks netns teardown.

This path is easy to reach. __nft_rule_lookup() matches only on
rule->handle and does no genmask check. Deleting the same handle twice in
one batch therefore hits the -ENOENT path in nft_delrule().

Could the changelog mention the netdev reference leak, so stable
backporters can judge the impact of this fix?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261103140308.591690-3-pablo%40netfilter.org

  reply	other threads:[~2026-11-04 14:29 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 14:02 [PATCH net,v2 00/15] Netfilter/IPVS fixes for net Pablo Neira Ayuso
2026-11-03 14:02 ` [PATCH nf-next] netfilter: flowtable: do not scrub as crossing netns Pablo Neira Ayuso
2026-11-03 14:08   ` netdev-bot+sinfo
2026-11-03 14:10     ` Pablo Neira Ayuso
2026-11-03 14:02 ` [PATCH net 01/15] netfilter: nft_reject: prevent unbounded recursion in output hooks Pablo Neira Ayuso
2026-11-03 14:08   ` netdev-bot+sinfo
2026-11-03 14:11     ` Pablo Neira Ayuso
2026-11-03 14:02 ` [PATCH net 02/15] ipvs: wait grace period while reusing dest from trash Pablo Neira Ayuso
2026-11-03 14:18   ` Julian Anastasov
2026-11-04 14:29   ` netdev-bot+sashiko
2026-11-04 17:51     ` Julian Anastasov
2026-11-03 14:02 ` [PATCH net 03/15] ipvs: Defer application parent freeing until after RCU readers Pablo Neira Ayuso
2026-11-03 14:02 ` [PATCH net 04/15] ipvs: fix protocol data lifetime during namespace teardown Pablo Neira Ayuso
2026-11-03 14:02 ` [PATCH net 05/15] ipvs: do not create conns from packets with port 0 Pablo Neira Ayuso
2026-11-04 14:29   ` netdev-bot+sashiko
2026-11-04 19:28     ` Julian Anastasov
2026-11-03 14:02 ` [PATCH net 06/15] netfilter: nf_conntrack: limit expectation master chain depth Pablo Neira Ayuso
2026-11-04 14:29   ` netdev-bot+sashiko
2026-11-03 14:03 ` [PATCH net 07/15] netfilter: nf_dup: preserve guard across NFQUEUE reinjection Pablo Neira Ayuso
2026-11-04 14:29   ` netdev-bot+sashiko
2026-11-03 14:03 ` [PATCH net 08/15] netfilter: flowtable: extend ct timeout of offloaded GRE flows Pablo Neira Ayuso
2026-11-03 14:03 ` [PATCH net 09/15] netfilter: nft_set_rbtree: check catchall_sync return before queue_done Pablo Neira Ayuso
2026-11-03 14:03 ` [PATCH net 10/15] netfilter: bridge: use DEBUG_NET_WARN_ON_ONCE in nf_ct_bridge_refrag() Pablo Neira Ayuso
2026-11-03 14:03 ` [PATCH net 11/15] netfilter: x_tables: check target name before accessing verdict Pablo Neira Ayuso
2026-11-03 14:03 ` [PATCH net 12/15] netfilter: nf_conntrack_sip: fix OOB read in ct_sip_parse_transport() Pablo Neira Ayuso
2026-11-03 14:03 ` [PATCH net 13/15] netfilter: nf_tables: fix memleak when rule deletion fails with hardware offload Pablo Neira Ayuso
2026-11-04 14:29   ` netdev-bot+sashiko [this message]
2026-11-03 14:03 ` [PATCH net 14/15] netfilter: xt_recent: do not call remove_proc_entry() under recent_lock Pablo Neira Ayuso
2026-11-03 14:03 ` [PATCH net 15/15] netfilter: nat: zero newrange before filling it in Pablo Neira Ayuso
2026-11-03 17:06 ` [PATCH net,v2 00/15] Netfilter/IPVS fixes for net Pablo Neira Ayuso
  -- strict thread matches above, loose matches on Subject: below --
2026-11-02  0:56 [PATCH net " Pablo Neira Ayuso
2026-11-02  0:56 ` [PATCH net 13/15] netfilter: nf_tables: fix memleak when rule deletion fails with hardware offload Pablo Neira Ayuso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179380256708.488856.2178919556830092736@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=fw@strlen.de \
    --cc=horms@kernel.org \
    --cc=ja@ssi.bg \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pablo@netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox