svn commit: r364366 - in head/sys: amd64/linux arm64/linux compat/linux i386/linux

Mateusz Guzik mjg at FreeBSD.org
Tue Aug 18 22:04:25 UTC 2020


Author: mjg
Date: Tue Aug 18 22:04:22 2020
New Revision: 364366
URL: https://svnweb.freebsd.org/changeset/base/364366

Log:
  linux: add sysctl compat.linux.use_emul_path
  
  This is a step towards facilitating jails with only Linux binaries.
  Supporting emul_path adds path lookups which are completely spurious
  if the binary at hand runs in a Linux-based root directory.
  
  It defaults to on (== current behavior).
  
  make -C /root/linux-5.3-rc8 -s -j 1 bzImage:
  
  use_emul_path=1: 101.65s user 68.68s system 100% cpu 2:49.62 total
  use_emul_path=0: 101.41s user 64.32s system 100% cpu 2:45.02 total

Modified:
  head/sys/amd64/linux/linux_machdep.c
  head/sys/arm64/linux/linux_machdep.c
  head/sys/compat/linux/linux_file.c
  head/sys/compat/linux/linux_mib.c
  head/sys/compat/linux/linux_misc.c
  head/sys/compat/linux/linux_stats.c
  head/sys/compat/linux/linux_uid16.c
  head/sys/compat/linux/linux_util.h
  head/sys/i386/linux/linux_machdep.c

Modified: head/sys/amd64/linux/linux_machdep.c
==============================================================================
--- head/sys/amd64/linux/linux_machdep.c	Tue Aug 18 22:03:55 2020	(r364365)
+++ head/sys/amd64/linux/linux_machdep.c	Tue Aug 18 22:04:22 2020	(r364366)
@@ -98,13 +98,17 @@ linux_execve(struct thread *td, struct linux_execve_ar
 	char *path;
 	int error;
 
-	LCONVPATHEXIST(td, args->path, &path);
-
 	LINUX_CTR(execve);
 
-	error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, args->argp,
-	    args->envp);
-	LFREEPATH(path);
+	if (!LUSECONVPATH(td)) {
+		error = exec_copyin_args(&eargs, args->path, UIO_USERSPACE,
+		    args->argp, args->envp);
+	} else {
+		LCONVPATHEXIST(td, args->path, &path);
+		error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, args->argp,
+		    args->envp);
+		LFREEPATH(path);
+	}
 	if (error == 0)
 		error = linux_common_execve(td, &eargs);
 	return (error);

Modified: head/sys/arm64/linux/linux_machdep.c
==============================================================================
--- head/sys/arm64/linux/linux_machdep.c	Tue Aug 18 22:03:55 2020	(r364365)
+++ head/sys/arm64/linux/linux_machdep.c	Tue Aug 18 22:04:22 2020	(r364366)
@@ -67,11 +67,15 @@ linux_execve(struct thread *td, struct linux_execve_ar
 	char *path;
 	int error;
 
-	LCONVPATHEXIST(td, uap->path, &path);
-
-	error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, uap->argp,
-	    uap->envp);
-	LFREEPATH(path);
+	if (!LUSECONVPATH(td)) {
+		error = exec_copyin_args(&eargs, uap->path, UIO_USERSPACE,
+		    uap->argp, uap->envp);
+	} else {
+		LCONVPATHEXIST(td, uap->path, &path);
+		error = exec_copyin_args(&eargs, path, UIO_SYSSPACE,
+		    uap->argp, uap->envp);
+		LFREEPATH(path);
+	}
 	if (error == 0)
 		error = linux_common_execve(td, &eargs);
 	return (error);

Modified: head/sys/compat/linux/linux_file.c
==============================================================================
--- head/sys/compat/linux/linux_file.c	Tue Aug 18 22:03:55 2020	(r364365)
+++ head/sys/compat/linux/linux_file.c	Tue Aug 18 22:04:22 2020	(r364366)
@@ -66,7 +66,8 @@ __FBSDID("$FreeBSD$");
 #include <compat/linux/linux_util.h>
 #include <compat/linux/linux_file.h>
 
