linux-user: add option to intercept execve() syscalls
PATCH v4 1/1 linux-user: add option to intercept execve() syscalls
This patch is based on the original work by Petros Angelatos [1], which I have updated to the current git master. The following commit message is largely based on Petros' original message.
In order for one to use QEMU user mode emulation under a chroot, it is required to use binfmt_misc. This can be avoided by QEMU never doing a raw execve() to the host system.
Introduce a new option, --execve, that uses the current QEMU interpreter to intercept execve().
qemu_execve() will prepend the interpreter path, similar to what binfmt_misc would do, and then pass the modified execve() to the host.
[1] https://patchwork.ozlabs.org/patch/582756/
Signed-off-by Ricardo Jesus <[email protected]>
--- linux-user/main.c | 8 +++ linux-user/qemu.h | 1 + linux-user/syscall.c | 138 +++++++++++++++++++++++++++++++++++++++---- 3 files changed, 136 insertions(+), 11 deletions(-)
linux-user/main.c +8 -0
@@ -107,6 +107,7 @@ static void usage(int exitcode);static const char *interp_prefix =CONFIG_QEMU_INTERP_PREFIX ;const char *qemu_uname_release; +const char *qemu_execve_path;/* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so we allocate a bigger stack. Need a better solution, for example
@@ -337,6 +338,11 @@ static void handle_arg_guest_base(const char *arg) have_guest_base = true; } +static void handle_arg_execve (const char *arg) +{ + qemu_execve_path =strdup (arg); +} +static void handle_arg_reserved_va (const char *arg) {char *p;
@@ -441,6 +447,8 @@ static const struct qemu_argument arg_table[] = { "uname", "set qemu uname release string to 'uname'"}, {"B" ,"QEMU_GUEST_BASE" , true, handle_arg_guest_base, "address", "set guest_base address to 'address'"}, + {"execve", "QEMU_EXECVE", true, handle_arg_execve, + "", "use this interpreter when a process calls execve()"}, {"R", "QEMU_RESERVED_VA", true, handle_arg_reserved_va, "size", "reserve 'size' bytes for guest virtual address space"}, {"d", "QEMU_LOG", true, handle_arg_log,
linux-user/qemu.h +1 -0
@@ -160,6 +160,7 @@ void init_task_state(TaskState *ts);void task_settid (TaskState *);void stop_all_tasks (void );extern const char *qemu_uname_release; +extern const char *qemu_execve_path;extern unsigned long mmap_min_addr;/* ??? See if we can avoid exposing so much of the loader internals. */
linux-user/syscall.c +127 -11
156 lines not on this page · raw message
Signature · 1 line
2.27.0