* [PATCH net-next] net: Prevent use after free in netif_napi_set_irq_locked()
@ 2025-03-03 12:02 Dan Carpenter
2025-03-03 15:58 ` Ahmed Zaki
2025-03-05 2:40 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2025-03-03 12:02 UTC (permalink / raw)
To: Ahmed Zaki
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Kuniyuki Iwashima, Sebastian Andrzej Siewior,
Alexander Lobakin, netdev, linux-kernel, kernel-janitors
The cpu_rmap_put() will call kfree() when the last reference is dropped
so it could result in a use after free when we dereference the same
pointer the next line. Move the cpu_rmap_put() after the dereference.
Fixes: bd7c00605ee0 ("net: move aRFS rmap management and CPU affinity to core")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
net/core/dev.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/core/dev.c b/net/core/dev.c
index 9189c4a048d7..c102349e04ee 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -7072,8 +7072,8 @@ void netif_napi_set_irq_locked(struct napi_struct *napi, int irq)
put_rmap:
#ifdef CONFIG_RFS_ACCEL
if (napi->dev->rx_cpu_rmap_auto) {
- cpu_rmap_put(napi->dev->rx_cpu_rmap);
napi->dev->rx_cpu_rmap->obj[napi->napi_rmap_idx] = NULL;
+ cpu_rmap_put(napi->dev->rx_cpu_rmap);
napi->napi_rmap_idx = -1;
}
#endif
--
2.47.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] net: Prevent use after free in netif_napi_set_irq_locked()
2025-03-03 12:02 [PATCH net-next] net: Prevent use after free in netif_napi_set_irq_locked() Dan Carpenter
@ 2025-03-03 15:58 ` Ahmed Zaki
2025-03-05 2:40 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Ahmed Zaki @ 2025-03-03 15:58 UTC (permalink / raw)
To: Dan Carpenter
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Kuniyuki Iwashima, Sebastian Andrzej Siewior,
Alexander Lobakin, netdev, linux-kernel, kernel-janitors
On 2025-03-03 5:02 a.m., Dan Carpenter wrote:
> The cpu_rmap_put() will call kfree() when the last reference is dropped
> so it could result in a use after free when we dereference the same
> pointer the next line. Move the cpu_rmap_put() after the dereference.
The last call to cpu_rmap_put() that frees the rmap will always be in
netif_del_cpu_rmap(). This matches the ref counter initially set in
netif_enable_cpu_rmap().
>
> Fixes: bd7c00605ee0 ("net: move aRFS rmap management and CPU affinity to core")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
> net/core/dev.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/core/dev.c b/net/core/dev.c
> index 9189c4a048d7..c102349e04ee 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -7072,8 +7072,8 @@ void netif_napi_set_irq_locked(struct napi_struct *napi, int irq)
> put_rmap:
> #ifdef CONFIG_RFS_ACCEL
> if (napi->dev->rx_cpu_rmap_auto) {
> - cpu_rmap_put(napi->dev->rx_cpu_rmap);
> napi->dev->rx_cpu_rmap->obj[napi->napi_rmap_idx] = NULL;
> + cpu_rmap_put(napi->dev->rx_cpu_rmap);
> napi->napi_rmap_idx = -1;
> }
> #endif
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] net: Prevent use after free in netif_napi_set_irq_locked()
2025-03-03 12:02 [PATCH net-next] net: Prevent use after free in netif_napi_set_irq_locked() Dan Carpenter
2025-03-03 15:58 ` Ahmed Zaki
@ 2025-03-05 2:40 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-03-05 2:40 UTC (permalink / raw)
To: Dan Carpenter
Cc: ahmed.zaki, davem, edumazet, kuba, pabeni, horms, kuniyu, bigeasy,
aleksander.lobakin, netdev, linux-kernel, kernel-janitors
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Mon, 3 Mar 2025 15:02:12 +0300 you wrote:
> The cpu_rmap_put() will call kfree() when the last reference is dropped
> so it could result in a use after free when we dereference the same
> pointer the next line. Move the cpu_rmap_put() after the dereference.
>
> Fixes: bd7c00605ee0 ("net: move aRFS rmap management and CPU affinity to core")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
>
> [...]
Here is the summary with links:
- [net-next] net: Prevent use after free in netif_napi_set_irq_locked()
https://git.kernel.org/netdev/net-next/c/f252f23ab657
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-03-05 2:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-03 12:02 [PATCH net-next] net: Prevent use after free in netif_napi_set_irq_locked() Dan Carpenter
2025-03-03 15:58 ` Ahmed Zaki
2025-03-05 2:40 ` patchwork-bot+netdevbpf
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.