Emulate setgroups for fakeroot guests#216
Merged
Merged
Conversation
Max042004
suggested changes
Jul 18, 2026
|
|
||
| int64_t sys_setgroups(guest_t *g, int size, uint64_t list_gva) | ||
| { | ||
| if (size < 0 || size > LINUX_NGROUPS_MAX) |
Collaborator
There was a problem hiding this comment.
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.
Collaborator
Author
There was a problem hiding this comment.
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
doanbaotrung
force-pushed
the
SYS_setgroups
branch
from
July 18, 2026 15:55
28269c4 to
b4b693c
Compare
Max042004
approved these changes
Jul 18, 2026
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.
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_setgroupsand making root/fakeroot calls a validated no-op. Non-root calls return-EPERM. Fixes #189.SYS_setgroups(159) inabi.h; wired indispatch.tbl; forwardedsc_setgroupstosys_setgroups.-EPERM.-EINVAL; bad pointer →-EFAULT; alloc failure →-ENOMEM.tests/test-credentials.cto cover root/fakeroot success, non-root denial, bad pointer, zero count, and invalid size.Written for commit b4b693c. Summary will update on new commits.