mirror of
https://github.com/rdmsr/zag.git
synced 2026-10-31 23:38:21 +00:00
ke/mutex: fix possible use-after-free
A thread might get reaped between loading the owner and its state, leading to a possible use-after-free.
This commit is contained in:
+8
-14
@@ -29,21 +29,15 @@ pub const Mutex = struct {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fast path: if the owner is running, try to acquire without a turnstile by spinning a bit.
|
// Fast path: Try to acquire without a turnstile by spinning a bit.
|
||||||
if (cur_owner.?.?.state.load(.monotonic) == .Running) {
|
for (0..optimistic_spins) |_| {
|
||||||
for (0..optimistic_spins) |_| {
|
if (m.owner.cmpxchgWeak(null, curtd, .acquire, .monotonic) != null) {
|
||||||
if (m.owner.cmpxchgStrong(null, curtd, .acquire, .monotonic)) |maybe_owner| {
|
std.atomic.spinLoopHint();
|
||||||
const owner = maybe_owner.?;
|
continue;
|
||||||
if (owner.state.load(.monotonic) != .Running) break;
|
|
||||||
|
|
||||||
std.atomic.spinLoopHint();
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
ke.ipl.lower(ipl);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ke.ipl.lower(ipl);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Slow path: contended, block on a turnstile.
|
// Slow path: contended, block on a turnstile.
|
||||||
|
|||||||
Reference in New Issue
Block a user