You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, thank you for your contribution in this project, I am scanning the unsoundness problem in rust project.
I notice the following code:
pub fn free_mutex(mutex: *mut KMutex) {
let index = unsafe { mutex.offset_from(&rust_mutex_pool[0] as *const _) } as usize;
let byte = index / 8;
let bit = index % 8;
USED[byte].fetch_and(!(1 << bit), Ordering::Relaxed);
}
Considering that pub mod mutex_alloc, and free_mutex is also a pub function. I assume that users can directly call this function. This potential situation could result in unsafe { mutex.offset_from(&rust_mutex_pool[0] as *const _) } being operating on a null pointer, I guess it might trigger undefined behavior (UB). For safety reasons, I felt it necessary to report this issue. If you have performed checks elsewhere that ensure this is safe, please don’t take offense at my raising this issue.
I suggest Several possible fixes:
If there is no external usage for free_mutex, it should not marked as pub.
free_mutex method should add additional check for null pointer.
mark free_mutex method as unsafe and proper doc to let users know that they should provide valid Pointers.
The text was updated successfully, but these errors were encountered:
Hello, thank you for your contribution in this project, I am scanning the unsoundness problem in rust project.
I notice the following code:
Considering that
pub mod mutex_alloc
, andfree_mutex
is also a pub function. I assume that users can directly call this function. This potential situation could result inunsafe { mutex.offset_from(&rust_mutex_pool[0] as *const _) }
being operating on a null pointer, I guess it might trigger undefined behavior (UB). For safety reasons, I felt it necessary to report this issue. If you have performed checks elsewhere that ensure this is safe, please don’t take offense at my raising this issue.I suggest Several possible fixes:
free_mutex
, it should not marked aspub
.free_mutex
method should add additional check for null pointer.free_mutex
method as unsafe and proper doc to let users know that they should provide valid Pointers.The text was updated successfully, but these errors were encountered: