From 85763544549f88df04a1fc0cf12d88873a4096d9 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Mon, 9 Nov 2026 12:26:37 -0500 Subject: [PATCH] fix(native): drive links into identity mounts stay, and relink and seccomp patch failures are logged --- .../droiddeck/launcher/runtime/NativeGuest.kt | 30 +++++++++++++++---- .../launcher/runtime/NativeGuestTest.kt | 13 ++++++++ 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/NativeGuest.kt b/app/src/main/java/com/droiddeck/launcher/runtime/NativeGuest.kt index 06d162b6ee..a221f1605b 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/NativeGuest.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/NativeGuest.kt @@ -11,6 +11,7 @@ import java.nio.file.Files * calls Android's seccomp policy blocks, from inside the process. */ object NativeGuest { + private const val TAG = "NativeGuest" const val HOOK = "usr/lib/libddnatv-hook.so" private val LIB_DIRS = listOf("usr/lib", "usr/lib/aarch64-linux-gnu", "usr/local/lib", "usr/lib/systemd") @@ -100,7 +101,12 @@ object NativeGuest { listOf("usr/lib/ld-linux-aarch64.so.1", "usr/lib/aarch64-linux-gnu/ld-linux-aarch64.so.1", "usr/lib/aarch64-linux-gnu/libc.so.6", "usr/lib/libc.so.6") .map { File(root, it) }.filter { it.exists() } - .distinctBy { it.canonicalPath }.sumOf { runCatching { ElfSeccompPatch.patchFile(it) }.getOrDefault(0) } + .distinctBy { it.canonicalPath }.sumOf { file -> + runCatching { ElfSeccompPatch.patchFile(file) }.getOrElse { + android.util.Log.e(TAG, "native userland: could not patch $file for Android's seccomp filter; programs will die with SIGSYS", it) + 0 + } + } private val HOST_LINK_TARGETS = listOf("/proc", "/dev", "/sys", "/sdcard", "/storage", "/data", "/system", "/vendor", "/apex", "/system_ext", "/product", "/odm", "/linkerconfig", "/mnt") @@ -149,11 +155,13 @@ object NativeGuest { if (!target.startsWith("/") || target == root || target.startsWith("$root/")) return null val mounts = binds.mapNotNull { spec -> val colon = spec.indexOf(':') - if (colon <= 0) null else spec.substring(0, colon).trimEnd('/') to spec.substring(colon + 1).trimEnd('/') - }.filter { (src, dst) -> src != dst && dst.isNotEmpty() } - if (mounts.any { (src, _) -> target == src || target.startsWith("$src/") }) return null + val src = (if (colon < 0) spec else spec.substring(0, colon)).trimEnd('/') + val dst = (if (colon < 0) spec else spec.substring(colon + 1)).trimEnd('/') + if (src.isEmpty() || dst.isEmpty()) null else src to dst + } + if (mounts.any { (src, dst) -> src != dst && (target == src || target.startsWith("$src/")) }) return null mounts.filter { (_, dst) -> target == dst || target.startsWith("$dst/") }.maxByOrNull { it.second.length } - ?.let { (src, dst) -> return src + target.removePrefix(dst) } + ?.let { (src, dst) -> return if (src == dst) null else src + target.removePrefix(dst) } if (HOST_LINK_TARGETS.any { target == it || target.startsWith("$it/") }) return null return root + if (target == "/") "" else target } @@ -172,7 +180,17 @@ object NativeGuest { var rewritten = 0 for (prefix in compatdata.distinct().flatMap { it.listFiles()?.toList().orEmpty() }) { val devices = File(prefix, "pfx/dosdevices").toPath() - val links = try { Files.newDirectoryStream(devices).use { it.toList() } } catch (_: java.io.IOException) { continue } + val links = try { + Files.newDirectoryStream(devices).use { it.toList() } + } catch (e: java.nio.file.NoSuchFileException) { + continue + } catch (e: java.io.IOException) { + android.util.Log.w(TAG, "native userland: could not read the drive links of $prefix", e) + continue + } catch (e: java.nio.file.DirectoryIteratorException) { + android.util.Log.w(TAG, "native userland: could not read the drive links of $prefix", e) + continue + } for (link in links) { try { if (!Files.isSymbolicLink(link)) continue diff --git a/app/src/test/java/com/droiddeck/launcher/runtime/NativeGuestTest.kt b/app/src/test/java/com/droiddeck/launcher/runtime/NativeGuestTest.kt index 6d10b9afd2..235b94d98d 100644 --- a/app/src/test/java/com/droiddeck/launcher/runtime/NativeGuestTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/runtime/NativeGuestTest.kt @@ -55,4 +55,17 @@ class NativeGuestTest { assertEquals(null, NativeGuest.hostLinkTarget("/storage/emulated/0/Games", linkRoot, sdBinds)) assertEquals(null, NativeGuest.hostLinkTarget("../drive_c", linkRoot, sdBinds)) } + + @Test + fun aLinkIntoAnIdentityMountStaysAsItIs() { + val binds = sdBinds + listOf("/odd/place:/odd/place", "/bare/mount") + assertEquals(null, NativeGuest.hostLinkTarget("/odd/place/games", linkRoot, binds)) + assertEquals(null, NativeGuest.hostLinkTarget("/bare/mount", linkRoot, binds)) + } + + @Test + fun aMountInsideAnIdentityMountStillMapsItsPaths() { + val binds = listOf("/odd/place", "/real/sd:/odd/place/sd") + assertEquals("/real/sd/x", NativeGuest.hostLinkTarget("/odd/place/sd/x", linkRoot, binds)) + } }