Skip to content

liburing: avoid signed overflow in buffer ring indexing - #1629

Open
SantanDon wants to merge 1 commit into
axboe:masterfrom
SantanDon:security/buf-ring-unsigned-offset
Open

liburing: avoid signed overflow in buffer ring indexing#1629
SantanDon wants to merge 1 commit into
axboe:masterfrom
SantanDon:security/buf-ring-unsigned-offset

Conversation

@SantanDon

Copy link
Copy Markdown

Summary

Avoid signed integer overflow in the public io_uring_buf_ring_add() helper when a high 16-bit ring tail is combined with a large positive buf_offset.

Why

The helper computes the buffer slot with:

(br->tail + buf_offset) & mask

br->tail is 16-bit and is promoted to signed int for the addition. With br->tail = UINT16_MAX and buf_offset = INT_MAX, UBSan reports signed integer overflow before the ring mask is applied.

The slot calculation is inherently modulo the ring size. Converting buf_offset to unsigned before the addition makes wraparound defined while preserving normal offsets and the existing masked index behavior.

Verification

A focused UBSan harness using the current expression reports:

runtime error: signed integer overflow: 65535 + 2147483647 cannot be represented in type int

With the proposed expression, UBSan is clean for offsets 0, 1, 2, 3 and the boundary case UINT16_MAX + INT_MAX; ordinary masked indices are unchanged. git diff --check is clean.

This is submitted as undefined-behavior hardening; I am not claiming an out-of-ring write or kernel exploit.

io_uring_buf_ring_add() adds the 16-bit ring tail to the signed
buf_offset before applying the ring mask. With a high tail and a large
positive offset, that addition can overflow signed int and invoke
undefined behavior.

The index is inherently modulo the ring size. Convert buf_offset to
unsigned before the addition so the wrap is defined while preserving
existing behavior for normal offsets.

Fixes: c41c485 ("Change io_uring_buf_ring_add() to take ring and buffer offset")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant