Skip to content

fix(ublk): prevent buffer slice UB by returning Option#83

Merged
jaredLunde merged 2 commits into
mainfrom
capy/fix-ublk-buffer-bounds
Jun 25, 2026
Merged

fix(ublk): prevent buffer slice UB by returning Option#83
jaredLunde merged 2 commits into
mainfrom
capy/fix-ublk-buffer-bounds

Conversation

@jaredLunde

Copy link
Copy Markdown
Contributor

This PR fixes a potential undefined behavior in the ublk buffer pool where PoolSlot::as_mut_slice used debug_assert! before std::slice::from_raw_parts_mut. In release builds, a malformed kernel length exceeding SLOT_SIZE would create an out-of-bounds mutable slice.

Changes:

  • Modify PoolSlot::as_mut_slice to return Option<&mut [u8]>, returning None for oversized requests
  • Modify IoBuf::as_mut_slice to return Option<&mut [u8]>, using safe get_mut for heap variant
  • Add early guard in acquire_io_buf to reject oversized lengths
  • Update call site in glidefs/src/block/ublk/device.rs to handle None by logging and returning -EIO
  • Add regression tests: pool_slot_rejects_oversized_slice and acquire_io_buf_rejects_oversized_len

The caller already has an error path for buffer allocation failures; this change routes oversized requests through the same degrade-safe path instead of risking UB.

Open GLID-001 GLID-001

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@jaredLunde jaredLunde added the capy Generated by capy.ai label Jun 25, 2026 — with Capy AI
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@jaredLunde jaredLunde merged commit 755088a into main Jun 25, 2026
25 checks passed
@jaredLunde jaredLunde deleted the capy/fix-ublk-buffer-bounds branch June 25, 2026 04:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

capy Generated by capy.ai

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant