-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correctly scope lock use in xde_detach
#545
Conversation
As part of #485, we need to *inspect* the contents of the shared `XdeState` before taking ownership and dropping its contents. However, I had created a scenario where: - The lock is acquired, based on a reference derived from the dev info ptr (`dip`), - Ownership of the contents of `dip` is taken using `Box::new_raw`, - These contents (`XdeState`) are freed, - The `MutexGuard` pointing into the `XdeState` is dropped, and attempts to unlock a freed mutex. This PR scopes the `&XdeState` and the derived `MutexGuard` in an inner block, correcting this drop order issue by forcing the free to happen at the end of a lexica scope. Fixes #543.
I've tested that this works via: pfexec bash -c "echo set kmem_flags = 0xf > /etc/system.d/kmem_debug"
pfexec reboot
#...
pfexec add_drv xde
pfexec modunload -i 0 For some more confirmation, we can compare the relevant MIR output with
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing that Kyle (and Andy for catching it)!
I realized we would've caught this sooner if KMutexGuard
actually had a Drop
impl that called mutex_destroy
–which is a thing we should be doing anyways:
mutex_destroy() releases any resources that might have been allocated by mutex_init(). mutex_destroy() must be called before freeing the memory containing the mutex, and should be called with the mutex unheld (not owned by any thread). The caller must be sure that no other thread attempts to use the mutex.
That would've marked the mutex as destroyed and caused mutex_exit
from the guard's drop to panic like in #543, just without relying on a debug kernel filling free'd memory with deadbeef
.
The fix should work as-is but mind adding the Drop
impls for KMutex
and KRwLock
(which is similarly missing rw_destroy
).
Required a little creativity to satisfy borrowck around `KMutex::into_inner`, but we got there.
I've taken some laps spinning up and down omicron, and I'm not seeing any lingering issues unearthed by the |
This PR includes one soundness fix over the current OPTE version, as well as dependency updates. * Correctly scope lock use in xde_detach (oxidecomputer/opte#545) * Lock file maintenance (oxidecomputer/opte#544) * Lock file maintenance (oxidecomputer/opte#541)
This PR includes one soundness fix over the current OPTE version, as well as dependency updates. * Correctly scope lock use in xde_detach (oxidecomputer/opte#545) * Lock file maintenance (oxidecomputer/opte#544) * Lock file maintenance (oxidecomputer/opte#541)
As part of #485, we need to inspect the contents of the shared
XdeState
before taking ownership and dropping its contents. However, I had created a scenario where:dip
),dip
is taken usingBox::new_raw
,XdeState
) are freed,MutexGuard
pointing into theXdeState
is dropped, and attempts to unlock a freed mutex.This PR scopes the
&XdeState
and the derivedMutexGuard
in an inner block, correcting this drop order issue by forcing the free to happen at the end of a lexical scope.Fixes #543.