Skip to content

Commit

Permalink
Kernel: Fix race in waitid
Browse files Browse the repository at this point in the history
This is similar to 28e1da3
and 4dd4dd2.

The crux is that wait verifies that the outvalue (siginfo* infop)
is writable *before* waiting, and writes to it *after* waiting.
In the meantime, a concurrent thread can make the output region
unwritable, e.g. by deallocating it.
  • Loading branch information
BenWiederhake authored and awesomekling committed Mar 8, 2020
1 parent d8cd4e4 commit b066586
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Kernel/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2427,6 +2427,12 @@ pid_t Process::sys$waitid(const Syscall::SC_waitid_params* user_params)
auto siginfo_or_error = do_waitid(static_cast<idtype_t>(params.idtype), params.id, params.options);
if (siginfo_or_error.is_error())
return siginfo_or_error.error();
// While we waited, the process lock was dropped. This gave other threads
// the opportunity to mess with the memory. For example, it could free the
// region, and map it to a region to which it has no write permissions.
// Therefore, we need to re-validate the pointer.
if (!validate_write_typed(params.infop))
return -EFAULT;

copy_to_user(params.infop, &siginfo_or_error.value());
return 0;
Expand Down

0 comments on commit b066586

Please sign in to comment.