xen-netfront: handle NULL returned by xdp_convert_buff_to_frame()
Subsystems (5)
PATCH v2 1/1 xen-netfront: handle NULL returned by xdp_convert_buff_to_frame()
The function xdp_convert_buff_to_frame() may return NULL if it fails to correctly convert the XDP buffer into an XDP frame due to memory constraints, internal errors, or invalid data. Failing to check for NULL may lead to a NULL pointer dereference if the result is used later in processing, potentially causing crashes, data corruption, or undefined behavior.
On XDP redirect failure, the associated page must be released explicitly if it was previously retained via get_page(). Failing to do so may result in a memory leak, as the pages reference count is not decremented.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- drivers/net/xen-netfront.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
drivers/net/xen-netfront.c +13 -6
@@ -985,20 +985,27 @@ static u32 xennet_run_xdp(struct netfront_queue *queue, struct page *pdata, act =bpf_prog_run_xdp (prog, xdp);switch (act) {case XDP_TX : -get_page (pdata); xdpf =xdp_convert_buff_to_frame (xdp); - err =xennet_xdp_xmit (queue->info->netdev,1 , &xdpf,0 ); -if (unlikely (!err)) -xdp_return_frame_rx_napi (xdpf); -else if (unlikely (err <0 )) +if (unlikely (!xdpf)) {trace_xdp_exception (queue->info->netdev, prog, act); +break ; + } +get_page (pdata); + err =xennet_xdp_xmit (queue->info->netdev,1 , &xdpf,0 ); +if (unlikely (err <=0 )) { +if (err <0 ) +trace_xdp_exception (queue->info->netdev, prog, act); +xdp_return_frame_rx_napi (xdpf); + }break ;case XDP_REDIRECT :get_page (pdata); err =xdp_do_redirect (queue->info->netdev, xdp, prog); *need_xdp_flush = true; -if (unlikely (err)) +if (unlikely (err)) {trace_xdp_exception (queue->info->netdev, prog, act); +xdp_return_buff (xdp); + }break ;case XDP_PASS :case XDP_DROP :
Signature · 1 line
2.43.0
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 8 lines · On Thu, 17 Apr 2025 12:21:17 +0000 you wrote:
The function
xdp_convert_buff_to_frame()may return NULL if it fails to correctly convert the XDP buffer into an XDP frame due to memory constraints, internal errors, or invalid data. Failing to check for NULL may lead to a NULL pointer dereference if the result is used later in processing, potentially causing crashes, data corruption, or undefined behavior.[...]
Here is the summary with links:
- [v2] xen-netfront: handle NULL returned by xdp_convert_buff_to_frame()
https://git.kernel.org/netdev/net/c/cc3628dcd851
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html