sched: supplementary groups, setresuid/setresgid, and PR_NSHCRED_AUTHSETEID - #19767
sched: supplementary groups, setresuid/setresgid, and PR_NSHCRED_AUTHSETEID#19767Abhishekmishra2808 wants to merge 4 commits into
Conversation
6602cf8 to
f3e8f00
Compare
055ab91 to
0fc9c1b
Compare
| #if CONFIG_SCHED_NGROUPS > 0 | ||
| for (i = 0; i < size; i++) | ||
| { | ||
| if ((uint16_t)list[i] > INT16_MAX) |
There was a problem hiding this comment.
why add this check
There was a problem hiding this comment.
matches existing UID/GID APIs
| rgroup = rtcb->group; | ||
| DEBUGASSERT(rgroup != NULL); | ||
|
|
||
| #if CONFIG_SCHED_NGROUPS > 0 |
There was a problem hiding this comment.
should we move the code related to CONFIG_SCHED_NGROUPS == 0 to libc?
There was a problem hiding this comment.
Yes, done
| } | ||
|
|
||
| rgroup->tg_ngroups = size; | ||
| #else |
There was a problem hiding this comment.
move the dummy code to libc too
| int binfmt_checkexecperm(FAR struct binary_s *bin) | ||
| { | ||
| FAR struct tcb_s *rtcb; | ||
| FAR struct task_group_s *tgroup; |
| int fs_checkmode(uid_t owner, gid_t group, mode_t mode, int amode) | ||
| { | ||
| FAR struct tcb_s *rtcb; | ||
| FAR struct task_group_s *tgroup; |
| #define GROUP_FLAG_SECURE_EXEC (1 << 5) /* Bit 5: Secure (setuid/setgid) executable */ | ||
| #define GROUP_FLAG_DUMPABLE (1 << 6) /* Bit 6: Process may be traced / coredumped */ | ||
| /* Bit 7: Available */ | ||
| #define GROUP_FLAG_NSHCRED (1 << 7) /* Bit 7: NSH credential agent (login/su) */ |
There was a problem hiding this comment.
where use this flag
There was a problem hiding this comment.
Set by PR_NSHCRED_ENABLE, required by AUTHSETEID.
| gid_t new_egid; | ||
| gid_t new_sgid; | ||
|
|
||
| if ((rgid != (gid_t)-1 && (uint16_t)rgid > INT16_MAX) || |
There was a problem hiding this comment.
why limit to INT16_MAX
There was a problem hiding this comment.
matches existing UID/GID APIs
| uid_t new_euid; | ||
| uid_t new_suid; | ||
|
|
||
| if ((ruid != (uid_t)-1 && (uint16_t)ruid > INT16_MAX) || |
| return -EPERM; | ||
| } | ||
|
|
||
| if ((uint16_t)euid > INT16_MAX || (uint16_t)egid > INT16_MAX) |
| * Requires euid == 0. Not inherited by child task groups. | ||
| * Required for PR_NSHCRED_AUTHSETEID. | ||
| * | ||
| * PR_NSHCRED_AUTHSETEID — verify username/password against the passwd |
There was a problem hiding this comment.
but why move the verify into kernel? it's better to keep it in userspace
There was a problem hiding this comment.
After hard-drop, raise needs a privileged API. If that API only checks an agent flag (old TOKEN), userspace can skip verify and still raise. AUTHSETEID binds verify and raise together for that reason (on flat builds with no memory isolation).
Soft-drop / saved UIDs avoids kernel passwd checks, but then raise-after-hard-drop goes away.
There was a problem hiding this comment.
Do you prefer keeping atomic kernel verify for hard-drop, or dropping hard-drop and using soft-drop only?
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>
Collapse password verification and euid/egid raise into one in-kernel prctl so hard-dropped NSH agents cannot mint privilege without the correct password. This replaces an earlier TOKEN+SETEID split that allowed mint-without-verify inside a flat address space. PR_NSHCRED_ENABLE still marks the agent task group at trusted init; AUTHSETEID requires that flag and a matching PBKDF2 passwd hash. Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
Document hard/soft drop, setresuid/setresgid, and PR_NSHCRED_AUTHSETEID for NSH login, su, and sudo. Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
0fc9c1b to
b569903
Compare
Summary
Impact
This extends NuttX process credentials with supplementary groups and full setres* support, and adds an in-kernel password-authenticated path to raise effective IDs for hard-dropped NSH sessions. Boards that enable CONFIG_SCHED_USER_IDENTITY (and related passwd/crypto options for AUTHSETEID) get the new syscalls and prctl commands; default configs that leave user identity disabled are unchanged.
Testing