[PATCH] netfilter: nf_dup_netdev: Fix net_device reference leak in nft_fwd_dup_netdev_offload()

Wentao Liang posted 1 patch 1 week, 1 day ago
net/netfilter/nf_dup_netdev.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH] netfilter: nf_dup_netdev: Fix net_device reference leak in nft_fwd_dup_netdev_offload()
Posted by Wentao Liang 1 week, 1 day ago
In nft_fwd_dup_netdev_offload(), dev_get_by_index() gets a reference to
the net_device corresponding to oif. When nft_flow_action_entry_next()
fails (returning NULL), the function returns -E2BIG directly without
dropping the net_device reference via dev_put(), causing a reference
leak.

Add dev_put(dev) before returning -E2BIG on failure.

Fixes: be2861dc36d7 ("netfilter: nft_{fwd,dup}_netdev: add offload support")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 net/netfilter/nf_dup_netdev.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/netfilter/nf_dup_netdev.c b/net/netfilter/nf_dup_netdev.c
index 3b0a70e154cd..dd627b7d72d9 100644
--- a/net/netfilter/nf_dup_netdev.c
+++ b/net/netfilter/nf_dup_netdev.c
@@ -80,8 +80,10 @@ int nft_fwd_dup_netdev_offload(struct nft_offload_ctx *ctx,
 		return -EOPNOTSUPP;
 
 	entry = nft_flow_action_entry_next(ctx, flow);
-	if (!entry)
+	if (!entry) {
+		dev_put(dev);
 		return -E2BIG;
+	}
 
 	entry->id = id;
 	entry->dev = dev;
-- 
2.34.1
Re: [PATCH] netfilter: nf_dup_netdev: Fix net_device reference leak in nft_fwd_dup_netdev_offload()
Posted by Xuanqiang Luo 1 week, 1 day ago
在 2026/9/16 15:36, Wentao Liang 写道:
> In nft_fwd_dup_netdev_offload(), dev_get_by_index() gets a reference to
> the net_device corresponding to oif. When nft_flow_action_entry_next()
> fails (returning NULL), the function returns -E2BIG directly without
> dropping the net_device reference via dev_put(), causing a reference
> leak.
> 
> Add dev_put(dev) before returning -E2BIG on failure.
> 
> Fixes: be2861dc36d7 ("netfilter: nft_{fwd,dup}_netdev: add offload support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
>   net/netfilter/nf_dup_netdev.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/net/netfilter/nf_dup_netdev.c b/net/netfilter/nf_dup_netdev.c
> index 3b0a70e154cd..dd627b7d72d9 100644
> --- a/net/netfilter/nf_dup_netdev.c
> +++ b/net/netfilter/nf_dup_netdev.c
> @@ -80,8 +80,10 @@ int nft_fwd_dup_netdev_offload(struct nft_offload_ctx *ctx,
>   		return -EOPNOTSUPP;
>   
>   	entry = nft_flow_action_entry_next(ctx, flow);
> -	if (!entry)
> +	if (!entry) {
> +		dev_put(dev);
>   		return -E2BIG;
> +	}
>   
>   	entry->id = id;
>   	entry->dev = dev;

Please update your local tree.

Florian Westphal has already fixed this issue:

https://lore.kernel.org/all/20260605114715.11297-1-fw@strlen.de/

Thanks!