Skip to content

semaphore: semop(-32768) incorrectly succeeds and produces negative semaphore values #15729

Description

@elnadym165

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:

Environment | semop result | GETVAL -- | -- | -- Native Linux 7.1.5 | -1, EAGAIN | 0 runc 1.3.6 | -1, EAGAIN | 0 runsc release-20260817.0 | 0 (success) | -32768

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.SemOp

This 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

  1. Widen the operand before negation, for example need := -int32(op.SemOp).

  2. Ensure an unsatisfiable negative operation returns EAGAIN with IPC_NOWAIT, matching Linux behavior.

  3. Review the existing ERANGE condition to avoid introducing a Linux-incompatible error response.

  4. Review the abs(int16) helper used for semaphore waiters, which has the same INT16_MIN arithmetic problem.

  5. Add regression tests for both blocking and nonblocking INT16_MIN operations, including an invariant asserting that semaphore values never become negative.

Environment

  • Audited commit: a97b4dd056998f835ee843c8ec2159b6633da2cf

  • gVisor runtime: release-20260817.0

  • Docker: 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 runc and runsc runtimes configured
  • Attached sem_neg_poc.c and sem_neg_poc2.c

Step 1 — Compile the PoC

gcc -static -O2 -Wall -o sem_neg_poc sem_neg_poc.c

Step 2 — Run on native Linux

./sem_neg_poc

Expected 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_poc

Expected: 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_poc

Observed 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_poc2

The 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.1

docker 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.0

uname

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

  1. added
    type: bug
    on Oct 13, 2026
  2. added a commit that references this issue on Nov 4, 2026
    0fe4adf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions