feat: fuck proot and proots mama (#2300)

* feat: experimental native userland that runs the Linux side without proot

* fix(native): keep the visible name of link2symlink binaries

* fix(ci): run the native hook build through bash

* fix(native): address review findings in the hook and the ctl fallback

* fix(ctl): use the broadcast fallback only when content is missing

* fix(native): survive Android's seccomp filter in ld.so, libc and posix_spawn children

* docs(native): how to test under Android's seccomp filter

* fix(session): hide an unlistable /sys/bus/pci/devices so libpci does not abort Chromium's GPU init

* fix(native): nested syscall() redirects no longer loop with libblsession's openat2

* fix(native): controllers reach Steam and the install-script evaluator no longer blocks game moves

* fix(native): write the hook's NUL character literals as escapes

* fix(native): proot fast path turns off and greys out while running without proot

* fix(native): D-Bus logins work and Xwayland still admits root once peers read as root

* fix(native): scripts on session mounts outside the rootfs run with the rootfs shell

* fix(native): games on the SD card library start in their own folder

* fix(native): Wine drive links proot made point at their real places

* fix(native): at-calls, uid lookups and relative programs follow the session's mounts

* fix(native): close-from in spawned programs covers what is open at the spawn

* fix(native): service names resolve and the DNS fallback answers what was asked

* build(native): the hook is built with its Go support and tracked by the preload recipe

* fix(native): drive links into identity mounts stay, and relink and seccomp patch failures are logged

* fix(native): seccomp-sim's filter holds every allowed call

* fix(ctl): the broadcast fallback only stands in for a missing content command

* fix(native): pre-2.33 glibc stat calls present owners as root too

* fix(native): res_init and res_ninit call glibc, so Steam's store resolves names

* fix(ci): a preload lock older than a new output rebuilds that group, and generated headers are not hashed

* fix(native): a second seccomp patch run leaves other system calls alone

* fix(native): the terminal and bottom desktop keep proot's environment in a native session

* fix(native): any number of session mounts, and openat2 relative to a mounted folder

* fix(agent): a native command's stdin is written beside its timeout

* fix(ctl): native rejects --env without = and timeouts outside 0-600 s

* fix(native): the resolver fallback has the network's IPv6 servers, and lookups keep the fallback's validation errors

* fix(native): a spawn whose dup2 source close-from closed fails with EBADF

* fix(native): __getcwd_chk checks its buffer, and seccomp-sim -a takes only call numbers

* feat(native): guests see the session hostname from uname and gethostname

* feat(native): the terminal and bottom desktop run without proot

* fix(components): an origin APK without a newer preload output still proves the rest

* fix(native): seccomp-sim -a rejects empty fields

* fix(native): gethostbyname no longer answers failed lookups with Ubuntu and Debian addresses

* feat(native): store installers, root helpers, Comet and Xodus run without proot

* fix(native): the hook finds libraries, preloads and itself through a sandbox's mounts, and ldconfig -C makes its cache

* feat(native): Flatpak sandboxes run without proot, and apply_extra runs without a runtime

* fix(native): remove, glob and nftw take guest paths, and links in a mount are followed as the guest sees them

* fix(native): Flatpak sandboxes get the session's mounts, their libraries' RUNPATHs, and no rootfs-only settings

* fix(native): gethostbyname asks the network's DNS servers, nftw of / gives single slashes, and the library path fits mapped directories

* fix(native): a native process starts in its working directory's real place

* fix(native): the library path given to ld.so holds whole directories only

* fix(native): Wine drive links keep their guest paths, so proot finds the library after a native session

* fix(native): droiddeckctl native prepares the rootfs with the setting off

* fix(native): a SysV segment stays while any process has it attached

* fix(native): DNS lookups ask the network's own servers before public ones

* fix(native): a program's own seccomp traps reach its own SIGSYS handler

* feat(native): run native sessions under a device's own app seccomp filter for testing

* fix(native): SysV attaches and collection take a lock, a failed mark fails the attach, and collection closes its directory

* fix(native): shmat fails when it cannot take the segment lock

* fix(native): the SysV segment lock is retried when a signal interrupts it

* fix(native): process tools see the session's processes as root's

* fix(native): native processes are named after their program, not ld.so

* fix(native): a session's helpers keep the mode the session started in

* fix(native): a keyed SysV segment stays until IPC_RMID

* fix(native): a rootfs link to an absolute guest path is followed in the guest, so Wine finds its z: drive

* fix(native): a sandbox whose loader can't be patched runs under proot

* fix(native): creating a private SysV segment also collects stale ones

* fix(native): a session stopped during startup forgets its mode

* fix(xbox): a native backend is authorized by its process ancestry

* fix(native): Wine's drive links are followed in the guest from any prefix

* fix(native): only the startup that owns the running session publishes its mode

* fix(native): a SysV segment stays until IPC_RMID even after its maker ends

* fix(native): a sandbox mount nested in another mount gets its own place

* fix(native): a sandbox whose mount places can't be made runs under proot
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-11 09:13:17 -05:00
1 parent b1a410ccd2
commit 2848484a99
67 files changed
+13157 -113

No files matched your search

@@ -55,6 +55,26 @@ class BwrapSpawnerTest {
assertTrue(Bind("/rootfs/etc/droiddeck/proc/stat", "/newproc/stat") in binds)
}
@Test fun theSessionsRootfsSettingsStayOutOfTheSandbox() {
val rootfs = "/data/app/linuxfs"
val env = mutableMapOf(
"DDNATV_ROOT" to rootfs, "DDNATV_BINDS" to "/dev:/dev", "HOME" to "/root",
"SPA_PLUGIN_DIR" to "/usr/local/lib/droiddeck-pipewire/lib/spa-0.2",
"LD_PRELOAD" to "/run/droiddeck-preload/libblsession.so:$rootfs/usr/local/lib/libblsession.so:$rootfs/usr/lib/libddnatv-hook.so",
)
BwrapSpawner.withoutRootfsSettings(env, rootfs)
assertEquals(mapOf("HOME" to "/root", "LD_PRELOAD" to "/run/droiddeck-preload/libblsession.so"), env)
val onlySession = mutableMapOf("LD_PRELOAD" to "$rootfs/usr/lib/libddnatv-hook.so")
BwrapSpawner.withoutRootfsSettings(onlySession, rootfs)
assertTrue(onlySession.isEmpty())
val wayland = mutableMapOf("SDL_VIDEODRIVER" to "x11", "WAYLAND_DISPLAY" to "wayland-0")
BwrapSpawner.withoutRootfsSettings(wayland, rootfs)
assertEquals(mapOf("WAYLAND_DISPLAY" to "wayland-0"), wayland)
val x11 = mutableMapOf("SDL_VIDEODRIVER" to "x11", "WAYLAND_DISPLAY" to "wayland-0", "DISPLAY" to ":99")
BwrapSpawner.withoutRootfsSettings(x11, rootfs)
assertEquals("x11", x11["SDL_VIDEODRIVER"])
}
@Test fun normalizeResolvesDotsLexically() {
assertEquals("/usr/lib/x", BwrapSpawner.normalize("/usr/lib/GL/../x"))
assertEquals("/", BwrapSpawner.normalize("/../.."))
@@ -0,0 +1,53 @@
package com.droiddeck.launcher.runtime
import java.nio.ByteBuffer
import java.nio.ByteOrder
import org.junit.Assert.assertEquals
import org.junit.Test
class ElfSeccompPatchTest {
private fun elfWith(vararg words: Int): ByteArray {
val data = ByteArray(0x200)
val b = ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN)
b.put(0, 0x7f); b.put(1, 'E'.code.toByte()); b.put(2, 'L'.code.toByte()); b.put(3, 'F'.code.toByte())
b.put(4, 2); b.put(5, 1)
b.putShort(18, 183)
b.putLong(32, 64)
b.putShort(54, 56); b.putShort(56, 1)
b.putInt(64, 1); b.putInt(68, 5)
b.putLong(72, 0x100); b.putLong(96, 0x100)
words.forEachIndexed { i, w -> b.putInt(0x100 + i * 4, w) }
return data
}
@Test
fun theSvcAfterEachBlockedCallIsAnsweredInPlace() {
val svc = 0xd4000001.toInt()
val data = elfWith(0xd2800c68.toInt(), 0xaa0003e1.toInt(), svc, 0xd28024a8.toInt(), svc, 0xd2803668.toInt(), svc)
assertEquals(3, ElfSeccompPatch.patch(data))
val b = ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN)
assertEquals(0xd503201f.toInt(), b.getInt(0x108))
assertEquals(0x928004a0.toInt(), b.getInt(0x110))
assertEquals(0x928004a0.toInt(), b.getInt(0x118))
assertEquals(0, ElfSeccompPatch.patch(data))
}
@Test
fun aSecondRunLeavesTheNextCallAlone() {
val svc = 0xd4000001.toInt()
val exit = 0xd2800ba8.toInt()
for (blocked in listOf(0xd2803668.toInt(), 0xd2800c68.toInt())) {
val data = elfWith(blocked, svc, 0xaa1303e0.toInt(), exit, svc)
assertEquals(1, ElfSeccompPatch.patch(data))
assertEquals(0, ElfSeccompPatch.patch(data))
assertEquals(svc, ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN).getInt(0x110))
}
}
@Test
fun otherSystemCallsAreLeftAlone() {
val svc = 0xd4000001.toInt()
val data = elfWith(0xd2800ba8.toInt(), svc)
assertEquals(0, ElfSeccompPatch.patch(data))
}
}
@@ -0,0 +1,99 @@
package com.droiddeck.launcher.runtime
import java.io.File
import java.nio.file.Files
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
class NativeGuestTest {
private fun rootWithLoader(): File = Files.createTempDirectory("native-root").toFile().also {
File(it, "usr/lib").mkdirs()
File(it, "usr/lib/ld-linux-aarch64.so.1").writeText("")
}
@Test
fun theSeccompSwitchNamesAHelperAndItsArgumentsInTheRootfs() {
val root = Files.createTempDirectory("rootfs").toFile()
assertEquals(null, NativeGuest.simulator(root))
File(root, "usr/local/bin").mkdirs()
File(root, "usr/local/bin/seccomp-sim").writeText("")
File(root, "etc/droiddeck").mkdirs()
File(root, "etc/droiddeck/seccomp-sim").writeText("/usr/local/bin/seccomp-sim -f /etc/droiddeck/app.bpf\n")
assertEquals(listOf(File(root, "usr/local/bin/seccomp-sim").path, "-f", File(root, "etc/droiddeck/app.bpf").path),
NativeGuest.simulator(root))
File(root, "etc/droiddeck/seccomp-sim").writeText("/usr/local/bin/missing")
assertEquals(null, NativeGuest.simulator(root))
}
@Test
fun aWorkingDirectoryInAMountIsItsSource() {
val root = Files.createTempDirectory("rootfs").toFile()
val storage = Files.createTempDirectory("storage").toFile()
File(root, "root").mkdirs()
// a mount spec is "src:dst"; Windows' drive letters cannot be written in one
org.junit.Assume.assumeFalse(storage.path.contains(':'))
val binds = listOf("${storage.path}:/root/Storage", "/proc")
assertEquals(storage, NativeGuest.workingDirectory(root, binds, "/root/Storage"))
assertEquals(File(root, "root"), NativeGuest.workingDirectory(root, binds, "/root"))
assertEquals(root, NativeGuest.workingDirectory(root, binds, "/nowhere"))
}
@Test
fun commandRunsTheProgramThroughTheRootfsLoader() {
val root = rootWithLoader()
val command = NativeGuest.command(root, "/usr/bin/env", listOf("-i", "A=1"))
assertEquals(File(root, "usr/lib/ld-linux-aarch64.so.1").path, command[0])
assertEquals(listOf("--argv0", "env", File(root, "usr/bin/env").path, "-i", "A=1"), command.drop(1))
}
@Test
fun mountsWithoutADestinationMapToThemselves() {
val root = rootWithLoader()
val env = NativeGuest.sessionEnvironment(root, listOf("/dev", "/a:/b"))
assertEquals("/dev:/dev|/a:/b", env["DDNATV_BINDS"])
assertEquals(root.path, env["DDNATV_ROOT"])
assertTrue(env.getValue("LD_PRELOAD").replace(File.separatorChar, '/').endsWith("usr/lib/libddnatv-hook.so"))
}
private val linkRoot = "/data/user/0/app/files/linuxfs"
private val sdBinds = listOf(
"/mnt/media_rw/CARD/files/steam:/mnt/droiddeck-sd",
"/data/user/0/app/files/steam-libraries/x/steamapps/compatdata:/mnt/droiddeck-sd/steamapps/compatdata",
"/storage/emulated/0",
)
@Test
fun aDriveLinkToTheCardGetsItsGuestPathBack() {
assertEquals("/mnt/droiddeck-sd", NativeGuest.guestLinkTarget("/mnt/media_rw/CARD/files/steam", linkRoot, sdBinds))
assertEquals("/mnt/droiddeck-sd/steamapps/compatdata/1",
NativeGuest.guestLinkTarget("/data/user/0/app/files/steam-libraries/x/steamapps/compatdata/1", linkRoot, sdBinds))
}
@Test
fun aDriveLinkIntoTheRootfsGetsItsGuestPathBack() {
assertEquals("/", NativeGuest.guestLinkTarget(linkRoot, linkRoot, sdBinds))
assertEquals("/root/Games", NativeGuest.guestLinkTarget("$linkRoot/root/Games", linkRoot, sdBinds))
}
@Test
fun guestPathsStayAsTheyAre() {
assertEquals(null, NativeGuest.guestLinkTarget("/mnt/droiddeck-sd", linkRoot, sdBinds))
assertEquals(null, NativeGuest.guestLinkTarget("/", linkRoot, sdBinds))
assertEquals(null, NativeGuest.guestLinkTarget("../drive_c", linkRoot, sdBinds))
assertEquals(null, NativeGuest.guestLinkTarget("/storage/emulated/0/Games", linkRoot, sdBinds))
}
@Test
fun aSiblingOfAMountSourceIsNotPartOfIt() {
assertEquals(null, NativeGuest.guestLinkTarget("/mnt/media_rw/CARD/files/steamx", linkRoot, sdBinds))
assertEquals(null, NativeGuest.guestLinkTarget("${linkRoot}x/root", linkRoot, sdBinds))
}
@Test
fun theFirstOfMountsSharingASourceIsTheGuestPath() {
val binds = sdBinds + "/data/user/0/app/files/steam-libraries/x/steamapps/compatdata:/mnt/bannerlator-sd/steamapps/compatdata"
assertEquals("/mnt/droiddeck-sd/steamapps/compatdata/2",
NativeGuest.guestLinkTarget("/data/user/0/app/files/steam-libraries/x/steamapps/compatdata/2", linkRoot, binds))
}
}
@@ -33,4 +33,8 @@ class ProotFastPathTest {
assertFalse(ProotFastPath.allows(preference = false, noSeccomp = false, source = LinuxRuntime.PROOT_PACK))
assertFalse(ProotFastPath.allows(preference = true, noSeccomp = true, source = LinuxRuntime.PROOT_PACK))
}
@Test fun fastPathStaysOffWithoutProot() {
assertFalse(ProotFastPath.allows(preference = true, noSeccomp = false, source = LinuxRuntime.PROOT_PACK, nativeUserland = true))
}
}