objcache: Check Seatbelt permissions before opening LMDB on Apple #63636
Ugh, Fable tells me an XNU kernel bug makes this leak the semaphore set every time the check fails, and I think it's right.
🫠
I'm not sure this check even fixes the problem we encountered in the sandbox, because Seatbelt's (deny ipc-sysv-sem) doesn't make semaphore set creation with semget fail at all! Unclear if that is a bug
There is apparently some private sandbox_check function that you can just query if it has the required support so I changed to that... I don't know if this is worth doing or if we should just merge https://github.com/JuliaCI/sandboxed-buildkite-agent/pull/176 and forget about it..
We shouldn't use an undocumented internal function IMO. Best to have upstream LMDB change things so we don't leave the database in a bad state if SysV IPC is blocked. Thanks for looking in to this
LGTM. Seems likely not the first time we've used internal APIs, especially due to working around platform bugs on Apple.
xal-0
KristofferC
On Apple platforms, LMDB uses SysV semaphores for its locks. Seatbelt can allow a new semaphore set to be created while denying initialization (
semctl(SETALL)), locking, and removal. LMDB then fails before initializing its lock region, and concurrent openers can encounterMDB_INVALID: File is not an LMDB file.Check the
ipc-sysv-sempermission withsandbox_checkbefore opening LMDB, and disable the cache with a notice when the sandbox explicitly denies access. This avoids allocating a probe semaphore that the sandbox would prevent us from removing. The private libSystem API is weakly imported and the check is best-effort: if the API is unavailable or the query fails, LMDB attempts to open the cache normally. Removing the API therefore does not disable caching for ordinary Mac users.The companion change, JuliaCI/sandboxed-buildkite-agent#176, allows
ipc-sysv-semso the cache can operate in macOS CI. Its permission rule was validated locally; the full CI profile has not been tested here.Fixes #62800
Implemented with assistance from Codex (GPT-6).