Add option --mixed-mode to disable mixed execution

Disable the check to see if the executable being executed
is the same ELF machine as the host system. This is to
support the case where ELF objects are run under a custom
QEMU emulator or LD_LIBRARY_PATH.

Bug: https://github.com/proot-me/proot/issues/343
This commit is contained in:
David Leonard 2023-02-13 16:09:01 +10:00 committed by Lucas Ramage
parent 6cd6da9fa4
commit 8d94d2a1a7
5 changed files with 20 additions and 2 deletions

View File

@ -184,7 +184,7 @@ care: $(OBJECTS) $(CARE_OBJECTS)
# Special case to compute which files depend on the auto-generated
# file "build.h".
USE_BUILD_H := $(patsubst $(SRC)%.c,%.o,$(shell egrep -sl 'include[[:space:]]+"build.h"' $(patsubst %.o,$(SRC)%.c,$(OBJECTS) $(CARE_OBJECTS))))
USE_BUILD_H := $(patsubst $(SRC)%.c,%.o,$(shell grep -E -sl 'include[[:space:]]+"build.h"' $(patsubst %.o,$(SRC)%.c,$(OBJECTS) $(CARE_OBJECTS))))
$(USE_BUILD_H): build.h
%.o: %.c

View File

@ -143,6 +143,12 @@ static int handle_option_q(Tracee *tracee, const Cli *cli UNUSED, const char *va
return 0;
}
static int handle_option_mixed_mode(Tracee *tracee, const Cli *cli UNUSED, const char *value UNUSED)
{
tracee->mixed_mode = value;
return 0;
}
static int handle_option_w(Tracee *tracee, const Cli *cli UNUSED, const char *value)
{
tracee->fs->cwd = talloc_strdup(tracee->fs, value);

View File

@ -51,6 +51,7 @@ static const char *recommended_su_bindings[] = {
static int handle_option_r(Tracee *tracee, const Cli *cli, const char *value);
static int handle_option_b(Tracee *tracee, const Cli *cli, const char *value);
static int handle_option_q(Tracee *tracee, const Cli *cli, const char *value);
static int handle_option_mixed_mode(Tracee *tracee, const Cli *cli, const char *value);
static int handle_option_w(Tracee *tracee, const Cli *cli, const char *value);
static int handle_option_v(Tracee *tracee, const Cli *cli, const char *value);
static int handle_option_V(Tracee *tracee, const Cli *cli, const char *value);
@ -137,6 +138,15 @@ Copyright (C) 2023 PRoot Developers, licensed under GPL v2 or later.",
\temulated by QEMU user-mode. The native execution of host programs\n\
\tis still effective and the whole host rootfs is bound to\n\
\t/host-rootfs in the guest environment.",
},
{ .class = "Regular options",
.arguments = {
{ .name = "--mixed-mode", .separator = ' ', .value = "value" },
{ .name = NULL, .separator = '\0', .value = NULL } },
.handler = handle_option_mixed_mode,
.description = "Disable the mixed-execution feature.",
.detail = "\tDo not treat ELF executables specially when they appear to be\n\
\tnative executables of the host system.",
},
{ .class = "Regular options",
.arguments = {

View File

@ -382,7 +382,7 @@ static int expand_runner(Tracee* tracee, char host_path[PATH_MAX], char user_pat
/* No need to adjust argv[] if it's a host binary (a.k.a
* mixed-mode). */
if (!is_host_elf(tracee, host_path)) {
if (tracee->mixed_mode || !is_host_elf(tracee, host_path)) {
ArrayOfXPointers *argv;
size_t nb_qemu_args;
size_t i;

View File

@ -204,6 +204,8 @@ typedef struct tracee {
* execve sysexit. */
struct load_info *load_info;
/* Disable mixed-execution (native host) check */
bool mixed_mode;
/**********************************************************************
* Private but inherited resources *