Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Calling `find_unused_id(0)` or `reserve_ids(0, ...)` on an `IdPool` initialized with a capacity of 0 triggers a kernel panic when `CONFIG_RUST_BITMAP_HARDENED` is enabled. --
commit c0cd93bbf9f36768f04bc377021b9e32ae0dce05 Author: Eliot Courtney <[email protected]> rust: id_pool: do not round capacity up to BitmapVec::MAX_INLINE_LEN This commit modifies IdPool::with_capacity to stop rounding the capacity up to BitmapVec::MAX_INLINE_LEN. This allows explicitly creating pools with 0 capacity, and adjusts grow_request and shrink_request to handle the new floor. > diff --git a/rust/kernel/id_pool.rs b/rust/kernel/id_pool.rs > index 06a4c71c4c6c9..4f329249df9d0 100644 > --- a/rust/kernel/id_pool.rs > +++ b/rust/kernel/id_pool.rs > @@ -112,13 +112,8 @@ pub fn new() -> Self { > } > > /// Constructs a new [`IdPool`] with space for a specific number of bits. > - /// > - /// A capacity below [`MAX_INLINE_LEN`] is adjusted to > [`MAX_INLINE_LEN`]. > - /// > - /// [`MAX_INLINE_LEN`]: BitmapVec::MAX_INLINE_LEN > #[inline] > pub fn with_capacity(num_ids: usize, flags: Flags) -> Result<Self, > AllocError> { > - let num_ids = usize::max(num_ids, BitmapVec::MAX_INLINE_LEN); > let map = BitmapVec::new(num_ids, flags)?; > Ok(Self { map }) > } [Severity: High] Does allowing a capacity of 0 here introduce a kernel panic during standard allocations if CONFIG_RUST_BITMAP_HARDENED is enabled? If a caller attempts to allocate an ID on a 0-capacity pool using patterns like pool.find_unused_id(0) or pool.reserve_ids(0, ...), the call delegates directly to the underlying bitmap without its own bounds check: IdPool::find_unused_id() { Some(UnusedId { id: self.map.next_zero_bit(offset)?, pool: self, }) } This passes offset=0 to Bitmap::next_zero_bit(), which contains an assertion that start < self.len(). Since 0 < 0 is false on a 0-capacity pool, it panics immediately instead of gracefully returning None to prompt a grow_request(). [ ... ] -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=11
