rust: id_pool: document panics in `find_unused_id` and `release_id`
Subsystems (2)
PATCH v2 1/1 rust: id_pool: document panics in `find_unused_id` and `release_id`
find_unused_id() calls Bitmap::next_zero_bit() and release_id() calls Bitmap::clear_bit(), both of which panic when CONFIG_RUST_BITMAP_HARDENED is enabled and the index is out of bounds. Neither IdPool method documents this.
Add the missing # Panics sections and state the bounds requirement on offset and id.
---
Changes in v2:
- Use "within bounds" instead of "in bounds", following feedback from
Alexandre Courbot.
- Add Fixes:, treating the documentation hole as a bug [1].
- Link to v1: https://lore.kernel.org/rust-for-linux/[email protected]/
--- rust/kernel/id_pool.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
rust/kernel/id_pool.rs +14 -1
@@ -224,7 +224,13 @@ pub fn grow(&mut self, mut resizer: PoolResizer) {/// Finds an unused ID in the bitmap. /// /// Upon success, returns its index. Otherwise, returns [`None`] -/// to indicate that a [`Self::grow_request`] is needed. +/// to indicate that a [`Self::grow_request`] is needed. `offset` must be +/// within bounds. +/// +/// # Panics +/// +/// Panics if `CONFIG_RUST_BITMAP_HARDENED` is enabled and `offset` is out +/// of bounds. #[inline] #[must_use] pub fn find_unused_id (&mut self, offset:usize ) ->Option <UnusedId <'_>> {
@@ -236,6 +242,13 @@ pub fn find_unused_id(&mut self, offset: usize) -> Option<UnusedId<'_>> { }/// Releases an ID. +/// +/// The `id` must be within bounds. +/// +/// # Panics +/// +/// Panics if `CONFIG_RUST_BITMAP_HARDENED` is enabled and `id` is out of +/// bounds. #[inline] pub fn release_id (&mut self, id:usize ) { self.map.clear_bit (id);
base-commit: 73e3f0710014fe6d4ed98cfc02292f6121db7558 --
2.47.3
Quoted 58 lines · Georgios Androutsopoulos
find_unused_id()callsBitmap::next_zero_bit()andrelease_id()callsBitmap::clear_bit(), both of which panic whenCONFIG_RUST_BITMAP_HARDENEDis enabled and the index is out of bounds. NeitherIdPoolmethod documents this.Add the missing
# Panicssections and state the bounds requirement onoffsetandid.Fixes 2cdae413cd3e ("rust: add dynamic ID pool abstraction for bitmap")Reviewed-by Alexandre Courbot <[email protected]>Signed-off-by Georgios Androutsopoulos <[email protected]>---
Changes in v2:
- Use "within bounds" instead of "in bounds", following feedback from
Alexandre Courbot.
- Add Fixes:, treating the documentation hole as a bug [1].
- Link to v1: https://lore.kernel.org/rust-for-linux/[email protected]/--- rust/kernel/id_pool.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)rust/kernel/id_pool.rs +14
-1@@ -224,7 +224,13 @@ pub fn grow(&mut self, mut resizer: PoolResizer) {/// Finds an unused ID in the bitmap. /// /// Upon success, returns its index. Otherwise, returns [`None`] -/// to indicate that a [`Self::grow_request`] is needed. +/// to indicate that a [`Self::grow_request`] is needed. `offset` must be +/// within bounds. +/// +/// # Panics +/// +/// Panics if `CONFIG_RUST_BITMAP_HARDENED` is enabled and `offset` is out +/// of bounds. #[inline] #[must_use] pub fn find_unused_id (&mut self, offset:usize ) ->Option <UnusedId <'_>> {@@ -236,6 +242,13 @@ pub fn find_unused_id(&mut self, offset: usize) -> Option<UnusedId<'_>> { }/// Releases an ID. +/// +/// The `id` must be within bounds. +/// +/// # Panics +/// +/// Panics if `CONFIG_RUST_BITMAP_HARDENED` is enabled and `id` is out of +/// bounds. #[inline] pub fn release_id (&mut self, id:usize ) { self.map.clear_bit (id);
Quoted 4 lines
base-commit:
73e3f0710014fe6d4ed98cfc02292f6121db7558--
2.47.3
Hi,
Just checking if there are any remaining concerns with this patch, or if it can be picked up.
Thanks,
Georgios
Yury Norov
AppliedQuoted 11 lines · Georgios Androutsopoulos
find_unused_id()callsBitmap::next_zero_bit()andrelease_id()callsBitmap::clear_bit(), both of which panic whenCONFIG_RUST_BITMAP_HARDENEDis enabled and the index is out of bounds. NeitherIdPoolmethod documents this.Add the missing
# Panicssections and state the bounds requirement onoffsetandid.Fixes 2cdae413cd3e ("rust: add dynamic ID pool abstraction for bitmap")Reviewed-by Alexandre Courbot <[email protected]>Signed-off-by Georgios Androutsopoulos <[email protected]>
Applied both in bitmap-for-next. Thanks!
Quoted 49 lines
---
Changes in v2:
- Use "within bounds" instead of "in bounds", following feedback from
Alexandre Courbot.
- Add Fixes:, treating the documentation hole as a bug [1].
- Link to v1: https://lore.kernel.org/rust-for-linux/[email protected]/--- rust/kernel/id_pool.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)rust/kernel/id_pool.rs +14
-1@@ -224,7 +224,13 @@ pub fn grow(&mut self, mut resizer: PoolResizer) {/// Finds an unused ID in the bitmap. /// /// Upon success, returns its index. Otherwise, returns [`None`] -/// to indicate that a [`Self::grow_request`] is needed. +/// to indicate that a [`Self::grow_request`] is needed. `offset` must be +/// within bounds. +/// +/// # Panics +/// +/// Panics if `CONFIG_RUST_BITMAP_HARDENED` is enabled and `offset` is out +/// of bounds. #[inline] #[must_use] pub fn find_unused_id (&mut self, offset:usize ) ->Option <UnusedId <'_>> {@@ -236,6 +242,13 @@ pub fn find_unused_id(&mut self, offset: usize) -> Option<UnusedId<'_>> { }/// Releases an ID. +/// +/// The `id` must be within bounds. +/// +/// # Panics +/// +/// Panics if `CONFIG_RUST_BITMAP_HARDENED` is enabled and `id` is out of +/// bounds. #[inline] pub fn release_id (&mut self, id:usize ) { self.map.clear_bit (id);base-commit:
73e3f0710014fe6d4ed98cfc02292f6121db7558--
2.47.3