Skip to content

Emulate setgroups for fakeroot guests#216

Merged
jserv merged 1 commit into
sysprog21:mainfrom
open-sources-port:SYS_setgroups
Jul 18, 2026
Merged

Emulate setgroups for fakeroot guests#216
jserv merged 1 commit into
sysprog21:mainfrom
open-sources-port:SYS_setgroups

Conversation

@doanbaotrung

@doanbaotrung doanbaotrung commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Wire aarch64 SYS_setgroups through the syscall dispatch table and emulate it in the guest identity layer. Allow root/fakeroot callers to set or clear supplementary groups as a no-op after validating the guest group list, while non-root callers receive EPERM.

Extend credential coverage for root/fakeroot success, non-root denial, bad pointers, zero-count calls, and invalid sizes.

Fix #189


Summary by cubic

Emulates setgroups(2) for aarch64 guests by wiring SYS_setgroups and making root/fakeroot calls a validated no-op. Non-root calls return -EPERM. Fixes #189.

  • New Features
    • Defined SYS_setgroups (159) in abi.h; wired in dispatch.tbl; forwarded sc_setgroups to sys_setgroups.
    • Root or fakeroot: validate group list and return 0 (including size == 0). Others: -EPERM.
    • Errors: size < 0 or > 65536 → -EINVAL; bad pointer → -EFAULT; alloc failure → -ENOMEM.
    • Extended tests/test-credentials.c to cover root/fakeroot success, non-root denial, bad pointer, zero count, and invalid size.

Written for commit b4b693c. Summary will update on new commits.

Review in cubic

@jserv
jserv requested a review from Max042004 July 17, 2026 08:36

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 6 files

Re-trigger cubic

Comment thread src/syscall/sys.c Outdated

int64_t sys_setgroups(guest_t *g, int size, uint64_t list_gva)
{
if (size < 0 || size > LINUX_NGROUPS_MAX)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sys_setgroups() checks argument validity before privilege, which is the reverse of the real kernel's order. Linux's sys_setgroups (kernel/groups.c) checks CAP_SETGID first, then validates gidsetsize.

Confirmed with the default (non-root, GUEST_UID=1000) guest: setgroups((unsigned)-1, 0) currently returns -EINVAL, but a real kernel returns -EPERM here since the capability check runs first. The new "setgroups invalid size" test in tests/test-credentials.c bakes in this reversed order (it expects -EINVAL unconditionally, regardless of caller privilege), so it won't catch a fix.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed:

sys.c:

  • sys_setgroups() now checks privilege first, then validates gidsetsize, matching Linux behavior.

test-credentials.c:

  • invalid-size test now expects:root/fakeroot: -EINVAL
  • non-root: -EPERM

Wire aarch64 SYS_setgroups through the syscall dispatch table and
emulate it in the guest identity layer. Allow root/fakeroot callers to
set or clear supplementary groups as a no-op after validating the guest
group list, while non-root callers receive EPERM.

Extend credential coverage for root/fakeroot success, non-root denial,
bad pointers, zero-count calls, and invalid sizes.

Fix sysprog21#189
@jserv
jserv merged commit ffec4db into sysprog21:main Jul 18, 2026
10 checks passed
@doanbaotrung
doanbaotrung deleted the SYS_setgroups branch July 18, 2026 17:13
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.

Missing SYS_setgroups (Syscall 159) on AArch64 breaks privilege-dropping guest processes

3 participants