Repository navigation
control: keep the registry working under kernel.shm_rmid_forced=1 - #355
Conversation
|
Thanks for the PR! |
30b2dd6 to
5216ca5
Compare
|
Thanks for dropping the first commit. One thing to fix before merge:
Please pick a constant whose XOR with the lock constant has a high bit set (bit 30, say), so no realistic uid pair collides. |
With shm_rmid_forced=1 the kernel destroys a SysV segment as soon as its last attachment drops, while semaphores live on. The registry attached and detached its directory and segments per operation, so they vanished in the middle of a claim (EINVAL), and the signed semaphores left behind made every later run look for a directory that no longer existed (ENOENT). - Each live claim keeps the directory and its own segment attached, and a transaction keeps every segment it opens attached until it ends. - A missing directory means no claim is alive; it is created again. - The salt that keys every segment is also kept in a small semaphore set, so a recreated directory finds the existing semaphore arrays instead of orphaning an 8196-semaphore array on every idle-to-busy cycle. - A segment destroyed with its last claimant takes the chain links in its records with it. A walk that reaches one relinks every bucket from the surviving records under the lock; an interrupted relink is redone. - A segment destroyed between shmget and shmat, by a detach outside the lock or at a claimant's exit, is looked up again. It is validated only once attached, when it can no longer disappear. Fixes multikernel#353 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5216ca5 to
fbf3435
Compare
Fixes #353
Problem
With kernel.shm_rmid_forced=1, the kernel destroys a SysV shared-memory segment as soon as its last attachment drops, but semaphores persist. The control registry attached and detached its directory and segments for each operation, so they disappeared in the middle of a claim. The first sandlock run failed with EINVAL. After that, the signed semaphores pointed at a directory that no longer existed, so every later run failed with ENOENT until someone ran ipcrm. No sandbox could start on such a host.
Changes
control: keep the registry alive under kernel.shm_rmid_forced=1
Without this, every idle→busy cycle would orphan an 8196-semaphore array and eventually exhaust SEMMNI.
With the default shm_rmid_forced=0, the only differences are one extra 9-semaphore set per user and two extra attachments per sandbox. The rebuild path never runs.
Testing
All runs below used kernel.shm_rmid_forced=1.
Compatibility note
If a binary from before this change finds a rebuild that was interrupted midway, it reports the registry as invalid until a new binary completes a transaction. This needs a crash during a rebuild, which only happens under shm_rmid_forced=1, where binaries from before this change could not run anyway.