fix(nativeguest): a script interpreter reached through a bind runs as a guest program (#3112)

* fix(nativeguest): a script interpreter reached through a bind runs as a guest program

A Flatpak runtime binds its own /usr outside the sandbox root, so the hook
took #!/usr/bin/bash there for an Android program and handed it to the
kernel, which failed with "bad interpreter". An interpreter whose guest
path is a bind now starts like any guest program.

* Native hook: keep Android interpreters a bind reaches on the host

* Native hook: match the root of an interpreter on a folder boundary
This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-11-23 23:42:04 -05:00
1 parent 5f2699e56b
commit e349d2544e
3 files changed
+50 -7

No files matched your search

+2 -2
View File
@@ -476,7 +476,7 @@ static int ddnatv_execve(const char *filename, char *const argv[], char *const e
return -1;
}
int ret;
if (is_host_interpreter(rewritten_interp)) {
if (is_host_interpreter(interp, rewritten_interp)) {
char **sys_env = clean_env_for_system(envp);
ret = run_execve(orig_execve, rewritten_interp, new_argv, sys_env);
int saved_errno = errno;
@@ -829,7 +829,7 @@ static int spawn_script(pid_t *pid, const char *script, struct exec_probe *probe
char **new_argv = build_script_argv(rewritten_interp, interp_arg, script, argv);
if (!new_argv) return ENOMEM;
int ret;
if (is_host_interpreter(rewritten_interp)) {
if (is_host_interpreter(interp, rewritten_interp)) {
orig_posix_spawn_f_type orig_posix_spawn = real_posix_spawn();
char **sys_env = clean_env_for_system(envp);
ret = orig_posix_spawn ? orig_posix_spawn(pid, rewritten_interp, file_actions, attrp, new_argv, sys_env) : ENOSYS;
+8 -4
View File
@@ -966,10 +966,14 @@ static void parse_shebang(char *hdr, char **interp, char **interp_arg) {
*interp_arg = arg;
}
// Interpreters outside the rootfs (Android's /system/bin/sh) run with Android's environment.
static int is_host_interpreter(const char *interp) {
return strncmp(interp, "/system", 7) == 0 ||
(g_ddnatv_root[0] != '\0' && strncmp(interp, g_ddnatv_root, g_ddnatv_root_len) != 0);
// Interpreters outside the rootfs and its binds (Android's /system/bin/sh) run with Android's environment.
static int is_host_interpreter(const char *interp, const char *rewritten) {
if (strncmp(rewritten, "/system", 7) == 0) return 1;
if (g_ddnatv_root[0] == '\0' || get_rootfs_subpath(rewritten)) return 0;
if (!is_mapped_guest_path(interp)) return 1;
struct exec_probe probe;
probe_exec_file(rewritten, &probe);
return probe.android_interp;
}
// argv for running `script` with its interpreter: interp [arg] script args... (the script's own