* [PATCH net] net: mana: restore the XDP program pointer when pre-allocation fails
@ 2026-09-04 20:26 Long Li
2026-09-08 9:43 ` Simon Horman
2026-09-10 15:20 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Long Li @ 2026-09-04 20:26 UTC (permalink / raw)
To: Long Li, Konstantin Taranov, Jakub Kicinski, David S . Miller,
Paolo Abeni, Eric Dumazet, Andrew Lunn, Jason Gunthorpe,
Leon Romanovsky, Haiyang Zhang, K . Y . Srinivasan, Wei Liu,
Dexuan Cui, shradhagupta, Simon Horman, ernis, stephen,
shirazsaleem
Cc: netdev, linux-rdma, linux-hyperv, linux-kernel, bpf, sdf, daniel,
hawk, ast, john.fastabend
mana_xdp_set() publishes the new program into apc->bpf_prog before it
allocates anything, because mana_pre_alloc_rxbufs() sizes the buffers
from it via mana_get_rxbuf_cfg(). When that allocation fails the
function returns the error directly, skipping the err_dealloc_rxbuffs
label which is the only place that restores the previous pointer.
The attach is reported as failed, so the BPF core drops the reference it
held for the caller and the program can be freed, while apc->bpf_prog
still points at it. The next consumer of mana_xdp_get() - typically
mana_chn_setxdp() from mana_alloc_queues() on the following ifup, or
after a TX timeout reset - then calls bpf_prog_add() on freed memory.
This is reachable from an ordinary "ip link set dev ethX xdp obj ..."
whenever the per-queue RX buffer pre-allocation cannot be satisfied.
Restore the previous program on that error path.
Fixes: 730ff06d3f5c ("net: mana: Use page pool fragments for RX buffers instead of full pages to improve memory efficiency.")
Signed-off-by: Long Li <longli@microsoft.com>
---
drivers/net/ethernet/microsoft/mana/mana_bpf.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/net/ethernet/microsoft/mana/mana_bpf.c b/drivers/net/ethernet/microsoft/mana/mana_bpf.c
index 53308e139cbe917b074dd381c83546fc74d7b79f..5c9961ee9747ab7747ce2f51eb40f3e7a55510cf 100644
--- a/drivers/net/ethernet/microsoft/mana/mana_bpf.c
+++ b/drivers/net/ethernet/microsoft/mana/mana_bpf.c
@@ -208,6 +208,7 @@ static int mana_xdp_set(struct net_device *ndev, struct bpf_prog *prog,
if (err) {
NL_SET_ERR_MSG_MOD(extack,
"XDP: Insufficient memory for tx/rx re-config");
+ apc->bpf_prog = old_prog;
return err;
}
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH net] net: mana: restore the XDP program pointer when pre-allocation fails
2026-09-04 20:26 [PATCH net] net: mana: restore the XDP program pointer when pre-allocation fails Long Li
@ 2026-09-08 9:43 ` Simon Horman
2026-09-10 15:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Simon Horman @ 2026-09-08 9:43 UTC (permalink / raw)
To: Long Li
Cc: Konstantin Taranov, Jakub Kicinski, David S . Miller,
Paolo Abeni, Eric Dumazet, Andrew Lunn, Jason Gunthorpe,
Leon Romanovsky, Haiyang Zhang, K . Y . Srinivasan, Wei Liu,
Dexuan Cui, shradhagupta, ernis, stephen, shirazsaleem, netdev,
linux-rdma, linux-hyperv, linux-kernel, bpf, sdf, daniel, hawk,
ast, john.fastabend
On Fri, Sep 04, 2026 at 01:26:40PM -0700, Long Li wrote:
> mana_xdp_set() publishes the new program into apc->bpf_prog before it
> allocates anything, because mana_pre_alloc_rxbufs() sizes the buffers
> from it via mana_get_rxbuf_cfg(). When that allocation fails the
> function returns the error directly, skipping the err_dealloc_rxbuffs
> label which is the only place that restores the previous pointer.
>
> The attach is reported as failed, so the BPF core drops the reference it
> held for the caller and the program can be freed, while apc->bpf_prog
> still points at it. The next consumer of mana_xdp_get() - typically
> mana_chn_setxdp() from mana_alloc_queues() on the following ifup, or
> after a TX timeout reset - then calls bpf_prog_add() on freed memory.
>
> This is reachable from an ordinary "ip link set dev ethX xdp obj ..."
> whenever the per-queue RX buffer pre-allocation cannot be satisfied.
>
> Restore the previous program on that error path.
>
> Fixes: 730ff06d3f5c ("net: mana: Use page pool fragments for RX buffers instead of full pages to improve memory efficiency.")
> Signed-off-by: Long Li <longli@microsoft.com>
Reviewed-by: Simon Horman <horms@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH net] net: mana: restore the XDP program pointer when pre-allocation fails
2026-09-04 20:26 [PATCH net] net: mana: restore the XDP program pointer when pre-allocation fails Long Li
2026-09-08 9:43 ` Simon Horman
@ 2026-09-10 15:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-09-10 15:20 UTC (permalink / raw)
To: Long Li
Cc: kotaranov, kuba, davem, pabeni, edumazet, andrew+netdev, jgg,
leon, haiyangz, kys, wei.liu, decui, shradhagupta, horms, ernis,
stephen, shirazsaleem, netdev, linux-rdma, linux-hyperv,
linux-kernel, bpf, sdf, daniel, hawk, ast, john.fastabend
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Fri, 4 Sep 2026 13:26:40 -0700 you wrote:
> mana_xdp_set() publishes the new program into apc->bpf_prog before it
> allocates anything, because mana_pre_alloc_rxbufs() sizes the buffers
> from it via mana_get_rxbuf_cfg(). When that allocation fails the
> function returns the error directly, skipping the err_dealloc_rxbuffs
> label which is the only place that restores the previous pointer.
>
> The attach is reported as failed, so the BPF core drops the reference it
> held for the caller and the program can be freed, while apc->bpf_prog
> still points at it. The next consumer of mana_xdp_get() - typically
> mana_chn_setxdp() from mana_alloc_queues() on the following ifup, or
> after a TX timeout reset - then calls bpf_prog_add() on freed memory.
>
> [...]
Here is the summary with links:
- [net] net: mana: restore the XDP program pointer when pre-allocation fails
https://git.kernel.org/netdev/net/c/4c46beb807ef
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:[~2026-09-10 15:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-04 20:26 [PATCH net] net: mana: restore the XDP program pointer when pre-allocation fails Long Li
2026-09-08 9:43 ` Simon Horman
2026-09-10 15:20 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®