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
This commit is contained in:
parent
d5e3895ea4
commit
a125ed50a6
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=364366
@ -98,13 +98,17 @@ linux_execve(struct thread *td, struct linux_execve_args *args)
|
||||
char *path;
|
||||
int error;
|
||||
|
||||
LCONVPATHEXIST(td, args->path, &path);
|
||||
|
||||
LINUX_CTR(execve);
|
||||
|
||||
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);
|
||||
|
@ -67,11 +67,15 @@ linux_execve(struct thread *td, struct linux_execve_args *uap)
|
||||
char *path;
|
||||
int error;
|
||||
|
||||
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);
|
||||
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);
|
||||
|
@ -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 *args)
|
||||
char *path;
|
||||
int error;
|
||||
|
||||
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 *path, int l_flags, int mod
|
||||
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 *path, int l_flags, int mod
|
||||
}
|
||||
|
||||
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,11 +555,15 @@ linux_access(struct thread *td, struct linux_access_args *args)
|
||||
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(td, args->path, &path);
|
||||
|
||||
error = kern_accessat(td, AT_FDCWD, path, UIO_SYSSPACE, 0,
|
||||
args->amode);
|
||||
LFREEPATH(path);
|
||||
}
|
||||
|
||||
return (error);
|
||||
}
|
||||
@ -556,10 +580,13 @@ linux_faccessat(struct thread *td, struct linux_faccessat_args *args)
|
||||
return (EINVAL);
|
||||
|
||||
dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->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);
|
||||
}
|
||||
|
||||
return (error);
|
||||
}
|
||||
@ -572,8 +599,19 @@ linux_unlink(struct thread *td, struct linux_unlink_args *args)
|
||||
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_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 */
|
||||
@ -584,6 +622,8 @@ linux_unlink(struct thread *td, struct linux_unlink_args *args)
|
||||
}
|
||||
}
|
||||
LFREEPATH(path);
|
||||
}
|
||||
|
||||
return (error);
|
||||
}
|
||||
#endif
|
||||
|
@ -85,6 +85,10 @@ 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 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);
|
||||
|
@ -263,18 +263,23 @@ linux_uselib(struct thread *td, struct linux_uselib_args *args)
|
||||
int error;
|
||||
bool locked, opened, textset;
|
||||
|
||||
LCONVPATHEXIST(td, args->library, &library);
|
||||
|
||||
a_out = NULL;
|
||||
vp = NULL;
|
||||
locked = false;
|
||||
textset = false;
|
||||
opened = false;
|
||||
|
||||
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,11 +737,15 @@ linux_utime(struct thread *td, struct linux_utime_args *args)
|
||||
struct l_utimbuf lut;
|
||||
char *fname;
|
||||
int error;
|
||||
bool convpath;
|
||||
|
||||
convpath = LUSECONVPATH(td);
|
||||
if (convpath)
|
||||
LCONVPATHEXIST(td, args->fname, &fname);
|
||||
|
||||
if (args->times) {
|
||||
if ((error = copyin(args->times, &lut, sizeof lut))) {
|
||||
if (convpath)
|
||||
LFREEPATH(fname);
|
||||
return (error);
|
||||
}
|
||||
@ -748,9 +757,14 @@ linux_utime(struct thread *td, struct linux_utime_args *args)
|
||||
} else
|
||||
tvp = NULL;
|
||||
|
||||
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,7 +777,10 @@ linux_utimes(struct thread *td, struct linux_utimes_args *args)
|
||||
struct timeval tv[2], *tvp = NULL;
|
||||
char *fname;
|
||||
int error;
|
||||
bool convpath;
|
||||
|
||||
convpath = LUSECONVPATH(td);
|
||||
if (convpath)
|
||||
LCONVPATHEXIST(td, args->fname, &fname);
|
||||
|
||||
if (args->tptr != NULL) {
|
||||
@ -778,9 +795,14 @@ linux_utimes(struct thread *td, struct linux_utimes_args *args)
|
||||
tvp = tv;
|
||||
}
|
||||
|
||||
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,12 +903,16 @@ linux_futimesat(struct thread *td, struct linux_futimesat_args *args)
|
||||
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;
|
||||
if (convpath)
|
||||
LCONVPATHEXIST_AT(td, args->filename, &fname, dfd);
|
||||
|
||||
if (args->utimes != NULL) {
|
||||
if ((error = copyin(args->utimes, ltv, sizeof ltv))) {
|
||||
if (convpath)
|
||||
LFREEPATH(fname);
|
||||
return (error);
|
||||
}
|
||||
@ -897,8 +923,13 @@ linux_futimesat(struct thread *td, struct linux_futimesat_args *args)
|
||||
tvp = tv;
|
||||
}
|
||||
|
||||
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 *args)
|
||||
{
|
||||
char *path;
|
||||
int error;
|
||||
enum uio_seg seg;
|
||||
bool convpath;
|
||||
|
||||
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)
|
||||
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,6 +1136,7 @@ linux_mknod(struct thread *td, struct linux_mknod_args *args)
|
||||
error = EINVAL;
|
||||
break;
|
||||
}
|
||||
if (convpath)
|
||||
LFREEPATH(path);
|
||||
return (error);
|
||||
}
|
||||
@ -1106,19 +1147,29 @@ linux_mknodat(struct thread *td, struct linux_mknodat_args *args)
|
||||
{
|
||||
char *path;
|
||||
int error, dfd;
|
||||
enum uio_seg seg;
|
||||
bool convpath;
|
||||
|
||||
dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->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 *args)
|
||||
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,6 +1191,7 @@ linux_mknodat(struct thread *td, struct linux_mknodat_args *args)
|
||||
error = EINVAL;
|
||||
break;
|
||||
}
|
||||
if (convpath)
|
||||
LFREEPATH(path);
|
||||
return (error);
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ translate_vnhook_major_minor(struct vnode *vp, struct stat *sb)
|
||||
}
|
||||
|
||||
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, char *path,
|
||||
|
||||
#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 uio_seg pathseg,
|
||||
}
|
||||
|
||||
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_args *args)
|
||||
char *path;
|
||||
int 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);
|
||||
return (newstat_copyout(&buf, args->buf));
|
||||
@ -226,10 +229,13 @@ linux_newlstat(struct thread *td, struct linux_newlstat_args *args)
|
||||
char *path;
|
||||
int error;
|
||||
|
||||
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 *args)
|
||||
char *path;
|
||||
int 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);
|
||||
if (error) {
|
||||
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 *args)
|
||||
char *path;
|
||||
int 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);
|
||||
if (error) {
|
||||
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_args *args)
|
||||
char *path;
|
||||
int error;
|
||||
|
||||
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_statfs64_args *args)
|
||||
if (args->bufsize != sizeof(struct l_statfs64))
|
||||
return (EINVAL);
|
||||
|
||||
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_args *args)
|
||||
char *filename;
|
||||
int error;
|
||||
|
||||
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_args *args)
|
||||
char *filename;
|
||||
int error;
|
||||
|
||||
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_fstatat64_args *args)
|
||||
AT_SYMLINK_NOFOLLOW : 0;
|
||||
|
||||
dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
|
||||
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);
|
||||
if (!error)
|
||||
error = stat64_copyout(&buf, args->statbuf);
|
||||
LFREEPATH(path);
|
||||
}
|
||||
if (error == 0)
|
||||
error = stat64_copyout(&buf, args->statbuf);
|
||||
|
||||
return (error);
|
||||
}
|
||||
@ -645,12 +673,16 @@ linux_newfstatat(struct thread *td, struct linux_newfstatat_args *args)
|
||||
AT_SYMLINK_NOFOLLOW : 0;
|
||||
|
||||
dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
|
||||
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);
|
||||
}
|
||||
|
@ -112,8 +112,11 @@ linux_chown16(struct thread *td, struct linux_chown16_args *args)
|
||||
char *path;
|
||||
int error;
|
||||
|
||||
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
|
||||
@ -126,8 +129,8 @@ linux_chown16(struct thread *td, struct linux_chown16_args *args)
|
||||
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,6 +140,10 @@ linux_lchown16(struct thread *td, struct linux_lchown16_args *args)
|
||||
char *path;
|
||||
int error;
|
||||
|
||||
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);
|
||||
|
||||
/*
|
||||
@ -151,8 +158,8 @@ linux_lchown16(struct thread *td, struct linux_lchown16_args *args)
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -51,9 +51,12 @@ 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 { \
|
||||
int _error; \
|
||||
|
@ -104,11 +104,15 @@ linux_execve(struct thread *td, struct linux_execve_args *args)
|
||||
char *newpath;
|
||||
int error;
|
||||
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user