__xskq_cons_peek() trusts the userspace-controlled producer index without checking that the producer-consumer distance fits in the ring. In __xp_alloc(), an invalid fill descriptor is consumed one at a time until the cached producer is reached. A one-entry ring with an invalid address and a forged producer index can therefore keep the kernel in this loop for billions of iterations in receive context. Treat producer values beyond the ring capacity as an empty queue. This bounds the consumer to the userspace-provided ring size and prevents the long loop. Fixes: c5ed924b54c8 ("xsk: Simplify the consumer ring access functions") Cc: stable@vger.kernel.org Reported-by: Vega Link: https://bugtracker.nebusec.ai/f/13760 Assisted-by: LLM Signed-off-by: Zhiling Zou --- net/xdp/xsk_queue.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/xdp/xsk_queue.h b/net/xdp/xsk_queue.h index 1bc42c8902f4b..315b656534749 100644 --- a/net/xdp/xsk_queue.h +++ b/net/xdp/xsk_queue.h @@ -344,6 +344,9 @@ static inline void __xskq_cons_peek(struct xsk_queue *q) { /* Refresh the local pointer */ q->cached_prod = smp_load_acquire(&q->ring->producer); /* C, matches B */ + /* A malformed producer must not make us consume beyond the ring. */ + if (q->cached_prod - q->cached_cons > q->nentries) + q->cached_prod = q->cached_cons; } static inline void xskq_cons_get_entries(struct xsk_queue *q)