veth: fix NAPI leak in XDP enable error path
Subsystems (2)
PATCH 1/1 veth: fix NAPI leak in XDP enable error path
During XDP enablement in veth, if xdp_rxq_info_reg() or xdp_rxq_info_reg_mem_model() fails, the driver rolls back the changes.
However, the rollback loop:
for (i--; i >= start; i--) {decrements the loop index 'i' before the first iteration. This correctly skips unregistering the rxq for the failed index 'i' (as registration failed or was already cleaned up), but it also erroneously skips calling netif_napi_deli() for rq[i].xdp_napi.
Since netif_napi_add() was already called for index 'i', this leaves a dangling napi_struct in the device's napi_list. When the veth device is later destroyed, the freed queue memory (which contains the leaked NAPI structure) can be reused.
The subsequent device teardown iterates the NAPI list and corrupts the reallocated memory, leading to UAF.
Fix this by explicitly deleting the NAPI association for the failed index 'i' before rolling back the successfully configured queues.
--- drivers/net/veth.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/veth.c +2 -0
@@ -1137,6 +1137,8 @@ static int veth_enable_xdp_range(struct net_device *dev, int start, int end, err_reg_mem:xdp_rxq_info_unreg (&priv->rq[i].xdp_rxq); err_rxq_reg: +if (!napi_already_on) +netif_napi_del (&priv->rq[i].xdp_napi);for (i--; i >= start; i--) {struct veth_rq *rq = &priv->rq[i];
Signature · 1 line
2.55.0.rc0.786.g65d90a0328-goog
Quoted 31 lines · Eric Dumazet
During XDP enablement in veth, if
xdp_rxq_info_reg()orxdp_rxq_info_reg_mem_model()fails, the driver rolls back the changes.However, the rollback loop:
for (i--; i >= start; i--) {decrements the loop index 'i' before the first iteration. This correctly skips unregistering the rxq for the failed index 'i' (as registration failed or was already cleaned up), but it also erroneously skips calling
netif_napi_deli()for rq[i].xdp_napi.Since
netif_napi_add()was already called for index 'i', this leaves a danglingnapi_structin the device'snapi_list. When the veth device is later destroyed, the freed queue memory (which contains the leaked NAPI structure) can be reused.The subsequent device teardown iterates the NAPI list and corrupts the reallocated memory, leading to UAF.
Fix this by explicitly deleting the NAPI association for the failed index 'i' before rolling back the successfully configured queues.
Fixes b02e5a0ebb17 ("xsk: Propagate napi_id to XDP socket Rx path")Reported-by Guenter Roeck <[email protected]>Signed-off-by Eric Dumazet <[email protected]>Cc Björn Töpel <[email protected]>Cc Daniel Borkmann <[email protected]>Cc Ilias Apalodimas <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Tariq Toukan <[email protected]>
Quoted 4 lines
--- drivers/net/veth.c | 2 ++ 1 file changed, 2 insertions(+)
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 4 lines · On Mon, 22 Jun 2026 11:18:25 +0000 you wrote:
During XDP enablement in veth, if
xdp_rxq_info_reg()orxdp_rxq_info_reg_mem_model()fails, the driver rolls back the changes.However, the rollback loop:
Quoted 8 lines
for (i--; i >= start; i--) {decrements the loop index 'i' before the first iteration. This correctly skips unregistering the rxq for the failed index 'i' (as registration failed or was already cleaned up), but it also erroneously skips calling
netif_napi_deli()for rq[i].xdp_napi.[...]
Here is the summary with links:
- [net] veth: fix NAPI leak in XDP enable error path
https://git.kernel.org/netdev/net/c/6739027cb72d
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html