mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-25 07:46:01 +00:00
feat(native): run native sessions under a device's own app seccomp filter for testing
This commit is contained in:
1 parent
049da87a67
commit
0e56b54a69
5 files changed
+105
-7
No files matched your search
@@ -415,7 +415,7 @@ object BwrapSpawner {
|
||||
"LD_LIBRARY_PATH" to SANDBOX_LIB_DIRS.map(::host).filter { it.isDirectory }.joinToString(":") { it.path },
|
||||
"LD_PRELOAD" to hook.path,
|
||||
).filterValues { it.isNotEmpty() }
|
||||
return (NativeGuest.simulator(rootfs)?.let { listOf(it.path) + launch } ?: launch) to env
|
||||
return (NativeGuest.simulator(rootfs)?.let { it + launch } ?: launch) to env
|
||||
}
|
||||
|
||||
private val runpathDirs = java.util.concurrent.ConcurrentHashMap<String, List<String>>()
|
||||
|
||||
@@ -25,11 +25,18 @@ object NativeGuest {
|
||||
SessionPrefs.nativeUserland(context) && available(LinuxRuntime.rootDir(context))
|
||||
|
||||
/**
|
||||
* Development switch: a guest path in etc/droiddeck/seccomp-sim names a helper that applies Android's
|
||||
* app seccomp filter before the program starts, for devices (eng builds) that run apps without one.
|
||||
* Development switch: etc/droiddeck/seccomp-sim names a helper (a guest path, then its arguments)
|
||||
* that applies Android's app seccomp filter before the program starts, for devices that run apps
|
||||
* without one (eng builds, or a permissive SELinux, where zygote skips it). Guest paths among the
|
||||
* arguments are given as their places in the rootfs, as the helper runs before the hook.
|
||||
*/
|
||||
fun simulator(root: File): File? = File(root, "etc/droiddeck/seccomp-sim").takeIf { it.isFile }
|
||||
?.readText()?.trim()?.takeIf { it.startsWith("/") }?.let { File(root, it.removePrefix("/")) }?.takeIf { it.isFile }
|
||||
fun simulator(root: File): List<String>? {
|
||||
val words = File(root, "etc/droiddeck/seccomp-sim").takeIf { it.isFile }?.readText()?.trim()
|
||||
?.split(Regex("\\s+"))?.filter { it.isNotEmpty() } ?: return null
|
||||
val helper = words.firstOrNull()?.takeIf { it.startsWith("/") }?.let { File(root, it.removePrefix("/")) }
|
||||
?.takeIf { it.isFile } ?: return null
|
||||
return listOf(helper.path) + words.drop(1).map { if (it.startsWith("/")) File(root, it.removePrefix("/")).path else it }
|
||||
}
|
||||
|
||||
fun hook(root: File): File = File(root, HOOK)
|
||||
|
||||
@@ -55,7 +62,7 @@ object NativeGuest {
|
||||
val loader = checkNotNull(loader(root)) { "no glibc loader in ${root.path}" }
|
||||
val host = File(root, program.removePrefix("/"))
|
||||
val launch = listOf(loader.path, "--argv0", host.name, host.path) + args
|
||||
return simulator(root)?.let { listOf(it.path) + launch } ?: launch
|
||||
return simulator(root)?.let { it + launch } ?: launch
|
||||
}
|
||||
|
||||
/** The environment of the session process: the hook's root, the mounts proot used to make, the preload list. */
|
||||
|
||||
@@ -12,6 +12,20 @@ class NativeGuestTest {
|
||||
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()
|
||||
|
||||
Reference in new issue
Block a user