-static int	linux_common_open(struct thread *, int, char *, int, int);
+static int	linux_common_open(struct thread *, int, const char *, int, int,
+		    enum uio_seg);
 static int	linux_getdents_error(struct thread *, int, int);
 
 static struct bsd_to_linux_bitmap seal_bitmap[] = {
@@ -107,17 +108,22 @@ linux_creat(struct thread *td, struct linux_creat_args
 	char *path;
 	int error;
 
-	LCONVPATHEXIST(td, args->path, &path);
-
-	error = kern_openat(td, AT_FDCWD, path, UIO_SYSSPACE,
-	    O_WRONLY | O_CREAT | O_TRUNC, args->mode);
-	LFREEPATH(path);
+	if (!LUSECONVPATH(td)) {
+		error = kern_openat(td, AT_FDCWD, args->path, UIO_USERSPACE,
+		    O_WRONLY | O_CREAT | O_TRUNC, args->mode);
+	} else {
+		LCONVPATHEXIST(td, args->path, &path);
+		error = kern_openat(td, AT_FDCWD, path, UIO_SYSSPACE,
+		    O_WRONLY | O_CREAT | O_TRUNC, args->mode);
+		LFREEPATH(path);
+	}
 	return (error);
 }
 #endif
 
 static int
-linux_common_open(struct thread *td, int dirfd, char *path, int l_flags, int mode)
+linux_common_open(struct thread *td, int dirfd, const char *path, int l_flags,
+    int mode, enum uio_seg seg)
 {
 	struct proc *p = td->td_proc;
 	struct file *fp;
@@ -163,7 +169,7 @@ linux_common_open(struct thread *td, int dirfd, char *
 		bsd_flags |= O_DIRECTORY;
 	/* XXX LINUX_O_NOATIME: unable to be easily implemented. */
 
-	error = kern_openat(td, dirfd, path, UIO_SYSSPACE, bsd_flags, mode);
+	error = kern_openat(td, dirfd, path, seg, bsd_flags, mode);
 	if (error != 0) {
 		if (error == EMLINK)
 			error = ELOOP;
@@ -201,7 +207,6 @@ linux_common_open(struct thread *td, int dirfd, char *
 	}
 
 done:
-	LFREEPATH(path);
 	return (error);
 }
 
@@ -209,15 +214,22 @@ int
 linux_openat(struct thread *td, struct linux_openat_args *args)
 {
 	char *path;
-	int dfd;
+	int dfd, error;
 
 	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(td, args->filename, &path, 1, dfd);
 	else
 		LCONVPATH_AT(td, args->filename, &path, 0, dfd);
 
-	return (linux_common_open(td, dfd, path, args->flags, args->mode));
+	error = linux_common_open(td, dfd, path, args->flags, args->mode,
+	    UIO_SYSSPACE);
+	LFREEPATH(path);
+	return (error);
 }
 
 #ifdef LINUX_LEGACY_SYSCALLS
@@ -225,13 +237,21 @@ 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(td, args->path, &path);
 	else
 		LCONVPATHEXIST(td, args->path, &path);
 
-	return (linux_common_open(td, AT_FDCWD, path, args->flags, args->mode));
+	error = linux_common_open(td, AT_FDCWD, path, args->flags, args->mode,
+	    UIO_SYSSPACE);
+	LFREEPATH(path);
+	return (error);
 }
 #endif
 
@@ -535,12 +555,16 @@ linux_access(struct thread *td, struct linux_access_ar
 	if (args->amode & ~(F_OK | X_OK | W_OK | R_OK))
 		return (EINVAL);
 
-	LCONVPATHEXIST(td, args->path, &path);
+	if (!LUSECONVPATH(td)) {
+		error = kern_accessat(td, AT_FDCWD, args->path, UIO_USERSPACE, 0,
+		    args->amode);
+	} else {
+		LCONVPATHEXIST(td, args->path, &path);
+		error = kern_accessat(td, AT_FDCWD, path, UIO_SYSSPACE, 0,
+		    args->amode);
+		LFREEPATH(path);
+	}
 
-	error = kern_accessat(td, AT_FDCWD, path, UIO_SYSSPACE, 0,
-	    args->amode);
-	LFREEPATH(path);
-
 	return (error);
 }
 #endif
@@ -556,11 +580,14 @@ linux_faccessat(struct thread *td, struct linux_facces
 		return (EINVAL);
 
 	dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
-	LCONVPATHEXIST_AT(td, args->filename, &path, dfd);
+	if (!LUSECONVPATH(td)) {
+		error = kern_accessat(td, dfd, args->filename, UIO_USERSPACE, 0, args->amode);
+	} else {
+		LCONVPATHEXIST_AT(td, args->filename, &path, dfd);
+		error = kern_accessat(td, dfd, path, UIO_SYSSPACE, 0, args->amode);
+		LFREEPATH(path);
+	}
 
-	error = kern_accessat(td, dfd, path, UIO_SYSSPACE, 0, args->amode);
-	LFREEPATH(path);
-
 	return (error);
 }
 
@@ -572,18 +599,31 @@ linux_unlink(struct thread *td, struct linux_unlink_ar
 	int error;
 	struct stat st;
 
-	LCONVPATHEXIST(td, 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,
-		    NULL) == 0) {
-			if (S_ISDIR(st.st_mode))
-				error = EISDIR;
+	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_SYSSPACE, &st, NULL) == 0) {
+				if (S_ISDIR(st.st_mode))
+					error = EISDIR;
+			}
 		}
