Repository navigation
Description
Description
Summary
gVisor's SysV semaphore implementation incorrectly handles sem_op = -32768 (INT16_MIN) because it performs negation using signed 16-bit arithmetic.
In pkg/sentry/kernel/semaphore/semaphore.go, the executeOps function evaluates -op.SemOp without widening the operand first. Negating INT16_MIN overflows the int16 range, leaving the result negative.
Consequently, a decrement that should block or return EAGAIN instead succeeds and can commit a negative semaphore value, violating the valid Linux semaphore-value range.
The behavior has been reproduced using the same statically linked C binary on native Linux, runc, and gVisor runsc.
Expected vs. actual behavior
With an initialized semaphore value of zero and sem_op = -32768 using IPC_NOWAIT:
The negative value also disrupts subsequent legitimate semaphore operations. The attached secondary PoC demonstrates blocked or rejected operations and recovery using 32,768 increment operations.
Root cause
File: pkg/sentry/kernel/semaphore/semaphore.go
Function: (*Set).executeOps
The problematic logic is:
if -op.SemOp > valueMax { return nil, 0, linuxerr.ERANGE }
if -op.SemOp > tmpVals[op.SemNum] {
// Wait or return EAGAIN.
}
For op.SemOp = -32768, both comparisons operate on the incorrectly negated signed 16-bit value.
Execution then reaches:
tmpVals[op.SemNum] += op.SemOpThis permits a negative value to be committed to the semaphore set.
Impact
Violates the Linux semaphore-value invariant of
0 <= semval <= SEMVMX.Produces an observable compatibility difference through
semctl(GETVAL/GETALL).Can disrupt semaphore-based synchronization and resource accounting inside the same sandbox.
May require explicit state repair before ordinary semaphore operations can proceed.
No host compromise, sandbox escape, or cross-sandbox impact is claimed.
Suggested fix
Widen the operand before negation, for example
need := -int32(op.SemOp).Ensure an unsatisfiable negative operation returns
EAGAINwithIPC_NOWAIT, matching Linux behavior.Review the existing
ERANGEcondition to avoid introducing a Linux-incompatible error response.Review the
abs(int16)helper used for semaphore waiters, which has the sameINT16_MINarithmetic problem.Add regression tests for both blocking and nonblocking
INT16_MINoperations, including an invariant asserting that semaphore values never become negative.
Environment
Audited commit:
a97b4dd056998f835ee843c8ec2159b6633da2cfgVisor runtime:
release-20260817.0Docker: 28.5.2
Platform: systrap
Host: Kali Linux, kernel 7.1.5
Reference runtime: runc 1.3.6
Previous maintainer communication
This issue was initially disclosed privately to the gVisor security team on September 28, 2026.
On October 13, Etienne Perot confirmed receipt and recommended reporting it through the public GitHub issue tracker because the demonstrated behavior does not meet the project's security-vulnerability criteria.
This issue is being filed publicly in accordance with that recommendation.
gvisor_semop_int16_overflow_report4 (2).zip
Steps to reproduce
Prerequisites
- Linux host with GCC
- Docker with
runcandrunscruntimes configured - Attached
sem_neg_poc.candsem_neg_poc2.c
Step 1 — Compile the PoC
gcc -static -O2 -Wall -o sem_neg_poc sem_neg_poc.cStep 2 — Run on native Linux
./sem_neg_pocExpected observation:
semop(-32768, IPC_NOWAIT): -1, errno=EAGAIN
GETVAL: 0
Step 3 — Run under runc
docker run --rm --runtime=runc \
-v "$PWD:/poc:ro" \
alpine:3.20 /poc/sem_neg_pocExpected: Same behavior as native Linux.
Step 4 — Run under gVisor
docker run --rm --runtime=runsc \
-v "$PWD:/poc:ro" \
alpine:3.20 /poc/sem_neg_pocObserved on runsc release-20260817.0:
semop(-32768, IPC_NOWAIT): 0 (success)
GETVAL: -32768
Step 5 — Verify the synchronization impact
Compile and execute the secondary PoC:
gcc -static -O2 -Wall -o sem_neg_poc2 sem_neg_poc2.c
docker run --rm --runtime=runsc \
-v "$PWD:/poc:ro" \
alpine:3.20 /poc/sem_neg_poc2The second PoC demonstrates disruption of subsequent semaphore operations and the number of increment operations needed to restore the original zero value.
Reproduction result
Native Linux and runc reject the operation and preserve the semaphore value at zero.
gVisor incorrectly accepts the operation and commits the negative value -32768.
The original C PoCs and captured differential execution logs are available as supporting evidence.
runsc version
runsc version release-20260817.0
spec: 1.2.1docker version (if using docker)
Docker Client: 28.5.2+dfsg4
Docker Server: 28.5.2+dfsg4
API version: 1.51
Go version: go1.26.5
OS/Arch: linux/amd64
containerd: 2.1.9+unknown
runc: 1.3.6+ds1
docker-init: 0.19.0uname
Linux kali 7.1.5+kali-amd64 #1 SMP PREEMPT_DYNAMIC Kali 7.1.5-1kali1 (2026-07-29) x86_64 GNU/Linux
kubectl (if using Kubernetes)
Not applicable.
Reproduced using standalone Docker containers with
the runc and runsc OCI runtimes.
Kubernetes was not used.repo state (if built from source)
Not built from source. Tested runtime: runsc release-20260817.0 spec: 1.2.1 Original source audit: google/gvisor Commit: a97b4dd The original local source checkout has since been deleted. The vulnerability was reproduced using the installed runsc runtime and a standalone C proof of concept.
runsc debug logs (if available)
Internal runsc debug logs were not collected during the original investigation.
The issue was reproduced using standalone C proof-of-concept programs and differential testing across:
- Native Linux 7.1.5
- runc 1.3.6
- runsc release-20260817.0
Observed results:
- Linux/runc: semop(-32768, IPC_NOWAIT) returns EAGAIN; GETVAL remains 0.
- runsc: semop(-32768, IPC_NOWAIT) succeeds; GETVAL returns -32768.
The reproduction does not require internal runsc debugging instrumentation.
The original PoC and execution logs are available as supporting evidence.
Activity
Block semop with sem_op -32768 instead of wrapping the semaphore nega…