Skip to content

sched: supplementary groups and setresuid/setresgid - #19767

Merged
acassis merged 3 commits into
apache:masterfrom
Abhishekmishra2808:feature/supp-groups-and-sudo
Aug 12, 2026
Merged

sched: supplementary groups and setresuid/setresgid#19767
acassis merged 3 commits into
apache:masterfrom
Abhishekmishra2808:feature/supp-groups-and-sudo

Conversation

@Abhishekmishra2808

@Abhishekmishra2808 Abhishekmishra2808 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  1. Add per-task-group supplementary GIDs (setgroups / getgroups / initgroups) when CONFIG_SCHED_NGROUPS > 0
  2. Add setresuid / setresgid for real/effective/saved UID and GID changes
  3. Extend DAC checks (binfmt, pseudoFS/inode) via nxsched_has_gid(tcb, gid)
  4. When CONFIG_SCHED_NGROUPS == 0, provide libc getgroups/setgroups stubs
  5. Add private uid_valid/gid_valid helpers

Impact

This change adds POSIX supplementary group support and setresuid/setresgid to NuttX’s user-identity layer. When CONFIG_SCHED_NGROUPS > 0, each task group keeps a supplementary GID list wired through setgroups, getgroups, and initgroups; DAC checks in binfmt exec and inode permission paths now use nxsched_has_gid() so access can be granted via supplementary membership, not only the primary GID. When CONFIG_SCHED_NGROUPS is zero, the kernel omits group syscall code and libc supplies getgroups/setgroups stubs, so builds without supplementary groups stay lean. setresuid and setresgid complete the real/effective/saved credential setters needed for login and privilege-drop flows without relying on setreuid alone. Configs without CONFIG_SCHED_USER_IDENTITY are unaffected.

Testing

nsh# useradd testuser UserPass1!
nsh# cat /tmp/passwd
root:$pbkdf2-sha256$10000$uwK3GNfobksYkqa5H9-Rcw$kNsxMZi26PeLxdWKgFjNvZpOoouP_DcHyO2mwyACVc0:0:0:/
testuser:$pbkdf2-sha256$10000$LCsDACzp0RA26xvaHPsY2g$gfCJXfLINNOKNIpVqepoUaYJiMbB8ojezAlosZJnrXY:1000:1000:/
nsh# su testuser
nsh$ id
uid=1000(testuser) suid=0(root) gid=1000 sgid=0(root) groups=1000
nsh$ su root
password: 
nsh# id
uid=0(root) gid=0(root) groups=0(root)
nsh# 

@github-actions github-actions Bot added Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. Area: BINFMT labels Aug 10, 2026
@Abhishekmishra2808
Abhishekmishra2808 force-pushed the feature/supp-groups-and-sudo branch from 6602cf8 to f3e8f00 Compare August 10, 2026 16:08
@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

Comment thread sched/group/group_setgroups.c Outdated
Comment thread sched/group/group_getgroups.c Outdated
Comment thread sched/group/group_setgroups.c Outdated
Comment thread binfmt/binfmt_checkexec.c Outdated
Comment thread fs/inode/fs_inode.c Outdated
Comment thread include/nuttx/sched.h Outdated
Comment thread sched/group/group_setresgid.c Outdated
Comment thread sched/group/group_setresuid.c Outdated
Comment thread sched/task/task_nshcred_auth.c Outdated
Comment thread include/sys/prctl.h Outdated
@Abhishekmishra2808
Abhishekmishra2808 force-pushed the feature/supp-groups-and-sudo branch 3 times, most recently from 897a50a to 360775a Compare August 12, 2026 06:40
@github-actions github-actions Bot added Size: L The size of the change in this PR is large and removed Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. labels Aug 12, 2026
Comment thread include/sys/types.h Outdated
@Abhishekmishra2808
Abhishekmishra2808 force-pushed the feature/supp-groups-and-sudo branch from ee6a2d9 to 021c319 Compare August 12, 2026 07:16
@github-actions github-actions Bot added Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. and removed Size: L The size of the change in this PR is large labels Aug 12, 2026
@Abhishekmishra2808
Abhishekmishra2808 force-pushed the feature/supp-groups-and-sudo branch from 021c319 to 8be13db Compare August 12, 2026 07:20
@Abhishekmishra2808 Abhishekmishra2808 changed the title sched: supplementary groups, setresuid/setresgid, and PR_NSHCRED_AUTHSETEID sched: supplementary groups and setresuid/setresgid Aug 12, 2026
Comment thread include/sys/types.h Outdated
@Abhishekmishra2808
Abhishekmishra2808 force-pushed the feature/supp-groups-and-sudo branch from 8be13db to b9e6c77 Compare August 12, 2026 09:36
@github-actions github-actions Bot added Size: L The size of the change in this PR is large and removed Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. labels Aug 12, 2026
Comment thread libs/libc/grp/lib_initgroups.c Outdated
Track supplementary GIDs per task group, wire setgroups/getgroups
syscalls when CONFIG_SCHED_NGROUPS > 0, and honor them in DAC checks
via nxsched_has_gid().  When NGROUPS is 0, libc provides getgroups/
setgroups stubs.  initgroups() fails instead of silently truncating
when membership exceeds CONFIG_SCHED_NGROUPS.

Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
Complete the POSIX credential setters for real/effective/saved UID and
GID so login and privilege-drop paths can clear saved-root without
relying on setreuid patterns alone.

Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
Document CONFIG_SCHED_NGROUPS, setgroups/getgroups/initgroups, and
setresuid/setresgid in the user identity guide.

Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
@Abhishekmishra2808
Abhishekmishra2808 force-pushed the feature/supp-groups-and-sudo branch from b9e6c77 to c0f8ed8 Compare August 12, 2026 12:03
@Abhishekmishra2808

Copy link
Copy Markdown
Contributor Author

@acassis PTAL

@acassis
acassis merged commit 3bc0b17 into apache:master Aug 12, 2026
78 of 94 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: BINFMT Size: L The size of the change in this PR is large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants