fix(ublk): prevent buffer slice UB by returning Option#83
Merged
Conversation
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a potential undefined behavior in the ublk buffer pool where
PoolSlot::as_mut_sliceuseddebug_assert!beforestd::slice::from_raw_parts_mut. In release builds, a malformed kernel length exceedingSLOT_SIZEwould create an out-of-bounds mutable slice.Changes:
PoolSlot::as_mut_sliceto returnOption<&mut [u8]>, returningNonefor oversized requestsIoBuf::as_mut_sliceto returnOption<&mut [u8]>, using safeget_mutfor heap variantacquire_io_bufto reject oversized lengthsglidefs/src/block/ublk/device.rsto handleNoneby logging and returning-EIOpool_slot_rejects_oversized_sliceandacquire_io_buf_rejects_oversized_lenThe 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.