git: fd745e1db6b5 - main - linux(4): Use pwd_altroot() to tell namei() about ABI root path

From: Dmitry Chagin <dchagin_at_FreeBSD.org>
Date: Mon, 29 May 2023 08:20:07 UTC
The branch main has been updated by dchagin:

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

commit fd745e1db6b561900b8e5e9caa4ed05cf15398b3
Author:     Dmitry Chagin <dchagin@FreeBSD.org>
AuthorDate: 2023-05-29 08:16:46 +0000
Commit:     Dmitry Chagin <dchagin@FreeBSD.org>
CommitDate: 2023-05-29 08:16:46 +0000

    linux(4): Use pwd_altroot() to tell namei() about ABI root path
    
    PR:                     72920
    Differential Revision:  https://reviews.freebsd.org/D40090
    MFC after:              2 month
---
 sys/amd64/linux/linux_sysvec.c      |   6 +-
 sys/amd64/linux32/linux32_machdep.c |  12 +-
 sys/amd64/linux32/linux32_sysvec.c  |   6 +-
 sys/arm64/linux/linux_sysvec.c      |   4 +-
 sys/compat/linux/linux_emul.c       |  47 +----
 sys/compat/linux/linux_emul.h       |   3 +-
 sys/compat/linux/linux_file.c       | 407 ++++++------------------------------
 sys/compat/linux/linux_mib.c        |   4 -
 sys/compat/linux/linux_misc.c       | 120 ++---------
 sys/compat/linux/linux_stats.c      | 111 ++--------
 sys/compat/linux/linux_uid16.c      |  43 +---
 sys/compat/linux/linux_util.c       |  41 ++--
 sys/compat/linux/linux_util.h       |  25 +--
 sys/i386/linux/linux_machdep.c      |  15 +-
 sys/i386/linux/linux_sysvec.c       |   7 +-
 15 files changed, 158 insertions(+), 693 deletions(-)

diff --git a/sys/amd64/linux/linux_sysvec.c b/sys/amd64/linux/linux_sysvec.c
index 05afcdfcd045..943df00328fc 100644
--- a/sys/amd64/linux/linux_sysvec.c
+++ b/sys/amd64/linux/linux_sysvec.c
@@ -593,7 +593,6 @@ struct sysentvec elf_linux_sysvec = {
 	.sv_elf_core_osabi = ELFOSABI_NONE,
 	.sv_elf_core_abi_vendor = LINUX_ABI_VENDOR,
 	.sv_elf_core_prepare_notes = linux64_prepare_notes,
-	.sv_imgact_try	= linux_exec_imgact_try,
 	.sv_minsigstksz	= LINUX_MINSIGSTKSZ,
 	.sv_minuser	= VM_MIN_ADDRESS,
 	.sv_maxuser	= VM_MAXUSER_ADDRESS_LA48,
@@ -633,7 +632,7 @@ linux_on_exec_vmspace(struct proc *p, struct image_params *imgp)
 	error = linux_map_vdso(p, linux_vdso_obj, linux_vdso_base,
 	    LINUX_VDSOPAGE_SIZE, imgp);
 	if (error == 0)
-		linux_on_exec(p, imgp);
+		error = linux_on_exec(p, imgp);
 	return (error);
 }
 
