From cea7c564c70aa660d833e9a571aaca4119c0b714 Mon Sep 17 00:00:00 2001 From: Dmitry Chagin Date: Tue, 13 Jun 2023 15:24:25 +0300 Subject: [PATCH] namei: Reset the lookup to start from the real root for abs symlink target MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since fd745e1d Linux ABI specifies alternative root directory to reroot lookups. First, an attempt is made to lookup the file in /ABI/original-path. If that fails, the lookup is done in /original-path. In case of lookup symbolic link with leading / in target namei() fails due to reroot reloads original file name. To avoid this handle restart in a special maner, without origin path name reloading. Reported by: Goran Mekić, Vincent Milum Jr Tested by: Goran Mekić Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D40479 --- sys/kern/vfs_lookup.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c index 20919fb38b4..dd6282a45d9 100644 --- a/sys/kern/vfs_lookup.c +++ b/sys/kern/vfs_lookup.c @@ -721,6 +721,14 @@ namei(struct nameidata *ndp) */ cnp->cn_nameptr = cnp->cn_pnbuf; if (*(cnp->cn_nameptr) == '/') { + /* + * Reset the lookup to start from the real root without + * origin path name reloading. + */ + if (__predict_false(ndp->ni_rootdir != pwd->pwd_rdir)) { + cnp->cn_flags |= ISRESTARTED; + ndp->ni_rootdir = pwd->pwd_rdir; + } vrele(dp); error = namei_handle_root(ndp, &dp); if (error != 0)