git: 515f5d89aa2c - stable/15 - namei: Preserve ABI root for absolute symlinks before fallback

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Tue, 17 Nov 2026 01:09:31 UTC
The branch stable/15 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=515f5d89aa2c6ce5cd93d4f56621f4ea49072417

commit 515f5d89aa2c6ce5cd93d4f56621f4ea49072417
Author:     Ricardo Branco <rbranco@suse.de>
AuthorDate: 2026-04-26 16:44:39 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-11-17 00:24:56 +0000

    namei: Preserve ABI root for absolute symlinks before fallback
    
    (cherry picked from commit 459ac3044b516af698d7342431bdbcf784fdf7a4)
---
 sys/kern/vfs_lookup.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c
index 6f06fc8268fc..1ed8af81dde2 100644
--- a/sys/kern/vfs_lookup.c
+++ b/sys/kern/vfs_lookup.c
@@ -778,13 +778,17 @@ restart:
 		cnp->cn_nameptr = cnp->cn_pnbuf;
 		if (*(cnp->cn_nameptr) == '/') {
 			/*
-			 * Reset the lookup to start from the real root without
-			 * origin path name reloading.
+			 * For ABI-root lookups, preserve the ABI root while
+			 * following absolute symlinks during the first lookup.
+			 *
+			 * Only force the real root after the ABI lookup has
+			 * already failed and namei() has restarted in the
+			 * native namespace.  Otherwise absolute symlinks inside
+			 * /compat/linux, including the ELF interpreter symlink,
+			 * incorrectly escape to the native root (PR 289739).
 			 */
-			if (__predict_false(ndp->ni_rootdir != pwd->pwd_rdir)) {
-				cnp->cn_flags |= ISRESTARTED;
+			if ((cnp->cn_flags & ISRESTARTED) != 0)
 				ndp->ni_rootdir = pwd->pwd_rdir;
-			}
 			vrele(dp);
 			error = namei_handle_root(ndp, &dp);
 			if (error != 0)