mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 20:07:34 +00:00
Kernel: Fix race in clock_nanosleep
This is a complete fix of clock_nanosleep, because the thread holds the process lock again when returning from sleep()/sleep_until(). Therefore, no further concurrent invalidation can occur.
This commit is contained in:
parent
28e1da344d
commit
4dd4dd2f3c
1 changed files with 7 additions and 0 deletions
|
@ -4290,6 +4290,13 @@ int Process::sys$clock_nanosleep(const Syscall::SC_clock_nanosleep_params* user_
|
||||||
if (wakeup_time > g_uptime) {
|
if (wakeup_time > g_uptime) {
|
||||||
u32 ticks_left = wakeup_time - g_uptime;
|
u32 ticks_left = wakeup_time - g_uptime;
|
||||||
if (!is_absolute && params.remaining_sleep) {
|
if (!is_absolute && params.remaining_sleep) {
|
||||||
|
if (!validate_write_typed(params.remaining_sleep)) {
|
||||||
|
// This can happen because the lock is dropped while
|
||||||
|
// sleeping, thus giving other threads the opportunity
|
||||||
|
// to make the region unwritable.
|
||||||
|
return -EFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
timespec remaining_sleep;
|
timespec remaining_sleep;
|
||||||
memset(&remaining_sleep, 0, sizeof(timespec));
|
memset(&remaining_sleep, 0, sizeof(timespec));
|
||||||
remaining_sleep.tv_sec = ticks_left / TICKS_PER_SECOND;
|
remaining_sleep.tv_sec = ticks_left / TICKS_PER_SECOND;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue