CVSROOT:        /cvs
Module name:    src
Changes by:     [email protected]  2026/09/20 22:26:47

Modified files:
        sys/kern       : sysv_sem.c 

Log message:
Avoid sleeping while recording SEM_UNDO information

sys_semop(), by way of semundo_adjust() and semu_alloc(), could sleep in
pool_get(PR_WAITOK) after it had already applied the semaphore operations.
Another process can remove the set with IPC_RMID while we sleep; we then write
sempid and sem_otime through the freed semid_ds_kern and sem_base, and record
an undo entry for a set semundo_clear() has already swept, which panics
semexit() when the process exits.

This was introduced as a fallback in rev 1.14, after moving the
structures from a static array to a pool made the allocation able to
fail at all.  semop(2) documents ENOSPC, so drop the fallback with the
extra complexity to work around the sleep.

semundo_adjust() must then stop freeing an emptied structure in the middle of
an operation: sys_semop()'s rollback can need it again, and re-creating it
there is allowed to fail, which is a panic.  Keep it until done2.  That also
takes a second sleeping pool_put() out of the done: region.

Give the two places that release an undo structure one semu_free() to
share. Use a dead list in semundo_clear to deal with all sleep-capable
pool_puts in a single pass when this memory is no longer visible.

Reported by Acts1631 who also reviewed the patch

bluhm@ "please commit to current"

Reply via email to