Repository navigation
Enforce ownership check on shmctl(IPC_RMID) - #16263
Merged
Merged
Conversation
Any uid could destroy any SysV shared memory segment via shmctl(IPC_RMID) because Shmctl bypassed the ownership check that Registry.Remove enforces for semaphore and msgqueue. Only the creator or owner or a task with CAP_SYS_ADMIN in the owning user namespace should be allowed to mark a segment for destruction, matching Linux ipcctl_obtain_check and object CheckOwnership. Enforce CheckOwnership inside Shm.MarkDestroyed under s.mu.Lock() in the same critical section that transitions pendingDestruction to true, returning linuxerr.EPERM if unauthorized. This ensures atomic authorization and state transition without lock bouncing, and prevents TOCTOU against concurrent shmctl(IPC_SET). Key dissociation occurs outside s.mu to preserve the registry-to-shm lock hierarchy. Add a syscall regression test RmidOwnershipPermissionDenied in test/syscalls/linux/shm.cc covering permission denial on non-owners, SHM_DEST survival check, and successful destruction following ownership transfer via IPC_SET. Fixes #14191
copybara-service
Bot
force-pushed
the
test/cl1005154563
branch
from
October 23, 2026 18:41
b4a9030 to
f5018ba
Compare
PiperOrigin-RevId: 1005787710
copybara-service
Bot
force-pushed
the
test/cl1005154563
branch
from
October 23, 2026 19:42
f5018ba to
9f4c048
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enforce ownership check on shmctl(IPC_RMID)
Fixes #14191
What was wrong
Any uid could destroy any SysV shared memory segment via
shmctl(IPC_RMID).Shmctlinpkg/sentry/syscalls/linux/sys_shm.godirectly invokedsegment.MarkDestroyed(t)without checking that the caller is the creator, the current owner, or holdsCAP_SYS_ADMINin the owning user namespace. In Linux (ipc/shm.c:shmctl_down),IPC_RMIDandIPC_SETboth requireipcctl_obtain_check. In gVisor,IPC_SETalready enforces this vias.obj.Set, and other SysV mechanisms (semaphore,msgqueue) enforce it viaRegistry.Remove, butshmctl(IPC_RMID)was unauthenticated.What changed
Authorization in
Shm.MarkDestroyed(pkg/sentry/kernel/shm/shm.go):Shm.MarkDestroyed(ctx context.Context) errornow extracts credentials viaauth.CredentialsFromContext(ctx)and executess.obj.CheckOwnership(creds)unders.mu.Lock()within the same critical section that setspendingDestruction = true.linuxerr.EPERMif unauthorized.shmctl(IPC_SET)calls while keeping the ownership policy centralized in theshmpackage.s.registry.dissociateKey(s)ands.DecRef(ctx)outsides.muto preserve theRegistry.mu -> Shm.mulock hierarchy.Syscall Handler (
pkg/sentry/syscalls/linux/sys_shm.go):Shmctl,linux.IPC_RMIDdirectly delegates toreturn 0, nil, segment.MarkDestroyed(t).Syscall Regression Test (
test/syscalls/linux/shm.cc):ShmTest.RmidOwnershipPermissionDenied.CAP_SYS_ADMINdropped, scratch UID/GID) receivesEPERMwhen callingshmctl(IPC_RMID).SHM_DESTis not set onIPC_STAT.IPC_SET,shmctl(IPC_RMID)succeeds.Verification
make test TARGETS="//test/syscalls:shm_test_runsc_ptrace": PASSmake test TARGETS="//test/syscalls:shm_test_native": PASSAuto-fixed-by: [🤖] @EtiennePerot
FUTURE_COPYBARA_INTEGRATE_REVIEW=Enforce ownership check on shmctl(IPC_RMID) #14401 from adi-IL:fix/shm-ipcrmid-own-check e679272