+	} else {
+		LCONVPATHEXIST(td, 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,
+			    NULL) == 0) {
+				if (S_ISDIR(st.st_mode))
+					error = EISDIR;
+			}
+		}
+		LFREEPATH(path);
 	}
-	LFREEPATH(path);
+
 	return (error);
 }
 #endif

Modified: head/sys/compat/linux/linux_mib.c
==============================================================================
--- head/sys/compat/linux/linux_mib.c	Tue Aug 18 22:03:55 2020	(r364365)
+++ head/sys/compat/linux/linux_mib.c	Tue Aug 18 22:04:22 2020	(r364366)
@@ -85,6 +85,10 @@ SYSCTL_BOOL(_compat_linux, OID_AUTO, map_sched_prio, C
     &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 int	linux_set_osname(struct thread *td, char *osname);
 static int	linux_set_osrelease(struct thread *td, char *osrelease);
 static int	linux_set_oss_version(struct thread *td, int oss_version);

Modified: head/sys/compat/linux/linux_misc.c
==============================================================================
--- head/sys/compat/linux/linux_misc.c	Tue Aug 18 22:03:55 2020	(r364365)
+++ head/sys/compat/linux/linux_misc.c	Tue Aug 18 22:04:22 2020	(r364366)
@@ -263,18 +263,23 @@ linux_uselib(struct thread *td, struct linux_uselib_ar
 	int error;
 	bool locked, opened, textset;
 
-	LCONVPATHEXIST(td, args->library, &library);
-
 	a_out = NULL;
 	vp = NULL;
 	locked = false;
 	textset = false;
 	opened = false;
 
-	NDINIT(&ni, LOOKUP, ISOPEN | FOLLOW | LOCKLEAF | AUDITVNODE1,
-	    UIO_SYSSPACE, library, td);
-	error = namei(&ni);
-	LFREEPATH(library);
+	if (!LUSECONVPATH(td)) {
+		NDINIT(&ni, LOOKUP, ISOPEN | FOLLOW | LOCKLEAF | AUDITVNODE1,
+		    UIO_USERSPACE, args->library, td);
+		error = namei(&ni);
+	} else {
+		LCONVPATHEXIST(td, args->library, &library);
+		NDINIT(&ni, LOOKUP, ISOPEN | FOLLOW | LOCKLEAF | AUDITVNODE1,
+		    UIO_SYSSPACE, library, td);
+		error = namei(&ni);
+		LFREEPATH(library);
+	}
 	if (error)
 		goto cleanup;
 
@@ -732,12 +737,16 @@ linux_utime(struct thread *td, struct linux_utime_args
 	struct l_utimbuf lut;
 	char *fname;
 	int error;
+	bool convpath;
 
-	LCONVPATHEXIST(td, args->fname, &fname);
+	convpath = LUSECONVPATH(td);
+	if (convpath)
+		LCONVPATHEXIST(td, args->fname, &fname);
 
 	if (args->times) {
 		if ((error = copyin(args->times, &lut, sizeof lut))) {
-			LFREEPATH(fname);
+			if (convpath)
+				LFREEPATH(fname);
 			return (error);
 		}
 		tv[0].tv_sec = lut.l_actime;
@@ -748,9 +757,14 @@ linux_utime(struct thread *td, struct linux_utime_args
 	} else
 		tvp = NULL;
 
-	error = kern_utimesat(td, AT_FDCWD, fname, UIO_SYSSPACE, tvp,
-	    UIO_SYSSPACE);
-	LFREEPATH(fname);
+	if (!convpath) {
+		error = kern_utimesat(td, AT_FDCWD, args->fname, UIO_USERSPACE,
+		    tvp, UIO_SYSSPACE);
+	} else {
+		error = kern_utimesat(td, AT_FDCWD, fname, UIO_SYSSPACE, tvp,
+		    UIO_SYSSPACE);
+		LFREEPATH(fname);
+	}
 	return (error);
 }
 #endif
@@ -763,8 +777,11 @@ linux_utimes(struct thread *td, struct linux_utimes_ar
 	struct timeval tv[2], *tvp = NULL;
 	char *fname;
 	int error;
+	bool convpath;
 
-	LCONVPATHEXIST(td, args->fname, &fname);
+	convpath = LUSECONVPATH(td);
+	if (convpath)
+		LCONVPATHEXIST(td, args->fname, &fname);
 
 	if (args->tptr != NULL) {
 		if ((error = copyin(args->tptr, ltv, sizeof ltv))) {
@@ -778,9 +795,14 @@ linux_utimes(struct thread *td, struct linux_utimes_ar
 		tvp = tv;
 	}
 
-	error = kern_utimesat(td, AT_FDCWD, fname, UIO_SYSSPACE,
-	    tvp, UIO_SYSSPACE);
-	LFREEPATH(fname);
+	if (!convpath) {
+		error = kern_utimesat(td, AT_FDCWD, args->fname, UIO_USERSPACE,
+		    tvp, UIO_SYSSPACE);
+	} else {
+		error = kern_utimesat(td, AT_FDCWD, fname, UIO_SYSSPACE,
+		    tvp, UIO_SYSSPACE);
+		LFREEPATH(fname);
+	}
 	return (error);
 }
 #endif
@@ -881,13 +903,17 @@ linux_futimesat(struct thread *td, struct linux_futime
 	struct timeval tv[2], *tvp = NULL;
 	char *fname;
 	int error, dfd;
+	bool convpath;
 
+	convpath = LUSECONVPATH(td);
 	dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
-	LCONVPATHEXIST_AT(td, args->filename, &fname, dfd);
+	if (convpath)
+		LCONVPATHEXIST_AT(td, args->filename, &fname, dfd);
 
 	if (args->utimes != NULL) {
 		if ((error = copyin(args->utimes, ltv, sizeof ltv))) {
-			LFREEPATH(fname);
+			if (convpath)
+				LFREEPATH(fname);
 			return (error);
 		}
 		tv[0].tv_sec = ltv[0].tv_sec;
@@ -897,8 +923,13 @@ linux_futimesat(struct thread *td, struct linux_futime
 		tvp = tv;
 	}
 
-	error = kern_utimesat(td, dfd, fname, UIO_SYSSPACE, tvp, UIO_SYSSPACE);
-	LFREEPATH(fname);
+	if (!convpath) {
+		error = kern_utimesat(td, dfd, args->filename, UIO_USERSPACE,
+		    tvp, UIO_SYSSPACE);
+	} else {
+		error = kern_utimesat(td, dfd, fname, UIO_SYSSPACE, tvp, UIO_SYSSPACE);
+		LFREEPATH(fname);
+	}
 	return (error);
 }
 #endif
@@ -1062,19 +1093,28 @@ linux_mknod(struct thread *td, struct linux_mknod_args
 {
 	char *path;
 	int error;
+	enum uio_seg seg;
+	bool convpath;
 
-	LCONVPATHCREAT(td, args->path, &path);
+	convpath = LUSECONVPATH(td);
+	if (!convpath) {
+		path = args->path;
+		seg = UIO_USERSPACE;
+	} else {
+		LCONVPATHCREAT(td, args->path, &path);
+		seg = UIO_SYSSPACE;
+	}
 
 	switch (args->mode & S_IFMT) {
 	case S_IFIFO:
 	case S_IFSOCK:
-		error = kern_mkfifoat(td, AT_FDCWD, path, UIO_SYSSPACE,
+		error = kern_mkfifoat(td, AT_FDCWD, path, seg,
 		    args->mode);
 		break;
 
 	case S_IFCHR:
 	case S_IFBLK:
-		error = kern_mknodat(td, AT_FDCWD, path, UIO_SYSSPACE,
+		error = kern_mknodat(td, AT_FDCWD, path, seg,
 		    args->mode, args->dev);
 		break;
 
@@ -1086,7 +1126,7 @@ linux_mknod(struct thread *td, struct linux_mknod_args
 		args->mode |= S_IFREG;
 		/* FALLTHROUGH */
 	case S_IFREG:
-		error = kern_openat(td, AT_FDCWD, path, UIO_SYSSPACE,
+		error = kern_openat(td, AT_FDCWD, path, seg,
 		    O_WRONLY | O_CREAT | O_TRUNC, args->mode);
 		if (error == 0)
 			kern_close(td, td->td_retval[0]);
@@ -1096,7 +1136,8 @@ linux_mknod(struct thread *td, struct linux_mknod_args
 		error = EINVAL;
 		break;
 	}
-	LFREEPATH(path);
+	if (convpath)
+		LFREEPATH(path);
 	return (error);
 }
 #endif
@@ -1106,19 +1147,29 @@ linux_mknodat(struct thread *td, struct linux_mknodat_
 {
 	char *path;
 	int error, dfd;
+	enum uio_seg seg;
+	bool convpath;
 
 	dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
-	LCONVPATHCREAT_AT(td, args->filename, &path, dfd);
 
+	convpath = LUSECONVPATH(td);
+	if (!convpath) {
+		path = __DECONST(char *, args->filename);
+		seg = UIO_USERSPACE;
+	} else {
+		LCONVPATHCREAT_AT(td, args->filename, &path, dfd);
+		seg = UIO_SYSSPACE;
+	}
+
 	switch (args->mode & S_IFMT) {
 	case S_IFIFO:
 	case S_IFSOCK:
-		error = kern_mkfifoat(td, dfd, path, UIO_SYSSPACE, args->mode);
+		error = kern_mkfifoat(td, dfd, path, seg, args->mode);
 		break;
 
 	case S_IFCHR:
 	case S_IFBLK:
-		error = kern_mknodat(td, dfd, path, UIO_SYSSPACE, args->mode,
+		error = kern_mknodat(td, dfd, path, seg, args->mode,
 		    args->dev);
 		break;
 
@@ -1130,7 +1181,7 @@ linux_mknodat(struct thread *td, struct linux_mknodat_
 		args->mode |= S_IFREG;
 		/* FALLTHROUGH */
 	case S_IFREG:
-		error = kern_openat(td, dfd, path, UIO_SYSSPACE,
+		error = kern_openat(td, dfd, path, seg,
 		    O_WRONLY | O_CREAT | O_TRUNC, args->mode);
 		if (error == 0)
 			kern_close(td, td->td_retval[0]);
@@ -1140,7 +1191,8 @@ linux_mknodat(struct thread *td, struct linux_mknodat_
 		error = EINVAL;
 		break;
 	}
-	LFREEPATH(path);
+	if (convpath)
+		LFREEPATH(path);
 	return (error);
 }
 

Modified: head/sys/compat/linux/linux_stats.c
==============================================================================
--- head/sys/compat/linux/linux_stats.c	Tue Aug 18 22:03:55 2020	(r364365)
+++ head/sys/compat/linux/linux_stats.c	Tue Aug 18 22:04:22 2020	(r364366)
@@ -89,7 +89,7 @@ translate_vnhook_major_minor(struct vnode *vp, struct 
 }
 
 static int
-linux_kern_statat(struct thread *td, int flag, int fd, char *path,
+linux_kern_statat(struct thread *td, int flag, int fd, const char *path,
     enum uio_seg pathseg, struct stat *sbp)
 {
 
@@ -99,7 +99,7 @@ linux_kern_statat(struct thread *td, int flag, int fd,
 
 #ifdef LINUX_LEGACY_SYSCALLS
 static int
-linux_kern_stat(struct thread *td, char *path, enum uio_seg pathseg,
+linux_kern_stat(struct thread *td, const char *path, enum uio_seg pathseg,
     struct stat *sbp)
 {
 
@@ -107,7 +107,7 @@ linux_kern_stat(struct thread *td, char *path, enum ui
 }
 
 static int
-linux_kern_lstat(struct thread *td, char *path, enum uio_seg pathseg,
+linux_kern_lstat(struct thread *td, const char *path, enum uio_seg pathseg,
     struct stat *sbp)
 {
 
@@ -210,10 +210,13 @@ linux_newstat(struct thread *td, struct linux_newstat_
 	char *path;
 	int error;
 
-	LCONVPATHEXIST(td, args->path, &path);
-
-	error = linux_kern_stat(td, path, UIO_SYSSPACE, &buf);
-	LFREEPATH(path);
+	if (!LUSECONVPATH(td)) {
+		error = linux_kern_stat(td, args->path, UIO_USERSPACE, &buf);
+	} else {
+		LCONVPATHEXIST(td, args->path, &path);
+		error = linux_kern_stat(td, path, UIO_SYSSPACE, &buf);
+		LFREEPATH(path);
+	}
 	if (error)
 		return (error);
 	return (newstat_copyout(&buf, args->buf));
@@ -226,10 +229,13 @@ linux_newlstat(struct thread *td, struct linux_newlsta
 	char *path;
 	int error;
 
-	LCONVPATHEXIST(td, args->path, &path);
-
-	error = linux_kern_lstat(td, path, UIO_SYSSPACE, &sb);
-	LFREEPATH(path);
+	if (!LUSECONVPATH(td)) {
+		error = linux_kern_lstat(td, args->path, UIO_USERSPACE, &sb);
+	} else {
+		LCONVPATHEXIST(td, args->path, &path);
+		error = linux_kern_lstat(td, path, UIO_SYSSPACE, &sb);
+		LFREEPATH(path);
+	}
 	if (error)
 		return (error);
 	return (newstat_copyout(&sb, args->buf));
@@ -286,14 +292,16 @@ linux_stat(struct thread *td, struct linux_stat_args *
 	char *path;
 	int error;
 
-	LCONVPATHEXIST(td, args->path, &path);
-
-	error = linux_kern_stat(td, path, UIO_SYSSPACE, &buf);
-	if (error) {
+	if (!LUSECONVPATH(td)) {
+		error = linux_kern_stat(td, args->path, UIO_USERSPACE, &buf);
+	} else {
+		LCONVPATHEXIST(td, args->path, &path);
+		error = linux_kern_stat(td, path, UIO_SYSSPACE, &buf);
 		LFREEPATH(path);
+	}
+	if (error) {
 		return (error);
 	}
-	LFREEPATH(path);
 	return (stat_copyout(&buf, args->up));
 }
 
@@ -304,14 +312,16 @@ linux_lstat(struct thread *td, struct linux_lstat_args
 	char *path;
 	int error;
 
-	LCONVPATHEXIST(td, args->path, &path);
-
-	error = linux_kern_lstat(td, path, UIO_SYSSPACE, &buf);
-	if (error) {
+	if (!LUSECONVPATH(td)) {
+		error = linux_kern_lstat(td, args->path, UIO_USERSPACE, &buf);
+	} else {
+		LCONVPATHEXIST(td, args->path, &path);
+		error = linux_kern_lstat(td, path, UIO_SYSSPACE, &buf);
 		LFREEPATH(path);
+	}
+	if (error) {
 		return (error);
 	}
-	LFREEPATH(path);
 	return (stat_copyout(&buf, args->up));
 }
 #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
@@ -413,11 +423,15 @@ linux_statfs(struct thread *td, struct linux_statfs_ar
 	char *path;
 	int error;
 
-	LCONVPATHEXIST(td, args->path, &path);
-
-	bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
-	error = kern_statfs(td, path, UIO_SYSSPACE, bsd_statfs);
-	LFREEPATH(path);
+	if (!LUSECONVPATH(td)) {
+		bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
+		error = kern_statfs(td, args->path, UIO_USERSPACE, bsd_statfs);
+	} else {
+		LCONVPATHEXIST(td, args->path, &path);
+		bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
+		error = kern_statfs(td, path, UIO_SYSSPACE, bsd_statfs);
+		LFREEPATH(path);
+	}
 	if (error == 0)
 		error = bsd_to_linux_statfs(bsd_statfs, &linux_statfs);
 	free(bsd_statfs, M_STATFS);
@@ -457,11 +471,15 @@ linux_statfs64(struct thread *td, struct linux_statfs6
 	if (args->bufsize != sizeof(struct l_statfs64))
 		return (EINVAL);
 
-	LCONVPATHEXIST(td, args->path, &path);
-
-	bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
-	error = kern_statfs(td, path, UIO_SYSSPACE, bsd_statfs);
-	LFREEPATH(path);
+	if (!LUSECONVPATH(td)) {
+		bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
+		error = kern_statfs(td, args->path, UIO_USERSPACE, bsd_statfs);
+	} else {
+		LCONVPATHEXIST(td, args->path, &path);
+		bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
+		error = kern_statfs(td, path, UIO_SYSSPACE, bsd_statfs);
+		LFREEPATH(path);
+	}
 	if (error == 0)
 		bsd_to_linux_statfs64(bsd_statfs, &linux_statfs);
 	free(bsd_statfs, M_STATFS);
@@ -568,10 +586,13 @@ linux_stat64(struct thread *td, struct linux_stat64_ar
 	char *filename;
 	int error;
 
-	LCONVPATHEXIST(td, args->filename, &filename);
-
-	error = linux_kern_stat(td, filename, UIO_SYSSPACE, &buf);
-	LFREEPATH(filename);
+	if (!LUSECONVPATH(td)) {
+		error = linux_kern_stat(td, args->filename, UIO_USERSPACE, &buf);
+	} else {
+		LCONVPATHEXIST(td, args->filename, &filename);
+		error = linux_kern_stat(td, filename, UIO_SYSSPACE, &buf);
+		LFREEPATH(filename);
+	}
 	if (error)
 		return (error);
 	return (stat64_copyout(&buf, args->statbuf));
@@ -584,10 +605,13 @@ linux_lstat64(struct thread *td, struct linux_lstat64_
 	char *filename;
 	int error;
 
-	LCONVPATHEXIST(td, args->filename, &filename);
-
-	error = linux_kern_lstat(td, filename, UIO_SYSSPACE, &sb);
-	LFREEPATH(filename);
+	if (!LUSECONVPATH(td)) {
+		error = linux_kern_lstat(td, args->filename, UIO_USERSPACE, &sb);
+	} else {
+		LCONVPATHEXIST(td, args->filename, &filename);
+		error = linux_kern_lstat(td, filename, UIO_SYSSPACE, &sb);
+		LFREEPATH(filename);
+	}
 	if (error)
 		return (error);
 	return (stat64_copyout(&sb, args->statbuf));
@@ -620,12 +644,16 @@ linux_fstatat64(struct thread *td, struct linux_fstata
 	    AT_SYMLINK_NOFOLLOW : 0;
 
 	dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
-	LCONVPATHEXIST_AT(td, args->pathname, &path, dfd);
-
-	error = linux_kern_statat(td, flag, dfd, path, UIO_SYSSPACE, &buf);
-	if (!error)
+	if (!LUSECONVPATH(td)) {
+		error = linux_kern_statat(td, flag, dfd, args->pathname,
+		    UIO_USERSPACE, &buf);
+	} else {
+		LCONVPATHEXIST_AT(td, args->pathname, &path, dfd);
+		error = linux_kern_statat(td, flag, dfd, path, UIO_SYSSPACE, &buf);
+		LFREEPATH(path);
+	}
+	if (error == 0)
 		error = stat64_copyout(&buf, args->statbuf);
-	LFREEPATH(path);
 
 	return (error);
 }
@@ -645,12 +673,16 @@ linux_newfstatat(struct thread *td, struct linux_newfs
 	    AT_SYMLINK_NOFOLLOW : 0;
 
 	dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
-	LCONVPATHEXIST_AT(td, args->pathname, &path, dfd);
-
-	error = linux_kern_statat(td, flag, dfd, path, UIO_SYSSPACE, &buf);
+	if (!LUSECONVPATH(td)) {
+		error = linux_kern_statat(td, flag, dfd, args->pathname,
+		    UIO_USERSPACE, &buf);
+	} else {
+		LCONVPATHEXIST_AT(td, args->pathname, &path, dfd);
+		error = linux_kern_statat(td, flag, dfd, path, UIO_SYSSPACE, &buf);
+		LFREEPATH(path);
+	}
 	if (error == 0)
 		error = newstat_copyout(&buf, args->statbuf);
-	LFREEPATH(path);
 
 	return (error);
 }

Modified: head/sys/compat/linux/linux_uid16.c
==============================================================================
--- head/sys/compat/linux/linux_uid16.c	Tue Aug 18 22:03:55 2020	(r364365)
+++ head/sys/compat/linux/linux_uid16.c	Tue Aug 18 22:04:22 2020	(r364366)
@@ -112,22 +112,25 @@ linux_chown16(struct thread *td, struct linux_chown16_
 	char *path;
 	int error;
 
-	LCONVPATHEXIST(td, args->path, &path);
+	if (!LUSECONVPATH(td) && !SDT_PROBES_ENABLED()) {
+		error = kern_fchownat(td, AT_FDCWD, args->path, UIO_USERSPACE,
+		    CAST_NOCHG(args->uid), CAST_NOCHG(args->gid), 0);
+	} else {
+		LCONVPATHEXIST(td, args->path, &path);
+		/*
+		 * The DTrace probes have to be after the LCONVPATHEXIST, as
+		 * LCONVPATHEXIST may return on its own and we do not want to
+		 * have a stray entry without the corresponding return.
+		 */
+		LIN_SDT_PROBE3(uid16, linux_chown16, entry, args->path, args->uid,
+		    args->gid);
+		LIN_SDT_PROBE1(uid16, linux_chown16, conv_path, path);
 
-	/*
-	 * The DTrace probes have to be after the LCONVPATHEXIST, as
-	 * LCONVPATHEXIST may return on its own and we do not want to
-	 * have a stray entry without the corresponding return.
-	 */
-	LIN_SDT_PROBE3(uid16, linux_chown16, entry, args->path, args->uid,
-	    args->gid);
-	LIN_SDT_PROBE1(uid16, linux_chown16, conv_path, path);
-
-	error = kern_fchownat(td, AT_FDCWD, path, UIO_SYSSPACE,
-	    CAST_NOCHG(args->uid), CAST_NOCHG(args->gid), 0);
-	LFREEPATH(path);
-
-	LIN_SDT_PROBE1(uid16, linux_chown16, return, error);
+		error = kern_fchownat(td, AT_FDCWD, path, UIO_SYSSPACE,
+		    CAST_NOCHG(args->uid), CAST_NOCHG(args->gid), 0);
+		LFREEPATH(path);
+		LIN_SDT_PROBE1(uid16, linux_chown16, return, error);
+	}
 	return (error);
 }
 
@@ -137,22 +140,26 @@ linux_lchown16(struct thread *td, struct linux_lchown1
 	char *path;
 	int error;
 
-	LCONVPATHEXIST(td, args->path, &path);
+	if (!LUSECONVPATH(td) && !SDT_PROBES_ENABLED()) {
+		error = kern_fchownat(td, AT_FDCWD, args->path, UIO_USERSPACE,
+		    CAST_NOCHG(args->uid), CAST_NOCHG(args->gid), AT_SYMLINK_NOFOLLOW);
+	} else {
+		LCONVPATHEXIST(td, args->path, &path);
 
-	/*
-	 * The DTrace probes have to be after the LCONVPATHEXIST, as
-	 * LCONVPATHEXIST may return on its own and we do not want to
-	 * have a stray entry without the corresponding return.
-	 */
-	LIN_SDT_PROBE3(uid16, linux_lchown16, entry, args->path, args->uid,
-	    args->gid);
-	LIN_SDT_PROBE1(uid16, linux_lchown16, conv_path, path);
+		/*
+		 * The DTrace probes have to be after the LCONVPATHEXIST, as
+		 * LCONVPATHEXIST may return on its own and we do not want to
+		 * have a stray entry without the corresponding return.
+		 */
+		LIN_SDT_PROBE3(uid16, linux_lchown16, entry, args->path, args->uid,
+		    args->gid);
+		LIN_SDT_PROBE1(uid16, linux_lchown16, conv_path, path);
 
-	error = kern_fchownat(td, AT_FDCWD, path, UIO_SYSSPACE,
-	    CAST_NOCHG(args->uid), CAST_NOCHG(args->gid), AT_SYMLINK_NOFOLLOW);
-	LFREEPATH(path);
-
-	LIN_SDT_PROBE1(uid16, linux_lchown16, return, error);
+		error = kern_fchownat(td, AT_FDCWD, path, UIO_SYSSPACE,
+		    CAST_NOCHG(args->uid), CAST_NOCHG(args->gid), AT_SYMLINK_NOFOLLOW);
+		LFREEPATH(path);
+		LIN_SDT_PROBE1(uid16, linux_lchown16, return, error);
+	}
 	return (error);
 }
 

Modified: head/sys/compat/linux/linux_util.h
==============================================================================
--- head/sys/compat/linux/linux_util.h	Tue Aug 18 22:03:55 2020	(r364365)
+++ head/sys/compat/linux/linux_util.h	Tue Aug 18 22:04:22 2020	(r364366)
@@ -51,8 +51,11 @@ MALLOC_DECLARE(M_FUTEX);
 MALLOC_DECLARE(M_FUTEX_WP);
 
 extern char linux_emul_path[];
+extern int linux_use_emul_path;
 
 int linux_emul_convpath(struct thread *, const char *, enum uio_seg, char **, int, int);
+
+#define LUSECONVPATH(td) atomic_load_int(&linux_use_emul_path)
 
 #define LCONVPATH_AT(td, upath, pathp, i, dfd)				\
 	do {								\

Modified: head/sys/i386/linux/linux_machdep.c
==============================================================================
--- head/sys/i386/linux/linux_machdep.c	Tue Aug 18 22:03:55 2020	(r364365)
+++ head/sys/i386/linux/linux_machdep.c	Tue Aug 18 22:04:22 2020	(r364366)
@@ -104,11 +104,15 @@ linux_execve(struct thread *td, struct linux_execve_ar
 	char *newpath;
 	int error;
 
-	LCONVPATHEXIST(td, args->path, &newpath);
-
-	error = exec_copyin_args(&eargs, newpath, UIO_SYSSPACE,
-	    args->argp, args->envp);
-	LFREEPATH(newpath);
+	if (!LUSECONVPATH(td)) {
+		error = exec_copyin_args(&eargs, args->path, UIO_USERSPACE,
+		    args->argp, args->envp);
+	} else {
+		LCONVPATHEXIST(td, args->path, &newpath);
+		error = exec_copyin_args(&eargs, newpath, UIO_SYSSPACE,
+		    args->argp, args->envp);
+		LFREEPATH(newpath);
+	}
 	if (error == 0)
 		error = linux_common_execve(td, &eargs);
 	return (error);


More information about the svn-src-head mailing list