From 8cf1e60cc2672782c2f85f9bc6bbf0e7d4d89946 Mon Sep 17 00:00:00 2001 From: FryMcNugget Date: Thu, 3 Dec 2026 03:22:52 +0000 Subject: [PATCH] fix(runtime): thermal zone binds no longer leak into the stand-in for PCI devices (#3595) --- .../droiddeck/launcher/runtime/LegacyNames.kt | 33 ++++++++++++++++++- .../launcher/runtime/LinuxRuntime.java | 2 +- .../launcher/runtime/LegacyNamesTest.kt | 31 +++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/LegacyNames.kt b/app/src/main/java/com/droiddeck/launcher/runtime/LegacyNames.kt index 3f4589ae13..8008cf82ed 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/LegacyNames.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/LegacyNames.kt @@ -35,9 +35,40 @@ object LegacyNames { @Synchronized fun migrateEtc(root: File) { for ((old, new) in LINKED_DIRS) moveAndLink(File(root, old), File(root, new)) - File(root, "etc/droiddeck/empty").mkdirs() + clearEmptyStandIn(root) + File(root, NO_THERMAL).mkdirs() } + /** + * It stands in for /sys/bus/pci/devices, and libpci exits the whole process on an entry it cannot + * parse; older builds let thermal bind mount points leak into it. The guest can write here, so a + * link is never followed: one in place of the folder is removed, and one above it stops the cleanup. + */ + private fun clearEmptyStandIn(root: File) { + val linkedAbove = listOf("etc", "etc/droiddeck").firstOrNull { Files.isSymbolicLink(File(root, it).toPath()) } + if (linkedAbove != null) { + Log.w(TAG, "not clearing the empty stand-in: $linkedAbove is a link") + return + } + val empty = File(root, "etc/droiddeck/empty") + if (Files.isSymbolicLink(empty.toPath())) runCatching { Files.delete(empty.toPath()) } + .onFailure { Log.w(TAG, "could not remove the link at $empty", it); return } + empty.mkdirs() + empty.listFiles()?.forEach { entry -> + runCatching { deleteWithoutFollowing(entry.toPath()) }.onFailure { Log.w(TAG, "could not clear $entry", it) } + } + } + + private fun deleteWithoutFollowing(path: java.nio.file.Path) { + if (Files.isDirectory(path, java.nio.file.LinkOption.NOFOLLOW_LINKS)) { + Files.newDirectoryStream(path).use { entries -> entries.forEach(::deleteWithoutFollowing) } + } + Files.deleteIfExists(path) + } + + /** Stands in for a /sys/class/thermal the kernel won't list; proot adds the bound zones' mount points to it. */ + const val NO_THERMAL = "etc/droiddeck/no-thermal" + @Synchronized fun migrateRootfs(root: File) { migrateEtc(root) diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java b/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java index 142d4e90bc..327e7fc1ea 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java +++ b/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java @@ -248,7 +248,7 @@ public final class LinuxRuntime { // A kernel that refuses to list /sys/class/thermal (Pixel 10, Android 17) made mangoapp abort // at start ("filesystem_error ... Permission denied: '/sys/class/thermal/'") until its // wrapper gave up: it lists the directory for CPU temperatures. Empty there instead. - if (new File("/sys/class/thermal").list() == null) bind(cmd, new File(root, "etc/droiddeck/empty").getPath() + ":/sys/class/thermal"); + if (new File("/sys/class/thermal").list() == null) bind(cmd, new File(root, LegacyNames.NO_THERMAL).getPath() + ":/sys/class/thermal"); bind(cmd, context.getFilesDir().getPath()); bind(cmd, context.getCacheDir().getPath()); bind(cmd, liveDir(context).getPath()); diff --git a/app/src/test/java/com/droiddeck/launcher/runtime/LegacyNamesTest.kt b/app/src/test/java/com/droiddeck/launcher/runtime/LegacyNamesTest.kt index 027ed9359b..bb9d5e4671 100644 --- a/app/src/test/java/com/droiddeck/launcher/runtime/LegacyNamesTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/runtime/LegacyNamesTest.kt @@ -35,6 +35,37 @@ class LegacyNamesTest { assertEquals("droiddeck", link("etc/bannerlator")) } + @Test fun theEmptyStandInIsEmptiedAndThermalZonesGetTheirOwn() { + write("etc/droiddeck/empty/thermal_zone26/temp", "") + LegacyNames.migrateEtc(root) + assertEquals(emptyList(), File(root, "etc/droiddeck/empty").list()!!.toList()) + assertTrue(File(root, LegacyNames.NO_THERMAL).isDirectory) + } + + @Test fun clearingTheEmptyStandInRemovesLinksWithoutTouchingWhatTheyPointAt() { + write("home/keep/file", "kept") + val links = File(root, "etc/droiddeck/empty").apply { mkdirs() } + val made = runCatching { + Files.createSymbolicLink(File(links, "dir").toPath(), File(root, "home/keep").toPath()) + Files.createSymbolicLink(File(links, "dangling").toPath(), File(root, "missing").toPath()) + }.isSuccess + org.junit.Assume.assumeTrue("this file system cannot make symbolic links", made) + LegacyNames.migrateEtc(root) + assertEquals(emptyList(), links.list()!!.toList()) + assertEquals("kept", File(root, "home/keep/file").readText()) + } + + @Test fun aLinkInPlaceOfTheEmptyStandInIsReplacedWithoutTouchingItsTarget() { + write("home/keep/file", "kept") + val empty = File(root, "etc/droiddeck/empty").also { it.parentFile!!.mkdirs() } + val made = runCatching { Files.createSymbolicLink(empty.toPath(), File(root, "home/keep").toPath()) }.isSuccess + org.junit.Assume.assumeTrue("this file system cannot make symbolic links", made) + LegacyNames.migrateEtc(root) + assertFalse(Files.isSymbolicLink(empty.toPath())) + assertEquals(emptyList(), empty.list()!!.toList()) + assertEquals("kept", File(root, "home/keep/file").readText()) + } + @Test fun aFreshRuntimeGetsNoOldNames() { write("usr/local/bin/droiddeck-session", "new") LegacyNames.migrateRootfs(root)