mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-25 07:46:01 +00:00
fix(flatpak): find sandbox sources named by their kernel path when the session runs without proot (#3059)
Co-authored-by: maxjivi05 <maxjividen@gmail.com>
This commit is contained in:
1 parent
c298da6f60
commit
5f8655b13e
2 files changed
+38
-2
No files matched your search
@@ -112,9 +112,16 @@ object BwrapSpawner {
|
||||
return out
|
||||
}
|
||||
|
||||
internal fun withKernelPaths(sessionBinds: List<Bind>, canonical: (String) -> String): List<Bind> =
|
||||
sessionBinds + sessionBinds.filter { it.host == it.guest }.mapNotNull { bind ->
|
||||
runCatching { canonical(bind.host) }.getOrNull()
|
||||
?.takeIf { it != bind.guest && sessionBinds.none { other -> other.guest == it } }
|
||||
?.let { Bind(bind.host, it) }
|
||||
}
|
||||
|
||||
internal fun plan(context: Context, request: JSONObject, dir: File): Plan {
|
||||
val rootfs = LinuxRuntime.rootDir(context).path
|
||||
val session = LinuxRuntime.lastBinds(context).map { Bind.parse(it) }
|
||||
val session = withKernelPaths(LinuxRuntime.lastBinds(context).map { Bind.parse(it) }) { File(it).canonicalPath }
|
||||
val root = File(dir, "root").apply { mkdirs() }
|
||||
val binds = ArrayList<Bind>()
|
||||
var scratch = 0
|
||||
@@ -537,6 +544,9 @@ object BwrapSpawner {
|
||||
return f
|
||||
}
|
||||
|
||||
internal fun prootEnvironment(plan: Plan, startsThroughEnvTool: Boolean): Map<String, String> =
|
||||
if (startsThroughEnvTool) emptyMap() else plan.env - "LD_PRELOAD"
|
||||
|
||||
private fun run(context: Context, plan: Plan, client: LocalSocket, out: DataOutputStream, id: Int) {
|
||||
val verbose = plan.env["DROIDDECK_PROOT_VERBOSE"]?.toIntOrNull()
|
||||
val native = if (NativeGuest.forSession(context)) nativeLaunch(context, plan) else null
|
||||
@@ -558,7 +568,7 @@ object BwrapSpawner {
|
||||
ProcessBuilder(cmd).redirectErrorStream(true).directory(plan.root).also { b ->
|
||||
b.environment().apply {
|
||||
clear()
|
||||
if (!envTool) putAll(plan.env)
|
||||
putAll(prootEnvironment(plan, envTool))
|
||||
put("PROOT_LOADER", LinuxRuntime.prootLoader(context).path)
|
||||
put("PROOT_TMP_DIR", LinuxRuntime.prootTempDir(context).path)
|
||||
if (SessionPrefs.prootNoSeccomp(context)) put("PROOT_NO_SECCOMP", "1")
|
||||
|
||||
@@ -75,6 +75,32 @@ class BwrapSpawnerTest {
|
||||
assertEquals("x11", x11["SDL_VIDEODRIVER"])
|
||||
}
|
||||
|
||||
@Test fun sourcesNamedByTheirKernelPathReachTheSessionsMounts() {
|
||||
val files = "/data/user/0/com.droiddeck.launcher/files"
|
||||
val kernel = "/data/data/com.droiddeck.launcher/files"
|
||||
val binds = session + Bind(files, files)
|
||||
val aliased = BwrapSpawner.withKernelPaths(binds) { it.replace("/data/user/0/", "/data/data/") }
|
||||
val runtime = "/linuxfs/root/.local/share/flatpak/runtime/org.example.Platform/aarch64/1/abc/files"
|
||||
assertEquals("$files$runtime", BwrapSpawner.hostPath(aliased, "$files/linuxfs", "$kernel$runtime"))
|
||||
assertEquals("$files$runtime", BwrapSpawner.hostPath(aliased, "$files/linuxfs", "$files$runtime"))
|
||||
assertEquals("$files/linuxfs/usr/bin/env", BwrapSpawner.hostPath(aliased, "$files/linuxfs", "/usr/bin/env"))
|
||||
}
|
||||
|
||||
@Test fun kernelPathsLeaveOtherMountsAlone() {
|
||||
assertEquals(session, BwrapSpawner.withKernelPaths(session) { it })
|
||||
val renamed = listOf(Bind("/data/user/0/x", "/mnt/x"), Bind("/data/user/0/y", "/data/user/0/y"), Bind("/elsewhere", "/data/data/y"))
|
||||
assertEquals(renamed, BwrapSpawner.withKernelPaths(renamed) { it.replace("/data/user/0/", "/data/data/") })
|
||||
assertEquals(session, BwrapSpawner.withKernelPaths(session) { throw java.io.IOException(it) })
|
||||
}
|
||||
|
||||
@Test fun prootGetsNoGuestPreloadOfItsOwn() {
|
||||
val plan = BwrapSpawner.Plan(File("/sandbox"), emptyList(), "/", listOf("/app/bin/apply_extra"),
|
||||
mapOf("LD_PRELOAD" to "/run/droiddeck-preload/libddsession.so", "FLATPAK_ID" to "org.example.Ext"))
|
||||
assertEquals(mapOf("FLATPAK_ID" to "org.example.Ext"), BwrapSpawner.prootEnvironment(plan, false))
|
||||
assertTrue(BwrapSpawner.prootEnvironment(plan, true).isEmpty())
|
||||
assertEquals("/run/droiddeck-preload/libddsession.so", plan.env["LD_PRELOAD"])
|
||||
}
|
||||
|
||||
@Test fun normalizeResolvesDotsLexically() {
|
||||
assertEquals("/usr/lib/x", BwrapSpawner.normalize("/usr/lib/GL/../x"))
|
||||
assertEquals("/", BwrapSpawner.normalize("/../.."))
|
||||
|
||||
Reference in new issue
Block a user