Skip to content

Commit cc3628d

Browse files
Alexey Nepomnyashihkuba-moo
authored andcommitted
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. Cc: stable@vger.kernel.org # v5.9+ Fixes: 6c5aa6f ("xen networking: add basic XDP support for xen-netfront") Signed-off-by: Alexey Nepomnyashih <sdl@nppct.ru> Link: https://patch.msgid.link/20250417122118.1009824-1-sdl@nppct.ru Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 3a70120 commit cc3628d

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

drivers/net/xen-netfront.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -985,20 +985,27 @@ static u32 xennet_run_xdp(struct netfront_queue *queue, struct page *pdata,
985985
act = bpf_prog_run_xdp(prog, xdp);
986986
switch (act) {
987987
case XDP_TX:
988-
get_page(pdata);
989988
xdpf = xdp_convert_buff_to_frame(xdp);
989+
if (unlikely(!xdpf)) {
990+
trace_xdp_exception(queue->info->netdev, prog, act);
991+
break;
992+
}
993+
get_page(pdata);
990994
err = xennet_xdp_xmit(queue->info->netdev, 1, &xdpf, 0);
991-
if (unlikely(!err))
995+
if (unlikely(err <= 0)) {
996+
if (err < 0)
997+
trace_xdp_exception(queue->info->netdev, prog, act);
992998
xdp_return_frame_rx_napi(xdpf);
993-
else if (unlikely(err < 0))
994-
trace_xdp_exception(queue->info->netdev, prog, act);
999+
}
9951000
break;
9961001
case XDP_REDIRECT:
9971002
get_page(pdata);
9981003
err = xdp_do_redirect(queue->info->netdev, xdp, prog);
9991004
*need_xdp_flush = true;
1000-
if (unlikely(err))
1005+
if (unlikely(err)) {
10011006
trace_xdp_exception(queue->info->netdev, prog, act);
1007+
xdp_return_buff(xdp);
1008+
}
10021009
break;
10031010
case XDP_PASS:
10041011
case XDP_DROP:

0 commit comments

Comments
 (0)