git: 7396c23e5deb - main - linux: harden the linux_pwd_onexec() altroot entry

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Mon, 23 Nov 2026 00:16:01 UTC
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=7396c23e5deb0713f02c7138834f5a5a963f9f08

commit 7396c23e5deb0713f02c7138834f5a5a963f9f08
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-11-21 03:07:58 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-11-23 00:10:23 +0000

    linux: harden the linux_pwd_onexec() altroot entry
    
    Do not take the native altroot into account when looking up
    linux_emul_path.
    
    Reported by:    llm-postcr
    Reviewed by:    markj
    Fixes:  9757c0cf98e4 ("chaltroot(2) and fchaltroot(2): new syscalls")
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D61858
---
 sys/compat/linux/linux_util.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/sys/compat/linux/linux_util.c b/sys/compat/linux/linux_util.c
index d9f652e55cb2..5e211f3a1180 100644
--- a/sys/compat/linux/linux_util.c
+++ b/sys/compat/linux/linux_util.c
@@ -84,16 +84,18 @@ linux_pwd_onexec(struct thread *td)
 	struct nameidata nd;
 	int error;
 
+	/*
+	 * We never want the native altroot, in particular, for the
+	 * linux_emul_path lookup.
+	 */
+	pwd_altroot_clear(td);
+
 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, linux_emul_path);
 	error = namei(&nd);
-	if (error != 0) {
-		pwd_altroot_clear(td);
+	if (error != 0)
 		return (0);
-	}
 	NDFREE_PNBUF(&nd);
-	error = pwd_altroot(td, nd.ni_vp);
-	if (error != 0)
-		pwd_altroot_clear(td);
+	(void)pwd_altroot(td, nd.ni_vp);
 	vrele(nd.ni_vp);
 	return (0);
 }