Skip to content

Conversation

@wdcui
Copy link
Member

@wdcui wdcui commented Feb 2, 2026

Summary

Implement 8 syscalls for managing user and group IDs:

  • setuid, setgid: Set all three IDs (real, effective, saved)
  • setreuid, setregid: Set real and effective IDs
  • setresuid, setresgid: Set real, effective, and saved IDs independently
  • getresuid, getresgid: Get all three IDs

Motivation

These syscalls are commonly used by applications that need to drop privileges for security. For example, a server might start as root and then drop to a non-privileged user.

Changes

Credentials Struct

  • Extended Credentials struct with suid (saved-set-user-ID) and sgid (saved-set-group-ID) fields
  • Changed storage from Arc<Credentials> to RefCell<Credentials> to allow mutation

Syscall Implementation

  • Added SyscallRequest variants and parsing for all 8 syscalls
  • Implemented handlers with -1 (no-change) semantics per POSIX
  • All syscalls always succeed (no permission checks) since litebox is a sandboxed single-process environment

Testing

  • Added 6 unit tests covering all syscalls
  • Tests verify -1 no-op behavior, partial updates, and correct state tracking

Files Modified

  • litebox_common_linux/src/lib.rs - Added SyscallRequest variants and parsing
  • litebox_shim_linux/src/lib.rs - Changed credentials to RefCell, added dispatch
  • litebox_shim_linux/src/syscalls/process.rs - Updated Credentials struct, added handlers
  • litebox_shim_linux/src/loader/auxv.rs - Fixed credentials access

Testing Done

  • All 6 new unit tests pass
  • Full test suite: 161/176 tests pass (same 15 pre-existing failures as main branch, all TUN/Node.js related)

wdcui added 2 commits February 2, 2026 03:49
Implement 8 syscalls for managing user and group IDs:
- setuid, setgid: Set all three IDs (real, effective, saved)
- setreuid, setregid: Set real and effective IDs
- setresuid, setresgid: Set real, effective, and saved IDs independently
- getresuid, getresgid: Get all three IDs

Changes:
- Extended Credentials struct with suid (saved-set-user-ID) and sgid
  (saved-set-group-ID) fields
- Changed credentials storage from Arc<Credentials> to RefCell<Credentials>
  to allow mutation via setuid/setgid syscalls
- Added SyscallRequest variants and parsing for all 8 syscalls
- Implemented handlers with -1 (no-change) semantics per POSIX
- Added 6 unit tests covering all syscalls

All syscalls always succeed (no permission checks) since litebox is a
sandboxed single-process environment where applications may need to
drop privileges.
Per POSIX, the saved set-user-ID should be updated when the new
effective UID differs from the OLD REAL UID, not the old effective UID.

The previous implementation incorrectly compared against old_euid
instead of old_uid. This fix also adds test cases for the edge case
where euid is set to the current ruid value (suid should NOT update).

Same fix applied to setregid for saved set-group-ID.
@github-actions
Copy link

github-actions bot commented Feb 2, 2026

🤖 SemverChecks 🤖 ⚠️ Potential breaking API changes detected ⚠️

Click for details
--- failure enum_no_repr_variant_discriminant_changed: enum variant had its discriminant change value ---

Description:
The enum's variant had its discriminant value change. This breaks downstream code that used its value via a numeric cast like `as isize`.
        ref: https://doc.rust-lang.org/reference/items/enumerations.html#assigning-discriminant-values
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.46.0/src/lints/enum_no_repr_variant_discriminant_changed.ron

Failed in:
  variant SyscallRequest::Sysinfo 82 -> 90 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2266
  variant SyscallRequest::CapGet 83 -> 91 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2269
  variant SyscallRequest::GetDirent64 84 -> 92 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2273
  variant SyscallRequest::SchedGetAffinity 85 -> 93 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2278
  variant SyscallRequest::SchedYield 86 -> 94 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2283
  variant SyscallRequest::Futex 87 -> 95 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2284
  variant SyscallRequest::Execve 88 -> 96 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2287
  variant SyscallRequest::Umask 89 -> 97 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2292
  variant SyscallRequest::Prctl 90 -> 98 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2295
  variant SyscallRequest::Alarm 91 -> 99 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2298
  variant SyscallRequest::SetITimer 92 -> 100 in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2301

@wdcui wdcui closed this Feb 2, 2026
@wdcui wdcui deleted the wdcui/setuid-setgid-family branch February 2, 2026 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants