summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Maste <emaste@FreeBSD.org>2018-04-09 17:24:01 +0000
committerEd Maste <emaste@FreeBSD.org>2018-04-09 17:24:01 +0000
commitb267239d4b3d386418bb8d869dc59846d0dc0a58 (patch)
tree51ad1b2aece3e7a12c31310df05b22981cb0bb95
parent9a77a6435f2b88a740411f49c66b38cc451a1be6 (diff)
Notes
-rw-r--r--sys/amd64/linux/linux_sysvec.c43
-rw-r--r--sys/amd64/linux32/linux32_sysvec.c43
-rw-r--r--sys/compat/linux/linux_emul.c43
-rw-r--r--sys/compat/linux/linux_emul.h1
-rw-r--r--sys/i386/linux/linux_sysvec.c43
5 files changed, 44 insertions, 129 deletions
diff --git a/sys/amd64/linux/linux_sysvec.c b/sys/amd64/linux/linux_sysvec.c
index be6bc57a59cf1..7a1122494ffdd 100644
--- a/sys/amd64/linux/linux_sysvec.c
+++ b/sys/amd64/linux/linux_sysvec.c
@@ -86,12 +86,6 @@ __FBSDID("$FreeBSD$");
MODULE_VERSION(linux64, 1);
-#if BYTE_ORDER == LITTLE_ENDIAN
-#define SHELLMAGIC 0x2123 /* #! */
-#else
-#define SHELLMAGIC 0x2321
-#endif
-
#if defined(DEBUG)
SYSCTL_PROC(_compat_linux, OID_AUTO, debug,
CTLTYPE_STRING | CTLFLAG_RW,
@@ -125,7 +119,6 @@ static void linux_vdso_install(void *param);
static void linux_vdso_deinstall(void *param);
static void linux_set_syscall_retval(struct thread *td, int error);
static int linux_fetch_syscall_args(struct thread *td);
-static int linux_exec_imgact_try(struct image_params *iparams);
static void linux_exec_setregs(struct thread *td, struct image_params *imgp,
u_long stack);
static int linux_vsyscall(struct thread *td);
@@ -663,42 +656,6 @@ linux_rt_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
mtx_lock(&psp->ps_mtx);
}
-/*
- * 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.
- */
-static 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 then
- * 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(FIRST_THREAD_IN_PROC(imgp->proc),
- imgp->interpreter_name, UIO_SYSSPACE, &rpath, 0,
- AT_FDCWD);
- if (rpath != NULL)
- imgp->args->fname_buf =
- imgp->interpreter_name = rpath;
- }
- }
- return (error);
-}
-
#define LINUX_VSYSCALL_START (-10UL << 20)
#define LINUX_VSYSCALL_SZ 1024
diff --git a/sys/amd64/linux32/linux32_sysvec.c b/sys/amd64/linux32/linux32_sysvec.c
index b32d165ce8663..a7d31c3acc193 100644
--- a/sys/amd64/linux32/linux32_sysvec.c
+++ b/sys/amd64/linux32/linux32_sysvec.c
@@ -95,12 +95,6 @@ MODULE_VERSION(linux, 1);
suword32(pos++, val); \
} while (0)
-#if BYTE_ORDER == LITTLE_ENDIAN
-#define SHELLMAGIC 0x2123 /* #! */
-#else
-#define SHELLMAGIC 0x2321
-#endif
-
/*
* Allow the sendsig functions to use the ldebug() facility even though they
* are not syscalls themselves. Map them to syscall 0. This is slightly less
@@ -124,7 +118,6 @@ static int linux_fixup_elf(register_t **stack_base,
struct image_params *iparams);
static register_t *linux_copyout_strings(struct image_params *imgp);
static void linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask);
-static int linux_exec_imgact_try(struct image_params *iparams);
static void linux_exec_setregs(struct thread *td,
struct image_params *imgp, u_long stack);
static void linux32_fixlimit(struct rlimit *rl, int which);
@@ -718,42 +711,6 @@ linux32_fetch_syscall_args(struct thread *td)
}
/*
- * 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.
- */
-static 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 then
- * 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(FIRST_THREAD_IN_PROC(imgp->proc),
- imgp->interpreter_name, UIO_SYSSPACE, &rpath, 0,
- AT_FDCWD);
- if (rpath != NULL)
- imgp->args->fname_buf =
- imgp->interpreter_name = rpath;
- }
- }
- return (error);
-}
-
-/*
* Clear registers on exec
* XXX copied from ia32_signal.c.
*/
diff --git a/sys/compat/linux/linux_emul.c b/sys/compat/linux/linux_emul.c
index 2e78b5417425a..b30fb09b86bfe 100644
--- a/sys/compat/linux/linux_emul.c
+++ b/sys/compat/linux/linux_emul.c
@@ -1,6 +1,7 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
+ * Copyright (c) 1994-1996 Søren Schmidt
* Copyright (c) 2006 Roman Divacky
* Copyright (c) 2013 Dmitry Chagin
* All rights reserved.
@@ -32,6 +33,7 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/systm.h>
+#include <sys/fcntl.h>
#include <sys/imgact.h>
#include <sys/kernel.h>
#include <sys/ktr.h>
@@ -48,6 +50,11 @@ __FBSDID("$FreeBSD$");
#include <compat/linux/linux_persona.h>
#include <compat/linux/linux_util.h>
+#if BYTE_ORDER == LITTLE_ENDIAN
+#define SHELLMAGIC 0x2123 /* #! */
+#else
+#define SHELLMAGIC 0x2321
+#endif
/*
* This returns reference to the thread emuldata entry (if found)
@@ -168,6 +175,42 @@ linux_proc_exit(void *arg __unused, 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(FIRST_THREAD_IN_PROC(imgp->proc),
+ 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)
{
diff --git a/sys/compat/linux/linux_emul.h b/sys/compat/linux/linux_emul.h
index 7764c6ac52e42..3784d6a061a35 100644
--- a/sys/compat/linux/linux_emul.h
+++ b/sys/compat/linux/linux_emul.h
@@ -49,6 +49,7 @@ 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 *, int);
void linux_proc_exit(void *, struct proc *);
void linux_schedtail(struct thread *);
diff --git a/sys/i386/linux/linux_sysvec.c b/sys/i386/linux/linux_sysvec.c
index 93f21911306d2..ecf9e2c6314b4 100644
--- a/sys/i386/linux/linux_sysvec.c
+++ b/sys/i386/linux/linux_sysvec.c
@@ -77,12 +77,6 @@ __FBSDID("$FreeBSD$");
MODULE_VERSION(linux, 1);
-#if BYTE_ORDER == LITTLE_ENDIAN
-#define SHELLMAGIC 0x2123 /* #! */
-#else
-#define SHELLMAGIC 0x2321
-#endif
-
#if defined(DEBUG)
SYSCTL_PROC(_compat_linux, OID_AUTO, debug, CTLTYPE_STRING | CTLFLAG_RW, 0, 0,
linux_sysctl_debug, "A", "Linux debugging control");
@@ -113,7 +107,6 @@ static int linux_fixup(register_t **stack_base,
static int linux_fixup_elf(register_t **stack_base,
struct image_params *iparams);
static void linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask);
-static int linux_exec_imgact_try(struct image_params *iparams);
static void linux_exec_setregs(struct thread *td,
struct image_params *imgp, u_long stack);
static register_t *linux_copyout_strings(struct image_params *imgp);
@@ -816,42 +809,6 @@ linux_fetch_syscall_args(struct thread *td)
}
/*
- * 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.
- */
-static 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 then
- * 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(FIRST_THREAD_IN_PROC(imgp->proc),
- imgp->interpreter_name, UIO_SYSSPACE, &rpath, 0,
- AT_FDCWD);
- if (rpath != NULL)
- imgp->args->fname_buf =
- imgp->interpreter_name = rpath;
- }
- }
- return (error);
-}
-
-/*
* exec_setregs may initialize some registers differently than Linux
* does, thus potentially confusing Linux binaries. If necessary, we
* override the exec_setregs default(s) here.