diff options
| author | Konstantin Belousov <kib@FreeBSD.org> | 2026-09-28 21:53:05 +0000 |
|---|---|---|
| committer | Konstantin Belousov <kib@FreeBSD.org> | 2026-11-20 15:10:26 +0000 |
| commit | 2137bad49a6f4336cbc6c4045fdaf408dcc96f06 (patch) | |
| tree | 6459c929c80e2e5f545aef395ba7923f8edd140e | |
| parent | e880b7ad36567d5ba3cfd47c4c376b18ace2330a (diff) | |
exec_new_vmspace(): drop altroot for native processes if setuid
Noted and reviewed by: markj
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D60035
| -rw-r--r-- | sys/kern/kern_exec.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index 7871ac9b86fa..390f4cdaf3ed 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -1265,6 +1265,20 @@ exec_new_vmspace(struct image_params *imgp, struct sysentvec *sv) imgp->vmspace_destroyed = true; imgp->sysent = sv; + /* + * Drop altroot if setuid. It is done so late to avoid + * clearing altroot until there is no way for execve(2) to + * return to the calling image. + * + * Setuid is ignored for P2_NO_NEW_PRIVS processes, but + * credential_setid is only cleared by execve_nosetid() after + * the image activator returns, so check the flag here. + */ + if (imgp->credential_setid && + (p->p_flag2 & P2_NO_NEW_PRIVS) == 0 && + (sv->sv_flags & SV_ABI_MASK) == SV_ABI_FREEBSD) + pwd_altroot(td, NULL); + if (p->p_sysent->sv_onexec_old != NULL) p->p_sysent->sv_onexec_old(td); itimers_exec(p); |
