]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
xsk: Fix fragment node deletion to prevent buffer leak
authorNikhil P. Rao <nikhil.rao@amd.com>
Wed, 25 Feb 2026 00:00:26 +0000 (00:00 +0000)
committerJakub Kicinski <kuba@kernel.org>
Sat, 28 Feb 2026 16:55:11 +0000 (08:55 -0800)
After commit b692bf9a7543 ("xsk: Get rid of xdp_buff_xsk::xskb_list_node"),
the list_node field is reused for both the xskb pool list and the buffer
free list, this causes a buffer leak as described below.

xp_free() checks if a buffer is already on the free list using
list_empty(&xskb->list_node). When list_del() is used to remove a node
from the xskb pool list, it doesn't reinitialize the node pointers.
This means list_empty() will return false even after the node has been
removed, causing xp_free() to incorrectly skip adding the buffer to the
free list.

Fix this by using list_del_init() instead of list_del() in all fragment
handling paths, this ensures the list node is reinitialized after removal,
allowing the list_empty() to work correctly.

Fixes: b692bf9a7543 ("xsk: Get rid of xdp_buff_xsk::xskb_list_node")
Acked-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Signed-off-by: Nikhil P. Rao <nikhil.rao@amd.com>
Link: https://patch.msgid.link/20260225000456.107806-2-nikhil.rao@amd.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/xdp_sock_drv.h
net/xdp/xsk.c

index 242e34f771cca6ad8af471f853a43bd9f0d822e8..aefc368449d590a7b5a8316d4a968fd24403cabd 100644 (file)
@@ -122,7 +122,7 @@ static inline void xsk_buff_free(struct xdp_buff *xdp)
                goto out;
 
        list_for_each_entry_safe(pos, tmp, xskb_list, list_node) {
-               list_del(&pos->list_node);
+               list_del_init(&pos->list_node);
                xp_free(pos);
        }
 
@@ -157,7 +157,7 @@ static inline struct xdp_buff *xsk_buff_get_frag(const struct xdp_buff *first)
        frag = list_first_entry_or_null(&xskb->pool->xskb_list,
                                        struct xdp_buff_xsk, list_node);
        if (frag) {
-               list_del(&frag->list_node);
+               list_del_init(&frag->list_node);
                ret = &frag->xdp;
        }
 
@@ -168,7 +168,7 @@ static inline void xsk_buff_del_frag(struct xdp_buff *xdp)
 {
        struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp);
 
-       list_del(&xskb->list_node);
+       list_del_init(&xskb->list_node);
 }
 
 static inline struct xdp_buff *xsk_buff_get_head(struct xdp_buff *first)
index 3b46bc635c4327da1ac96a18c43c0d0c2f96c14e..be882a8d473c3d44992577139e14899bb527643d 100644 (file)
@@ -186,7 +186,7 @@ static int xsk_rcv_zc(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len)
                err = __xsk_rcv_zc(xs, pos, len, contd);
                if (err)
                        goto err;
-               list_del(&pos->list_node);
+               list_del_init(&pos->list_node);
        }
 
        return 0;