Fix Flatpak installs on older Android kernels (#752)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-10-13 21:31:26 -04:00
1 parent 83ec5708ed
commit 0d0465d19e
5 files changed
+282 -1

No files matched your search

+9 -1
View File
@@ -78,8 +78,16 @@ Added by DroidDeck:
exit.c act on (`TCSETSF`, the four termios2 requests, `FICLONE`) and allows the rest at once, and
the ioctl block is emitted first (after WinNative 53836ca9, which traces only the termios2 ones).
The `faccessat2` exit stop (termux 5ba8b95, for glibc's ENOSYS fallback on kernels before 5.8) and
the `statx` one (emulation on kernels before 4.11) are dropped when the running kernel is newer.
the `statx` one (emulation on kernels before 4.11) are dropped on kernels 5.8 and newer; patch
`0015` keeps it on 4.11–5.7 to return the mount ID added in 5.8.
Host build: `ioctl` 31.6 -> 0.5 us; `stat`/`statx`/`faccessat2` about 44 -> 28 us (one stop).
- `0015-statx-mnt-id-fdinfo.patch` - kernels before 5.8 can complete `statx` without the mount ID
that libglnx requires while chasing an open descriptor. PRoot keeps the exit stop on those
kernels and fills only a missing ordinary `STATX_MNT_ID` for `AT_EMPTY_PATH` after pinning the
tracee descriptor, matching its device and inode to the successful statx result, and reading
`mnt_id` from the pin's fdinfo. A later close/reuse of the tracee fd cannot redirect that read;
a concurrent reuse for the same inode through a different bind mount is indistinguishable at
the exit stop. It does not synthesize `STATX_MNT_ID_UNIQUE`.
Prototype (inert unless `PROOT_FASTPATH` is set; see `docs/development/proot-performance.md`):
+1
View File
@@ -30,6 +30,7 @@ fetch() {
}
fetch proot.tar.gz "https://github.com/termux/proot/archive/${PROOT_COMMIT}.tar.gz" "$PROOT_SHA256"
fetch talloc.tar.gz "https://www.samba.org/ftp/talloc/talloc-${TALLOC_VERSION}.tar.gz" "$TALLOC_SHA256"
cp "$HERE/statx_mnt_id.h" "$WORK/proot/src/tracee/statx_mnt_id.h"
for patch in "$HERE"/patches/*.patch; do
patch -d "$WORK/proot" -p1 --forward --quiet < "$patch"
done
@@ -0,0 +1,44 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: DroidDeck <droiddeck@users.noreply.github.com>
Date: Tue, 13 Oct 2026 00:00:00 +0000
Subject: [PATCH] statx: supply mount IDs on kernels before 5.8
On kernels before 5.8, statx can succeed without STATX_MNT_ID. Recover it
from the already-open descriptor after verifying its identity. Keep the
compatibility exit stop only on kernels that need the missing field.
---
diff --git a/src/syscall/seccomp.c b/src/syscall/seccomp.c
index ee7b8acd68660f38fd52f56e951ffb94e9061d68..ff3a79b60e9092a296bb444c919bb3861338727f 100644
--- a/src/syscall/seccomp.c
+++ b/src/syscall/seccomp.c
@@ -738,4 +738,4 @@ int enable_syscall_filtering(const Tracee *tracee)
- * the statx one emulates the call when it fails, which only a kernel
- * before 4.11 does for want of it - a statx Android's policy traps is
- * emulated from SIGSYS instead. Both stops re-read and re-translate
- * the path, and are paid on every call.
+ * the statx one emulates the syscall before 4.11 and supplies MNT_ID
+ * from fdinfo through 5.7. Android policy traps are still emulated from
+ * SIGSYS instead. Both stops re-read and re-translate the path, and are
+ * paid on every call.
@@ -764 +764,4 @@ static void drop_unneeded_exit_stops(void)
- if (major > 4 || (major == 4 && minor >= 11))
+ /* Linux 4.11 introduced statx; Linux 5.8 added MNT_ID.
+ * Keep its exit stop through 5.7 so the missing ID can be
+ * recovered from the descriptor's fdinfo. */
+ if (major > 5 || (major == 5 && minor >= 8))
diff --git a/src/tracee/statx.c b/src/tracee/statx.c
index ca972f892e84461cb694dd13a37bfbc67527b320..824771ccf5934e1f870fc36a29fb22fdcad0a856 100644
--- a/src/tracee/statx.c
+++ b/src/tracee/statx.c
@@ -4,0 +5 @@
+#include "tracee/statx_mnt_id.h"
@@ -125,0 +127,9 @@ int handle_statx_syscall(Tracee *tracee, bool from_sigsys) {
+ /* libglnx chases an already-open fd with AT_EMPTY_PATH and requires a
+ * mount ID. Kernels before 5.8 can succeed without returning that field.
+ * The tracee is stopped at this syscall exit; accept only the ordinary
+ * mount ID and verify the fdinfo inode against the statx result. */
+ if (droiddeck_proot_statx_fill_mnt_id(tracee->pid, (int) dirfd,
+ (int) flags, guest_path, (unsigned int) mask,
+ &state.statx_buf))
+ state.updated_stats = true;
+
+95
View File
@@ -0,0 +1,95 @@
#ifndef DROIDDECK_PROOT_STATX_MNT_ID_H
#define DROIDDECK_PROOT_STATX_MNT_ID_H
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include <sys/types.h>
#include <unistd.h>
static inline bool droiddeck_proot_read_fdinfo(int fd, uint64_t *mnt_id, uint64_t *ino) {
if (fd < 0 || !mnt_id || !ino) return false;
char fdinfo_path[64];
int n = snprintf(fdinfo_path, sizeof fdinfo_path, "/proc/self/fdinfo/%d", fd);
if (n < 0 || (size_t)n >= sizeof fdinfo_path) return false;
FILE *fdinfo = fopen(fdinfo_path, "r");
if (!fdinfo) return false;
bool have_mnt_id = false, have_ino = false;
uint64_t parsed_mnt_id = 0, parsed_ino = 0;
char line[256];
while (fgets(line, sizeof line, fdinfo)) {
const char *value = NULL;
uint64_t *field = NULL;
if (strncmp(line, "mnt_id:", 7) == 0) {
value = line + 7;
field = &parsed_mnt_id;
have_mnt_id = true;
} else if (strncmp(line, "ino:", 4) == 0) {
value = line + 4;
field = &parsed_ino;
have_ino = true;
}
if (!value) continue;
errno = 0;
char *end = NULL;
unsigned long long parsed = strtoull(value, &end, 10);
if (errno || end == value || (*end && *end != '\n' && *end != '\r')) {
if (field == &parsed_mnt_id) have_mnt_id = false;
else have_ino = false;
continue;
}
*field = (uint64_t)parsed;
}
bool read_error = ferror(fdinfo);
fclose(fdinfo);
if (read_error || !have_mnt_id || !have_ino || parsed_mnt_id == 0) return false;
*mnt_id = parsed_mnt_id;
*ino = parsed_ino;
return true;
}
static inline bool droiddeck_proot_statx_fill_mnt_id(pid_t pid, int fd,
int flags, const char *path,
unsigned int mask,
struct statx *buf) {
if (fd < 0 || !(flags & AT_EMPTY_PATH) || !path || path[0] != '\0'
|| !(mask & STATX_MNT_ID) || (buf->stx_mask & STATX_MNT_ID)
|| !(buf->stx_mask & STATX_INO))
return false;
char tracee_fd_path[64];
int n = snprintf(tracee_fd_path, sizeof tracee_fd_path, "/proc/%ld/fd/%d", (long)pid, fd);
if (n < 0 || (size_t)n >= sizeof tracee_fd_path) return false;
/* Another thread sharing the tracee's fd table can close/reuse fd after statx returns. Pin the
* current referent, then require both device and inode to match statx before trusting its mount.
* Read fdinfo from our pin so a later tracee fd reuse cannot change which mount ID is observed.
* A same-inode bind-mount alias has the same device/inode pair; at this exit stop we cannot
* distinguish that rare concurrent replacement from the mount used by the completed syscall. */
int pinned = open(tracee_fd_path, O_PATH | O_CLOEXEC);
if (pinned < 0) return false;
struct stat st;
bool same = fstat(pinned, &st) == 0 && st.st_ino == buf->stx_ino &&
major(st.st_dev) == buf->stx_dev_major && minor(st.st_dev) == buf->stx_dev_minor;
uint64_t mnt_id = 0, ino = 0;
bool have_fdinfo = same && droiddeck_proot_read_fdinfo(pinned, &mnt_id, &ino);
close(pinned);
if (!have_fdinfo || ino != st.st_ino) return false;
buf->stx_mnt_id = mnt_id;
buf->stx_mask |= STATX_MNT_ID;
return true;
}
#endif