kernel - Fix umtx (pthread_mutex etc) race in kernel
authorMatthew Dillon <dillon@apollo.backplane.com>
Wed, 6 Jun 2018 15:29:37 +0000 (08:29 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Wed, 6 Jun 2018 15:36:00 +0000 (08:36 -0700)
commitefbd013239d66d591bfbc71ed58d36141e70b76c
tree8d0563db9b1da0831f754daee991f8bd5ef193e4
parent6481baf48ca2078fc4844f9814bc9aeda81a8f5d
kernel - Fix umtx (pthread_mutex etc) race in kernel

* The umtx code could still race a fork despite the wakeup
  due to certain access paths leading into umtx_sleep() only
  issuing reads, thus not triggering a COW operation post-fork.
  This results in a loss of the interlock.

* Fix the issue by having umtx_sleep() fetch the user data
  with a read-modify-write instead of a read.  It now essentially
  does a lock xadd, adding $0 to the memory to force a write
  fault if necessary.

* Fixes 'go' tests and probably other situations that can arise
  when heavily threaded programs use fork/exec.

Reported-by: Tim Darby (+testing)
lib/libc/sys/umtx.2
sys/kern/kern_umtx.c