@@ -775,7 +774,6 @@ static Elf64_Brandinfo linux_glibc2brand = {
 	.brand		= ELFOSABI_LINUX,
 	.machine	= EM_X86_64,
 	.compat_3_brand	= "Linux",
-	.emul_path	= linux_emul_path,
 	.interp_path	= "/lib64/ld-linux-x86-64.so.2",
 	.sysvec		= &elf_linux_sysvec,
 	.interp_newpath	= NULL,
@@ -787,7 +785,6 @@ static Elf64_Brandinfo linux_glibc2brandshort = {
 	.brand		= ELFOSABI_LINUX,
 	.machine	= EM_X86_64,
 	.compat_3_brand	= "Linux",
-	.emul_path	= linux_emul_path,
 	.interp_path	= "/lib64/ld-linux.so.2",
 	.sysvec		= &elf_linux_sysvec,
 	.interp_newpath	= NULL,
@@ -799,7 +796,6 @@ static Elf64_Brandinfo linux_muslbrand = {
 	.brand		= ELFOSABI_LINUX,
 	.machine	= EM_X86_64,
 	.compat_3_brand	= "Linux",
-	.emul_path	= linux_emul_path,
 	.interp_path	= "/lib/ld-musl-x86_64.so.1",
 	.sysvec		= &elf_linux_sysvec,
 	.interp_newpath	= NULL,
diff --git a/sys/amd64/linux32/linux32_machdep.c b/sys/amd64/linux32/linux32_machdep.c
index 23d8f8767282..4e5d6eb55fc6 100644
--- a/sys/amd64/linux32/linux32_machdep.c
+++ b/sys/amd64/linux32/linux32_machdep.c
@@ -118,18 +118,10 @@ int
 linux_execve(struct thread *td, struct linux_execve_args *args)
 {
 	struct image_args eargs;
-	char *path;
 	int error;
 
-	if (!LUSECONVPATH(td)) {
-		error = freebsd32_exec_copyin_args(&eargs, args->path, UIO_USERSPACE,
-		    args->argp, args->envp);
-	} else {
-		LCONVPATHEXIST(args->path, &path);
-		error = freebsd32_exec_copyin_args(&eargs, path, UIO_SYSSPACE,
-		    args->argp, args->envp);
-		LFREEPATH(path);
-	}
+	error = freebsd32_exec_copyin_args(&eargs, args->path, UIO_USERSPACE,
+	    args->argp, args->envp);
 	if (error == 0)
 		error = linux_common_execve(td, &eargs);
 	AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td);
diff --git a/sys/amd64/linux32/linux32_sysvec.c b/sys/amd64/linux32/linux32_sysvec.c
index 3cec5d2e9eeb..e51ae68a229d 100644
--- a/sys/amd64/linux32/linux32_sysvec.c
+++ b/sys/amd64/linux32/linux32_sysvec.c
@@ -794,7 +794,6 @@ struct sysentvec elf_linux_sysvec = {
 	.sv_elf_core_osabi = ELFOSABI_NONE,
 	.sv_elf_core_abi_vendor = LINUX_ABI_VENDOR,
 	.sv_elf_core_prepare_notes = linux32_prepare_notes,
-	.sv_imgact_try	= linux_exec_imgact_try,
 	.sv_minsigstksz	= LINUX_MINSIGSTKSZ,
 	.sv_minuser	= VM_MIN_ADDRESS,
 	.sv_maxuser	= LINUX32_MAXUSER,
@@ -834,7 +833,7 @@ linux_on_exec_vmspace(struct proc *p, struct image_params *imgp)
 	error = linux_map_vdso(p, linux_vdso_obj, linux_vdso_base,
 	    LINUX32_VDSOPAGE_SIZE, imgp);
 	if (error == 0)
-		linux_on_exec(p, imgp);
+		error = linux_on_exec(p, imgp);
 	return (error);
 }
 
@@ -973,7 +972,6 @@ static Elf32_Brandinfo linux_brand = {
 	.brand		= ELFOSABI_LINUX,
 	.machine	= EM_386,
 	.compat_3_brand	= "Linux",
-	.emul_path	= linux_emul_path,
 	.interp_path	= "/lib/ld-linux.so.1",
 	.sysvec		= &elf_linux_sysvec,
 	.interp_newpath	= NULL,
@@ -985,7 +983,6 @@ static Elf32_Brandinfo linux_glibc2brand = {
 	.brand		= ELFOSABI_LINUX,
 	.machine	= EM_386,
 	.compat_3_brand	= "Linux",
-	.emul_path	= linux_emul_path,
 	.interp_path	= "/lib/ld-linux.so.2",
 	.sysvec		= &elf_linux_sysvec,
 	.interp_newpath	= NULL,
@@ -997,7 +994,6 @@ static Elf32_Brandinfo linux_muslbrand = {
 	.brand		= ELFOSABI_LINUX,
 	.machine	= EM_386,
 	.compat_3_brand	= "Linux",
-	.emul_path	= linux_emul_path,
 	.interp_path	= "/lib/ld-musl-i386.so.1",
 	.sysvec		= &elf_linux_sysvec,
 	.interp_newpath	= NULL,
diff --git a/sys/arm64/linux/linux_sysvec.c b/sys/arm64/linux/linux_sysvec.c
index bb9ff25893eb..3e06634117fe 100644
--- a/sys/arm64/linux/linux_sysvec.c
+++ b/sys/arm64/linux/linux_sysvec.c
@@ -376,7 +376,6 @@ struct sysentvec elf_linux_sysvec = {
 	.sv_elf_core_osabi = ELFOSABI_NONE,
 	.sv_elf_core_abi_vendor = LINUX_ABI_VENDOR,
 	.sv_elf_core_prepare_notes = linux64_prepare_notes,
-	.sv_imgact_try	= linux_exec_imgact_try,
 	.sv_minsigstksz	= LINUX_MINSIGSTKSZ,
 	.sv_minuser	= VM_MIN_ADDRESS,
 	.sv_maxuser	= VM_MAXUSER_ADDRESS,
@@ -415,7 +414,7 @@ linux_on_exec_vmspace(struct proc *p, struct image_params *imgp)
 	error = linux_map_vdso(p, linux_vdso_obj, linux_vdso_base,
 	    LINUX_VDSOPAGE_SIZE, imgp);
 	if (error == 0)
-		linux_on_exec(p, imgp);
+		error = linux_on_exec(p, imgp);
 	return (error);
 }
 
@@ -536,7 +535,6 @@ static Elf64_Brandinfo linux_glibc2brand = {
 	.brand		= ELFOSABI_LINUX,
 	.machine	= EM_AARCH64,
 	.compat_3_brand	= "Linux",
-	.emul_path	= linux_emul_path,
 	.interp_path	= "/lib64/ld-linux-x86-64.so.2",
 	.sysvec		= &elf_linux_sysvec,
 	.interp_newpath	= NULL,
diff --git a/sys/compat/linux/linux_emul.c b/sys/compat/linux/linux_emul.c
index ab877116b9fc..6a2ea1f26fe5 100644
--- a/sys/compat/linux/linux_emul.c
+++ b/sys/compat/linux/linux_emul.c
@@ -211,41 +211,6 @@ linux_on_exit(struct proc *p)
 	free(pem, M_LINUX);
 }
 
-/*
- * If a Linux binary is exec'ing something, try this image activator
- * first.  We override standard shell script execution in order to
- * be able to modify the interpreter path.  We only do this if a Linux
- * binary is doing the exec, so we do not create an EXEC module for it.
- */
-int
-linux_exec_imgact_try(struct image_params *imgp)
-{
-	const char *head = (const char *)imgp->image_header;
-	char *rpath;
-	int error = -1;
-
-	/*
-	 * The interpreter for shell scripts run from a Linux binary needs
-	 * to be located in /compat/linux if possible in order to recursively
-	 * maintain Linux path emulation.
-	 */
-	if (((const short *)head)[0] == SHELLMAGIC) {
-		/*
-		 * Run our normal shell image activator.  If it succeeds attempt
-		 * to use the alternate path for the interpreter.  If an
-		 * alternate path is found, use our stringspace to store it.
-		 */
-		if ((error = exec_shell_imgact(imgp)) == 0) {
-			linux_emul_convpath(imgp->interpreter_name, UIO_SYSSPACE,
-			    &rpath, 0, AT_FDCWD);
-			if (rpath != NULL)
-				imgp->args->fname_buf =
-				    imgp->interpreter_name = rpath;
-		}
-	}
-	return (error);
-}
-
 int
 linux_common_execve(struct thread *td, struct image_args *eargs)
 {
@@ -271,6 +236,10 @@ linux_common_execve(struct thread *td, struct image_args *eargs)
 	 * FreeBSD binary we destroy Linux emuldata thread & proc entries.
 	 */
 	if (SV_CURPROC_ABI() != SV_ABI_LINUX) {
+
+		/* Clear ABI root directory if set. */
+		linux_pwd_onexec_native(td);
+
 		PROC_LOCK(p);
 		em = em_find(td);
 		KASSERT(em != NULL, ("proc_exec: thread emuldata not found.\n"));
@@ -287,7 +256,7 @@ linux_common_execve(struct thread *td, struct image_args *eargs)
 	return (EJUSTRETURN);
 }
 
-void
+int
 linux_on_exec(struct proc *p, struct image_params *imgp)
 {
 	struct thread *td;
@@ -295,6 +264,7 @@ linux_on_exec(struct proc *p, struct image_params *imgp)
 #if defined(__amd64__)
 	struct linux_pemuldata *pem;
 #endif
+	int error;
 
 	td = curthread;
 	MPASS((imgp->sysent->sv_flags & SV_ABI_MASK) == SV_ABI_LINUX);
@@ -327,6 +297,10 @@ linux_on_exec(struct proc *p, struct image_params *imgp)
 				continue;
 			linux_proc_init(td, othertd, true);
 		}
+
+		/* Set ABI root directory. */
+		if ((error = linux_pwd_onexec(td)) != 0)
+			return (error);
 	}
 #if defined(__amd64__)
 	/*
@@ -339,6 +313,7 @@ linux_on_exec(struct proc *p, struct image_params *imgp)
 		pem->persona |= LINUX_READ_IMPLIES_EXEC;
 	}
 #endif
+	return (0);
 }
 
 void
diff --git a/sys/compat/linux/linux_emul.h b/sys/compat/linux/linux_emul.h
index b4234b0f8cbc..0fde8a1abe69 100644
--- a/sys/compat/linux/linux_emul.h
+++ b/sys/compat/linux/linux_emul.h
@@ -50,11 +50,10 @@ struct linux_emuldata {
 
 struct linux_emuldata	*em_find(struct thread *);
 
-int	linux_exec_imgact_try(struct image_params *);
 void	linux_proc_init(struct thread *, struct thread *, bool);
 void	linux_on_exit(struct proc *);
 void	linux_schedtail(struct thread *);
-void	linux_on_exec(struct proc *, struct image_params *);
+int	linux_on_exec(struct proc *, struct image_params *);
 void	linux_thread_dtor(struct thread *);
 int	linux_common_execve(struct thread *, struct image_args *);
 
diff --git a/sys/compat/linux/linux_file.c b/sys/compat/linux/linux_file.c
index 3dfea8946e33..4e8c3f435261 100644
--- a/sys/compat/linux/linux_file.c
+++ b/sys/compat/linux/linux_file.c
@@ -99,18 +99,9 @@ static struct bsd_to_linux_bitmap mfd_bitmap[] = {
 int
 linux_creat(struct thread *td, struct linux_creat_args *args)
 {
-	char *path;
-	int error;
 
-	if (!LUSECONVPATH(td)) {
-		return (kern_openat(td, AT_FDCWD, args->path, UIO_USERSPACE,
-		    O_WRONLY | O_CREAT | O_TRUNC, args->mode));
-	}
-	LCONVPATHEXIST(args->path, &path);
-	error = kern_openat(td, AT_FDCWD, path, UIO_SYSSPACE,
-	    O_WRONLY | O_CREAT | O_TRUNC, args->mode);
-	LFREEPATH(path);
-	return (error);
+	return (kern_openat(td, AT_FDCWD, args->path, UIO_USERSPACE,
+	    O_WRONLY | O_CREAT | O_TRUNC, args->mode));
 }
 #endif
 
@@ -216,45 +207,20 @@ done:
 int
 linux_openat(struct thread *td, struct linux_openat_args *args)
 {
-	char *path;
-	int dfd, error;
+	int dfd;
 
 	dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
-	if (!LUSECONVPATH(td)) {
-		return (linux_common_open(td, dfd, args->filename, args->flags,
-		    args->mode, UIO_USERSPACE));
-	}
-	if (args->flags & LINUX_O_CREAT)
-		LCONVPATH_AT(args->filename, &path, 1, dfd);
-	else
-		LCONVPATH_AT(args->filename, &path, 0, dfd);
-
-	error = linux_common_open(td, dfd, path, args->flags, args->mode,
-	    UIO_SYSSPACE);
-	LFREEPATH(path);
-	return (error);
+	return (linux_common_open(td, dfd, args->filename, args->flags,
+	    args->mode, UIO_USERSPACE));
 }
 
 #ifdef LINUX_LEGACY_SYSCALLS
 int
 linux_open(struct thread *td, struct linux_open_args *args)
 {
-	char *path;
-	int error;
-
-	if (!LUSECONVPATH(td)) {
-		return (linux_common_open(td, AT_FDCWD, args->path, args->flags,
-		    args->mode, UIO_USERSPACE));
-	}
-	if (args->flags & LINUX_O_CREAT)
-		LCONVPATHCREAT(args->path, &path);
-	else
-		LCONVPATHEXIST(args->path, &path);
 
-	error = linux_common_open(td, AT_FDCWD, path, args->flags, args->mode,
-	    UIO_SYSSPACE);
-	LFREEPATH(path);
-	return (error);
+	return (linux_common_open(td, AT_FDCWD, args->path, args->flags,
+	    args->mode, UIO_USERSPACE));
 }
 #endif
 
@@ -284,17 +250,8 @@ linux_name_to_handle_at(struct thread *td,
 	if ((args->flags & LINUX_AT_EMPTY_PATH) != 0)
 		bsd_flags |= AT_EMPTY_PATH;
 
-	if (!LUSECONVPATH(td)) {
-		error = kern_getfhat(td, bsd_flags, fd, args->name,
-		    UIO_USERSPACE, &fh, UIO_SYSSPACE);
-	} else {
-		char *path;
-
-		LCONVPATH_AT(args->name, &path, 0, fd);
-		error = kern_getfhat(td, bsd_flags, fd, path, UIO_SYSSPACE,
-		    &fh, UIO_SYSSPACE);
-		LFREEPATH(path);
-	}
+	error = kern_getfhat(td, bsd_flags, fd, args->name,
+	    UIO_USERSPACE, &fh, UIO_SYSSPACE);
 	if (error != 0)
 		return (error);
 
@@ -645,24 +602,13 @@ out:
 int
 linux_access(struct thread *td, struct linux_access_args *args)
 {
-	char *path;
-	int error;
 
 	/* Linux convention. */
 	if (args->amode & ~(F_OK | X_OK | W_OK | R_OK))
 		return (EINVAL);
 
-	if (!LUSECONVPATH(td)) {
-		error = kern_accessat(td, AT_FDCWD, args->path, UIO_USERSPACE, 0,
-		    args->amode);
-	} else {
-		LCONVPATHEXIST(args->path, &path);
-		error = kern_accessat(td, AT_FDCWD, path, UIO_SYSSPACE, 0,
-		    args->amode);
-		LFREEPATH(path);
-	}
-
-	return (error);
+	return (kern_accessat(td, AT_FDCWD, args->path, UIO_USERSPACE, 0,
+	    args->amode));
 }
 #endif
 
@@ -670,23 +616,14 @@ static int
 linux_do_accessat(struct thread *td, int ldfd, const char *filename,
     int amode, int flags)
 {
-	char *path;
-	int error, dfd;
+	int dfd;
 
 	/* Linux convention. */
 	if (amode & ~(F_OK | X_OK | W_OK | R_OK))
 		return (EINVAL);
 
 	dfd = (ldfd == LINUX_AT_FDCWD) ? AT_FDCWD : ldfd;
-	if (!LUSECONVPATH(td)) {
-		error = kern_accessat(td, dfd, filename, UIO_USERSPACE, flags, amode);
-	} else {
-		LCONVPATHEXIST_AT(filename, &path, dfd);
-		error = kern_accessat(td, dfd, path, UIO_SYSSPACE, flags, amode);
-		LFREEPATH(path);
-	}
-
-	return (error);
+	return (kern_accessat(td, dfd, filename, UIO_USERSPACE, flags, amode));
 }
 
 int
@@ -722,33 +659,18 @@ linux_faccessat2(struct thread *td, struct linux_faccessat2_args *args)
 int
 linux_unlink(struct thread *td, struct linux_unlink_args *args)
 {
-	char *path;
 	int error;
 	struct stat st;
 
-	if (!LUSECONVPATH(td)) {
-		error = kern_funlinkat(td, AT_FDCWD, args->path, FD_NONE,
-		    UIO_USERSPACE, 0, 0);
-		if (error == EPERM) {
-			/* Introduce POSIX noncompliant behaviour of Linux */
-			if (kern_statat(td, 0, AT_FDCWD, args->path,
-			    UIO_USERSPACE, &st) == 0) {
-				if (S_ISDIR(st.st_mode))
-					error = EISDIR;
-			}
-		}
-	} else {
-		LCONVPATHEXIST(args->path, &path);
-		error = kern_funlinkat(td, AT_FDCWD, path, FD_NONE, UIO_SYSSPACE, 0, 0);
-		if (error == EPERM) {
-			/* Introduce POSIX noncompliant behaviour of Linux */
-			if (kern_statat(td, 0, AT_FDCWD, path, UIO_SYSSPACE,
-			    &st) == 0) {
-				if (S_ISDIR(st.st_mode))
-					error = EISDIR;
-			}
+	error = kern_funlinkat(td, AT_FDCWD, args->path, FD_NONE,
+	    UIO_USERSPACE, 0, 0);
+	if (error == EPERM) {
+		/* Introduce POSIX noncompliant behaviour of Linux */
+		if (kern_statat(td, 0, AT_FDCWD, args->path,
+		    UIO_USERSPACE, &st) == 0) {
+			if (S_ISDIR(st.st_mode))
+				error = EISDIR;
 		}
-		LFREEPATH(path);
 	}
 
 	return (error);
@@ -778,142 +700,75 @@ linux_unlinkat_impl(struct thread *td, enum uio_seg pathseg, const char *path,
 int
 linux_unlinkat(struct thread *td, struct linux_unlinkat_args *args)
 {
-	char *path;
-	int error, dfd;
+	int dfd;
 
 	if (args->flag & ~LINUX_AT_REMOVEDIR)
 		return (EINVAL);
 	dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
-	if (!LUSECONVPATH(td)) {
-		return (linux_unlinkat_impl(td, UIO_USERSPACE, args->pathname,
-		    dfd, args));
-	}
-	LCONVPATHEXIST_AT(args->pathname, &path, dfd);
-	error = linux_unlinkat_impl(td, UIO_SYSSPACE, path, dfd, args);
-	LFREEPATH(path);
-	return (error);
+	return (linux_unlinkat_impl(td, UIO_USERSPACE, args->pathname,
+	    dfd, args));
 }
+
 int
 linux_chdir(struct thread *td, struct linux_chdir_args *args)
 {
-	char *path;
-	int error;
 
-	if (!LUSECONVPATH(td)) {
-		return (kern_chdir(td, args->path, UIO_USERSPACE));
-	}
-	LCONVPATHEXIST(args->path, &path);
-	error = kern_chdir(td, path, UIO_SYSSPACE);
-	LFREEPATH(path);
-	return (error);
+	return (kern_chdir(td, args->path, UIO_USERSPACE));
 }
 
 #ifdef LINUX_LEGACY_SYSCALLS
 int
 linux_chmod(struct thread *td, struct linux_chmod_args *args)
 {
-	char *path;
-	int error;
 
-	if (!LUSECONVPATH(td)) {
-		return (kern_fchmodat(td, AT_FDCWD, args->path, UIO_USERSPACE,
-		    args->mode, 0));
-	}
-	LCONVPATHEXIST(args->path, &path);
-	error = kern_fchmodat(td, AT_FDCWD, path, UIO_SYSSPACE, args->mode, 0);
-	LFREEPATH(path);
-	return (error);
+	return (kern_fchmodat(td, AT_FDCWD, args->path, UIO_USERSPACE,
+	    args->mode, 0));
 }
 #endif
 
 int
 linux_fchmodat(struct thread *td, struct linux_fchmodat_args *args)
 {
-	char *path;
-	int error, dfd;
+	int dfd;
 
 	dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
-	if (!LUSECONVPATH(td)) {
-		return (kern_fchmodat(td, dfd, args->filename, UIO_USERSPACE,
-		    args->mode, 0));
-	}
-	LCONVPATHEXIST_AT(args->filename, &path, dfd);
-	error = kern_fchmodat(td, dfd, path, UIO_SYSSPACE, args->mode, 0);
-	LFREEPATH(path);
-	return (error);
+	return (kern_fchmodat(td, dfd, args->filename, UIO_USERSPACE,
+	    args->mode, 0));
 }
 
 #ifdef LINUX_LEGACY_SYSCALLS
 int
 linux_mkdir(struct thread *td, struct linux_mkdir_args *args)
 {
-	char *path;
-	int error;
 
-	if (!LUSECONVPATH(td)) {
-		return (kern_mkdirat(td, AT_FDCWD, args->path, UIO_USERSPACE, args->mode));
-	}
-	LCONVPATHCREAT(args->path, &path);
-	error = kern_mkdirat(td, AT_FDCWD, path, UIO_SYSSPACE, args->mode);
-	LFREEPATH(path);
-	return (error);
+	return (kern_mkdirat(td, AT_FDCWD, args->path, UIO_USERSPACE, args->mode));
 }
 #endif
 
 int
 linux_mkdirat(struct thread *td, struct linux_mkdirat_args *args)
 {
-	char *path;
-	int error, dfd;
+	int dfd;
 
 	dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
-	if (!LUSECONVPATH(td)) {
-		return (kern_mkdirat(td, dfd, args->pathname, UIO_USERSPACE, args->mode));
-	}
-	LCONVPATHCREAT_AT(args->pathname, &path, dfd);
-	error = kern_mkdirat(td, dfd, path, UIO_SYSSPACE, args->mode);
-	LFREEPATH(path);
-	return (error);
+	return (kern_mkdirat(td, dfd, args->pathname, UIO_USERSPACE, args->mode));
 }
 
 #ifdef LINUX_LEGACY_SYSCALLS
 int
 linux_rmdir(struct thread *td, struct linux_rmdir_args *args)
 {
-	char *path;
-	int error;
 
-	if (!LUSECONVPATH(td)) {
-		return (kern_frmdirat(td, AT_FDCWD, args->path, FD_NONE,
-		    UIO_USERSPACE, 0));
-	}
-	LCONVPATHEXIST(args->path, &path);
-	error = kern_frmdirat(td, AT_FDCWD, path, FD_NONE, UIO_SYSSPACE, 0);
-	LFREEPATH(path);
-	return (error);
+	return (kern_frmdirat(td, AT_FDCWD, args->path, FD_NONE,
+	    UIO_USERSPACE, 0));
 }
 
 int
 linux_rename(struct thread *td, struct linux_rename_args *args)
 {
-	char *from, *to;
-	int error;
 
-	if (!LUSECONVPATH(td)) {
-		return (kern_renameat(td, AT_FDCWD, args->from, AT_FDCWD,
-		    args->to, UIO_USERSPACE));
-	}
-	LCONVPATHEXIST(args->from, &from);
-	/* Expand LCONVPATHCREATE so that `from' can be freed on errors */
-	error = linux_emul_convpath(args->to, UIO_USERSPACE, &to, 1, AT_FDCWD);
-	if (to == NULL) {
-		LFREEPATH(from);
-		return (error);
-	}
-	error = kern_renameat(td, AT_FDCWD, from, AT_FDCWD, to, UIO_SYSSPACE);
-	LFREEPATH(from);
-	LFREEPATH(to);
-	return (error);
+	return (kern_renameat(td, AT_FDCWD, args->from, AT_FDCWD,
+	    args->to, UIO_USERSPACE));
 }
 #endif
 
@@ -934,8 +789,7 @@ linux_renameat(struct thread *td, struct linux_renameat_args *args)
 int
 linux_renameat2(struct thread *td, struct linux_renameat2_args *args)
 {
-	char *from, *to;
-	int error, olddfd, newdfd;
+	int olddfd, newdfd;
 
 	if (args->flags != 0) {
 		if (args->flags & ~(LINUX_RENAME_EXCHANGE |
@@ -960,137 +814,68 @@ linux_renameat2(struct thread *td, struct linux_renameat2_args *args)
 
 	olddfd = (args->olddfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->olddfd;
 	newdfd = (args->newdfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->newdfd;
-	if (!LUSECONVPATH(td)) {
-		return (kern_renameat(td, olddfd, args->oldname, newdfd,
-		    args->newname, UIO_USERSPACE));
-	}
-	LCONVPATHEXIST_AT(args->oldname, &from, olddfd);
-	/* Expand LCONVPATHCREATE so that `from' can be freed on errors */
-	error = linux_emul_convpath(args->newname, UIO_USERSPACE, &to, 1, newdfd);
-	if (to == NULL) {
-		LFREEPATH(from);
-		return (error);
-	}
-	error = kern_renameat(td, olddfd, from, newdfd, to, UIO_SYSSPACE);
-	LFREEPATH(from);
-	LFREEPATH(to);
-	return (error);
+	return (kern_renameat(td, olddfd, args->oldname, newdfd,
+	    args->newname, UIO_USERSPACE));
 }
 
 #ifdef LINUX_LEGACY_SYSCALLS
 int
 linux_symlink(struct thread *td, struct linux_symlink_args *args)
 {
-	char *path, *to;
-	int error;
 
-	if (!LUSECONVPATH(td)) {
-		return (kern_symlinkat(td, args->path, AT_FDCWD, args->to,
-		    UIO_USERSPACE));
-	}
-	LCONVPATHEXIST(args->path, &path);
-	/* Expand LCONVPATHCREATE so that `path' can be freed on errors */
-	error = linux_emul_convpath(args->to, UIO_USERSPACE, &to, 1, AT_FDCWD);
-	if (to == NULL) {
-		LFREEPATH(path);
-		return (error);
-	}
-	error = kern_symlinkat(td, path, AT_FDCWD, to, UIO_SYSSPACE);
-	LFREEPATH(path);
-	LFREEPATH(to);
-	return (error);
+	return (kern_symlinkat(td, args->path, AT_FDCWD, args->to,
+	    UIO_USERSPACE));
 }
 #endif
 
 int
 linux_symlinkat(struct thread *td, struct linux_symlinkat_args *args)
 {
-	char *path, *to;
-	int error, dfd;
+	int dfd;
 
 	dfd = (args->newdfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->newdfd;
-	if (!LUSECONVPATH(td)) {
-		return (kern_symlinkat(td, args->oldname, dfd, args->newname,
-		    UIO_USERSPACE));
-	}
-	LCONVPATHEXIST(args->oldname, &path);
-	/* Expand LCONVPATHCREATE so that `path' can be freed on errors */
-	error = linux_emul_convpath(args->newname, UIO_USERSPACE, &to, 1, dfd);
-	if (to == NULL) {
-		LFREEPATH(path);
-		return (error);
-	}
-	error = kern_symlinkat(td, path, dfd, to, UIO_SYSSPACE);
-	LFREEPATH(path);
-	LFREEPATH(to);
-	return (error);
+	return (kern_symlinkat(td, args->oldname, dfd, args->newname,
+	    UIO_USERSPACE));
 }
 
 #ifdef LINUX_LEGACY_SYSCALLS
 int
 linux_readlink(struct thread *td, struct linux_readlink_args *args)
 {
-	char *name;
-	int error;
 
 	if (args->count <= 0)
 		return (EINVAL);
 
-	if (!LUSECONVPATH(td)) {
-		return (kern_readlinkat(td, AT_FDCWD, args->name, UIO_USERSPACE,
-		    args->buf, UIO_USERSPACE, args->count));
-	}
-	LCONVPATHEXIST(args->name, &name);
-	error = kern_readlinkat(td, AT_FDCWD, name, UIO_SYSSPACE,
-	    args->buf, UIO_USERSPACE, args->count);
-	LFREEPATH(name);
-	return (error);
+	return (kern_readlinkat(td, AT_FDCWD, args->name, UIO_USERSPACE,
+	    args->buf, UIO_USERSPACE, args->count));
 }
 #endif
 
 int
 linux_readlinkat(struct thread *td, struct linux_readlinkat_args *args)
 {
-	char *name;
-	int error, dfd;
+	int dfd;
 
 	if (args->bufsiz <= 0)
 		return (EINVAL);
 
 	dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
-	if (!LUSECONVPATH(td)) {
-		return (kern_readlinkat(td, dfd, args->path, UIO_USERSPACE,
-		    args->buf, UIO_USERSPACE, args->bufsiz));
-	}
-	LCONVPATHEXIST_AT(args->path, &name, dfd);
-	error = kern_readlinkat(td, dfd, name, UIO_SYSSPACE, args->buf,
-	    UIO_USERSPACE, args->bufsiz);
-	LFREEPATH(name);
-	return (error);
+	return (kern_readlinkat(td, dfd, args->path, UIO_USERSPACE,
+	    args->buf, UIO_USERSPACE, args->bufsiz));
 }
 
 int
 linux_truncate(struct thread *td, struct linux_truncate_args *args)
 {
-	char *path;
-	int error;
 
-	if (!LUSECONVPATH(td)) {
-		return (kern_truncate(td, args->path, UIO_USERSPACE, args->length));
-	}
-	LCONVPATHEXIST(args->path, &path);
-	error = kern_truncate(td, path, UIO_SYSSPACE, args->length);
-	LFREEPATH(path);
-	return (error);
+	return (kern_truncate(td, args->path, UIO_USERSPACE, args->length));
 }
 
 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
 int
 linux_truncate64(struct thread *td, struct linux_truncate64_args *args)
 {
-	char *path;
 	off_t length;
-	int error;
 
 #if defined(__amd64__) && defined(COMPAT_LINUX32)
 	length = PAIR32TO64(off_t, args->length);
@@ -1098,13 +883,7 @@ linux_truncate64(struct thread *td, struct linux_truncate64_args *args)
 	length = args->length;
 #endif
 
-	if (!LUSECONVPATH(td)) {
-		return (kern_truncate(td, args->path, UIO_USERSPACE, length));
-	}
-	LCONVPATHEXIST(args->path, &path);
-	error = kern_truncate(td, path, UIO_SYSSPACE, length);
-	LFREEPATH(path);
-	return (error);
+	return (kern_truncate(td, args->path, UIO_USERSPACE, length));
 }
 #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
 
@@ -1135,33 +914,16 @@ linux_ftruncate64(struct thread *td, struct linux_ftruncate64_args *args)
 int
 linux_link(struct thread *td, struct linux_link_args *args)
 {
-	char *path, *to;
-	int error;
 
-	if (!LUSECONVPATH(td)) {
-		return (kern_linkat(td, AT_FDCWD, AT_FDCWD, args->path, args->to,
-		    UIO_USERSPACE, AT_SYMLINK_FOLLOW));
-	}
-	LCONVPATHEXIST(args->path, &path);
-	/* Expand LCONVPATHCREATE so that `path' can be freed on errors */
-	error = linux_emul_convpath(args->to, UIO_USERSPACE, &to, 1, AT_FDCWD);
-	if (to == NULL) {
-		LFREEPATH(path);
-		return (error);
-	}
-	error = kern_linkat(td, AT_FDCWD, AT_FDCWD, path, to, UIO_SYSSPACE,
-	    AT_SYMLINK_FOLLOW);
-	LFREEPATH(path);
-	LFREEPATH(to);
-	return (error);
+	return (kern_linkat(td, AT_FDCWD, AT_FDCWD, args->path, args->to,
+	    UIO_USERSPACE, AT_SYMLINK_FOLLOW));
 }
 #endif
 
 int
 linux_linkat(struct thread *td, struct linux_linkat_args *args)
 {
-	char *path, *to;
-	int error, olddfd, newdfd, flag;
+	int olddfd, newdfd, flag;
 
 	if (args->flag & ~(LINUX_AT_SYMLINK_FOLLOW | LINUX_AT_EMPTY_PATH))
 		return (EINVAL);
@@ -1172,21 +934,8 @@ linux_linkat(struct thread *td, struct linux_linkat_args *args)
 
 	olddfd = (args->olddfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->olddfd;
 	newdfd = (args->newdfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->newdfd;
-	if (!LUSECONVPATH(td)) {
-		return (kern_linkat(td, olddfd, newdfd, args->oldname,
-		    args->newname, UIO_USERSPACE, flag));
-	}
-	LCONVPATHEXIST_AT(args->oldname, &path, olddfd);
-	/* Expand LCONVPATHCREATE so that `path' can be freed on errors */
-	error = linux_emul_convpath(args->newname, UIO_USERSPACE, &to, 1, newdfd);
-	if (to == NULL) {
-		LFREEPATH(path);
-		return (error);
-	}
-	error = kern_linkat(td, olddfd, newdfd, path, to, UIO_SYSSPACE, flag);
-	LFREEPATH(path);
-	LFREEPATH(to);
-	return (error);
+	return (kern_linkat(td, olddfd, newdfd, args->oldname,
+	    args->newname, UIO_USERSPACE, flag));
 }
 
 int
@@ -1772,26 +1521,16 @@ linux_fcntl64(struct thread *td, struct linux_fcntl64_args *args)
 int
 linux_chown(struct thread *td, struct linux_chown_args *args)
 {
-	char *path;
-	int error;
 
-	if (!LUSECONVPATH(td)) {
-		return (kern_fchownat(td, AT_FDCWD, args->path, UIO_USERSPACE,
-		    args->uid, args->gid, 0));
-	}
-	LCONVPATHEXIST(args->path, &path);
-	error = kern_fchownat(td, AT_FDCWD, path, UIO_SYSSPACE, args->uid,
-	    args->gid, 0);
-	LFREEPATH(path);
-	return (error);
+	return (kern_fchownat(td, AT_FDCWD, args->path, UIO_USERSPACE,
+	    args->uid, args->gid, 0));
 }
 #endif
 
 int
 linux_fchownat(struct thread *td, struct linux_fchownat_args *args)
 {
-	char *path;
-	int error, dfd, flag, unsupported;
+	int dfd, flag, unsupported;
 
 	unsupported = args->flag & ~(LINUX_AT_SYMLINK_NOFOLLOW | LINUX_AT_EMPTY_PATH);
 	if (unsupported != 0) {
@@ -1805,33 +1544,17 @@ linux_fchownat(struct thread *td, struct linux_fchownat_args *args)
 	    AT_EMPTY_PATH;
 
 	dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD :  args->dfd;
-	if (!LUSECONVPATH(td)) {
-		return (kern_fchownat(td, dfd, args->filename, UIO_USERSPACE,
-		    args->uid, args->gid, flag));
-	}
-	LCONVPATHEXIST_AT(args->filename, &path, dfd);
-	error = kern_fchownat(td, dfd, path, UIO_SYSSPACE, args->uid, args->gid,
-	    flag);
-	LFREEPATH(path);
-	return (error);
+	return (kern_fchownat(td, dfd, args->filename, UIO_USERSPACE,
+	    args->uid, args->gid, flag));
 }
 
 #ifdef LINUX_LEGACY_SYSCALLS
 int
 linux_lchown(struct thread *td, struct linux_lchown_args *args)
 {
-	char *path;
-	int error;
 
-	if (!LUSECONVPATH(td)) {
-		return (kern_fchownat(td, AT_FDCWD, args->path, UIO_USERSPACE, args->uid,
-		    args->gid, AT_SYMLINK_NOFOLLOW));
-	}
-	LCONVPATHEXIST(args->path, &path);
-	error = kern_fchownat(td, AT_FDCWD, path, UIO_SYSSPACE, args->uid, args->gid,
-	    AT_SYMLINK_NOFOLLOW);
-	LFREEPATH(path);
-	return (error);
+	return (kern_fchownat(td, AT_FDCWD, args->path, UIO_USERSPACE, args->uid,
+	    args->gid, AT_SYMLINK_NOFOLLOW));
 }
 #endif
 
diff --git a/sys/compat/linux/linux_mib.c b/sys/compat/linux/linux_mib.c
index 29e86ea1f07b..714225ef9f1c 100644
--- a/sys/compat/linux/linux_mib.c
+++ b/sys/compat/linux/linux_mib.c
@@ -91,10 +91,6 @@ SYSCTL_BOOL(_compat_linux, OID_AUTO, map_sched_prio, CTLFLAG_RDTUN,
     &linux_map_sched_prio, 0, "Map scheduler priorities to Linux priorities "
     "(not POSIX compliant)");
 
-int linux_use_emul_path = 1;
-SYSCTL_INT(_compat_linux, OID_AUTO, use_emul_path, CTLFLAG_RWTUN,
-    &linux_use_emul_path, 0, "Use linux.compat.emul_path");
-
 static bool linux_setid_allowed = true;
 SYSCTL_BOOL(_compat_linux, OID_AUTO, setid_allowed, CTLFLAG_RWTUN,
     &linux_setid_allowed, 0,
diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c
index bc6ff9559493..b5d48d106be6 100644
--- a/sys/compat/linux/linux_misc.c
+++ b/sys/compat/linux/linux_misc.c
@@ -474,7 +474,6 @@ linux_utime(struct thread *td, struct linux_utime_args *args)
 {
 	struct timeval tv[2], *tvp;
 	struct l_utimbuf lut;
-	char *fname;
 	int error;
 
 	if (args->times) {
@@ -488,16 +487,8 @@ linux_utime(struct thread *td, struct linux_utime_args *args)
 	} else
 		tvp = NULL;
 
-	if (!LUSECONVPATH(td)) {
-		error = kern_utimesat(td, AT_FDCWD, args->fname, UIO_USERSPACE,
-		    tvp, UIO_SYSSPACE);
-	} else {
-		LCONVPATHEXIST(args->fname, &fname);
-		error = kern_utimesat(td, AT_FDCWD, fname, UIO_SYSSPACE, tvp,
-		    UIO_SYSSPACE);
-		LFREEPATH(fname);
-	}
-	return (error);
+	return (kern_utimesat(td, AT_FDCWD, args->fname, UIO_USERSPACE,
+	    tvp, UIO_SYSSPACE));
 }
*** 700 LINES SKIPPED ***