]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
qede: fix off-by-one in BD ring consumption on build_skb failure
authorShigeru Yoshida <syoshida@redhat.com>
Tue, 30 Jun 2026 16:46:20 +0000 (01:46 +0900)
committerPaolo Abeni <pabeni@redhat.com>
Mon, 6 Jul 2026 10:03:10 +0000 (12:03 +0200)
qede_rx_build_skb() and qede_tpa_rx_build_skb() do not check for a
NULL return from qede_build_skb(). When it returns NULL under memory
pressure, the functions still consume a BD from the ring before
returning NULL. The callers then recycle additional BDs, resulting in
one extra BD being consumed (off-by-one). This desynchronizes the BD
ring, which can corrupt DMA page reference counts and lead to SLUB
freelist corruption.

Commit 4e910dbe3650 ("qede: confirm skb is allocated before using")
added a NULL check inside qede_build_skb() to prevent a NULL pointer
dereference, but did not address the missing NULL checks in the
callers, making this off-by-one reachable.

Fix this by adding NULL checks for the return value of
qede_build_skb() in both qede_rx_build_skb() and
qede_tpa_rx_build_skb(), returning NULL immediately before any BD ring
manipulation.

Fixes: 8a8633978b84 ("qede: Add build_skb() support.")
Signed-off-by: Shigeru Yoshida <syoshida@redhat.com>
Reviewed-by: Jamie Bainbridge <jamie.bainbridge@gmail.com>
Link: https://patch.msgid.link/20260630164623.3152625-1-syoshida@redhat.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/ethernet/qlogic/qede/qede_fp.c

index 33e18bb6977401a4a4c0edda77dced947cb60237..c11e0d8f98aa5c64763b17a8bbb29a1cd2bb7147 100644 (file)
@@ -765,6 +765,9 @@ qede_tpa_rx_build_skb(struct qede_dev *edev,
        struct sk_buff *skb;
 
        skb = qede_build_skb(rxq, bd, len, pad);
+       if (unlikely(!skb))
+               return NULL;
+
        bd->page_offset += rxq->rx_buf_seg_size;
 
        if (bd->page_offset == PAGE_SIZE) {
@@ -812,6 +815,8 @@ qede_rx_build_skb(struct qede_dev *edev,
        }
 
        skb = qede_build_skb(rxq, bd, len, pad);
+       if (unlikely(!skb))
+               return NULL;
 
        if (unlikely(qede_realloc_rx_buffer(rxq, bd))) {
                /* Incr page ref count to reuse on allocation failure so