From 93393485b92d44f96cc71635de0f863f9de4ff5d Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Mon, 9 Nov 2026 13:15:54 -0500 Subject: [PATCH] fix(native): any number of session mounts, and openat2 relative to a mounted folder --- tools/nativeguest/hook/files.c | 7 +++++++ tools/nativeguest/hook/paths.c | 10 +++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/tools/nativeguest/hook/files.c b/tools/nativeguest/hook/files.c index 02117068f..b2fdb1c37 100644 --- a/tools/nativeguest/hook/files.c +++ b/tools/nativeguest/hook/files.c @@ -195,6 +195,13 @@ int openat2(int dirfd, const char *pathname, struct ddnatv_open_how *how, size_t errno = EFAULT; return -1; } + const char *given = pathname; + DDNATV_AT_REMAP(dirfd, pathname); + // a remapped path is absolute, which RESOLVE_BENEATH and the like refuse: the caller walks it itself + if (pathname != given && how && how->resolve != 0) { + errno = ENOSYS; + return -1; + } char exe_buf[PATH_MAX]; if (is_proc_self_exe(pathname)) { if (g_real_exe[0] != '\0') { diff --git a/tools/nativeguest/hook/paths.c b/tools/nativeguest/hook/paths.c index c2b50c3ee..975d108ba 100644 --- a/tools/nativeguest/hook/paths.c +++ b/tools/nativeguest/hook/paths.c @@ -22,14 +22,14 @@ static void ddnatv_set_root(const char *root, size_t len) { // Mounts that proot used to provide: "src:dst" pairs from DDNATV_BINDS ('|' separated), longest dst first. // A path under dst is read from src; src equal to dst keeps a host path that would otherwise be // looked up in the rootfs. -#define DDNATV_MAX_BINDS 128 struct ddnatv_bind { char *src, *dst; size_t src_len, dst_len; int identity; int order; // position in DDNATV_BINDS: the earlier of two mounts of one folder is its guest path }; -static struct ddnatv_bind g_binds[DDNATV_MAX_BINDS]; +// as many as the session has: a fixed table dropped what came after its 128th entry +static struct ddnatv_bind *g_binds = NULL; static int g_nbinds = 0; static char *g_binds_raw = NULL; @@ -44,7 +44,11 @@ static void ddnatv_load_binds(const char *spec) { char *copy = strdup(spec); if (!raw || !copy) { free(raw); free(copy); return; } char *save = NULL; - for (char *entry = strtok_r(copy, "|", &save); entry && g_nbinds < DDNATV_MAX_BINDS; entry = strtok_r(NULL, "|", &save)) { + size_t count = 1; + for (const char *c = spec; *c; c++) count += *c == '|'; + g_binds = calloc(count, sizeof(*g_binds)); + if (!g_binds) { free(raw); free(copy); return; } + for (char *entry = strtok_r(copy, "|", &save); entry && (size_t)g_nbinds < count; entry = strtok_r(NULL, "|", &save)) { char *colon = strchr(entry, ':'); const char *src = entry; const char *dst = colon ? colon + 1 : entry;