HomeFreeBSD

jail: prevent a race between jail_attach in different threads

Description

jail: prevent a race between jail_attach in different threads

Attaching to a jail changes its root directory and its process
credentials. These operations both require unlocking the jail, and also
need allprison_lock unlocked. That means that if two threads are trying
to attach to different jails at the same time, it's possible for the
process to end up with one jail's root directory but the other jail's
credentials.

Solve this by forcing the process into single-threaded mode during
system calls that attach to a jail (jail_attach, jail_attach_jd, and
sometimes jail_set).

Reviewed by: kib, markj
Differential Revision: https://reviews.freebsd.org/D57858

(cherry picked from commit d4e0f4dab2d7f4de46bb79db1ca7e6e8a2e34746)

Details

Provenance
jamieAuthored on Jul 2 2026, 10:48 PM
Reviewer
kib
Differential Revision
D57858: Prevent a jail_attach race between threads
Parents
rG530ee2980c50: jail: clean up locking around do_jail_attach
Branches
Unknown
Tags
Unknown