From 43ff1db06b1769dfd72645573b03af42fa0e2dbb Mon Sep 17 00:00:00 2001 From: The412Banner <205237651+The412Banner@users.noreply.github.com> Date: Tue, 24 Nov 2026 17:50:04 -0500 Subject: [PATCH] fix(appimage): DwarFS AppImages unpack without proot (#3161) --- README.md | 1 + .../launcher/session/SessionFiles.kt | 2 + tools/build_local.sh | 6 ++ tools/components/recipes.json | 1 + tools/components/recipes/runtime.sh | 7 +++ tools/linuxfs/licenses/dwarfs-LICENSE | 49 +++++++++++++++++ .../overlay/usr/local/bin/droiddeck-fex | 29 ++++++++++ tools/linuxfs/unwrap-dwarfs.sh | 8 +++ tools/linuxfs/uruntime.env | 4 ++ tools/release/runtime_inputs.py | 2 +- tools/tests/test_droiddeck_fex.py | 55 +++++++++++++++++++ tools/tests/test_unwrap_dwarfs.py | 45 +++++++++++++++ 12 files changed, 208 insertions(+), 1 deletion(-) create mode 100644 tools/linuxfs/licenses/dwarfs-LICENSE create mode 100755 tools/linuxfs/unwrap-dwarfs.sh create mode 100644 tools/tests/test_unwrap_dwarfs.py diff --git a/README.md b/README.md index 066136eab3..71024514c4 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,7 @@ DroidDeck is [GPL-3.0](LICENSE). Steam and Proton belong to Valve Corporation. V - mmap ring buffer controller input by ribbit384 ([WinNative #345](https://github.com/WinNative-Emu/WinNative/pull/345)). - [FEX](https://github.com/FEX-Emu/FEX) (MIT) runs x86 code. DroidDeck's build puts the platform name under `AT_PLATFORM` so [sharun](https://github.com/VHSgunzo/sharun) AppImages by VHSgunzo (MIT) start through its [userland-execve](https://crates.io/crates/userland-execve) loader (MIT), and its GL thunk hands X errors to the program's own error handler. FEX's code disk cache was checked in its source. The fix for host stack left behind when a program leaves a signal handler without returning follows the approach suggested in [FEX-Emu/FEX#2487](https://github.com/FEX-Emu/FEX/issues/2487). The host stack fix for system calls that end a block is a backport of Ryan Houdek's [FEX-Emu/FEX#6122](https://github.com/FEX-Emu/FEX/pull/6122). - x86 AppImages, and arm64 ones whose runtime can't unpack on Android, are unpacked with [uruntime](https://github.com/VHSgunzo/uruntime) by VHSgunzo (MIT), shipped unmodified with its licence. +- DwarFS AppImages are unpacked without proot by `dwarfsextract` from [DwarFS](https://github.com/mhx/dwarfs) by Marcus Holland-Moritz (MIT), the release binary uruntime embeds, taken out of its self-extracting wrapper and shipped with its licence. - x86 programs linking OpenSSL 3 use the copy in the [Steam Linux Runtime 4.0](https://gitlab.steamos.cloud/steamrt/steamrt). x86 Linux games get the `/etc/asound.conf` that [pressure-vessel](https://gitlab.steamos.cloud/steamrt/steam-runtime-tools) writes. - `WriteProcessMemory` hooks fall back to `/proc//mem` the way [Wine](https://gitlab.winehq.org/wine/wine)'s `server/ptrace.c` did before Wine 11. - Windows programs on noexec storage get executable copies of their image pages, following [@yujikaido](https://github.com/yujikaido)'s finding in [droiddeck-rp4pro](https://github.com/yujikaido/droiddeck-rp4pro) that Wine's own processes need the noexec shim. diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt index 101e413933..177774a4ce 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt @@ -263,7 +263,9 @@ object SessionFiles { "usr/local/share/vkbridge/droidbridge_icd.json" to "usr/local/share/vkbridge/droidbridge_icd.json", "usr/local/bin/droiddeck-vkbridge-smoke" to "usr/local/bin/droiddeck-vkbridge-smoke", "usr/local/lib/droiddeck/uruntime" to "usr/local/lib/droiddeck/uruntime", + "usr/local/lib/droiddeck/dwarfsextract" to "usr/local/lib/droiddeck/dwarfsextract", "usr/local/lib/droiddeck-pipewire.tzst" to "usr/local/lib/droiddeck-pipewire.tzst", + "usr/local/share/licenses/dwarfs/LICENSE" to "usr/local/share/licenses/dwarfs/LICENSE", "usr/local/share/licenses/uruntime/LICENSE" to "usr/local/share/licenses/uruntime/LICENSE", ) + mangoapp + xclipse.map { it to it } + maliCompat + msitools.map { it to it } + vr + gpuLoad + fexPreloads).filter { (asset, _) -> val dir = asset.substringBeforeLast('/') diff --git a/tools/build_local.sh b/tools/build_local.sh index 2c76362956..b5d15acea6 100755 --- a/tools/build_local.sh +++ b/tools/build_local.sh @@ -312,6 +312,12 @@ else mkdir -p "${linuxfs_dir}/usr/local/lib/droiddeck" "${linuxfs_dir}/usr/local/share/licenses/uruntime" install -m644 "${uruntime_binary}" "${linuxfs_dir}/usr/local/lib/droiddeck/uruntime" install -m644 "${repo_root}/tools/linuxfs/licenses/uruntime-LICENSE" "${linuxfs_dir}/usr/local/share/licenses/uruntime/LICENSE" + dwarfs_wrapper=$(cached "${DWARFS_SHA256}" "${DWARFS_ASSET}" \ + bash -c 'curl -fsSL --retry 5 --retry-all-errors --connect-timeout 20 -o "$out" "$0"' "https://github.com/mhx/dwarfs/releases/download/${DWARFS_VERSION}/${DWARFS_ASSET}") + mkdir -p "${linuxfs_dir}/usr/local/share/licenses/dwarfs" + bash "${repo_root}/tools/linuxfs/unwrap-dwarfs.sh" "${dwarfs_wrapper}" "${linuxfs_dir}/usr/local/lib/droiddeck/dwarfsextract" + printf '%s %s\n' "${DWARFS_PAYLOAD_SHA256}" "${linuxfs_dir}/usr/local/lib/droiddeck/dwarfsextract" | shasum -a 256 -c - >&2 + install -m644 "${repo_root}/tools/linuxfs/licenses/dwarfs-LICENSE" "${linuxfs_dir}/usr/local/share/licenses/dwarfs/LICENSE" sync_assets="${repo_root}/app/src/main/assets/droiddeck-esync" if [[ -f "${repo_root}/tools/droiddeck-esync/release.env" ]]; then diff --git a/tools/components/recipes.json b/tools/components/recipes.json index 5fd8ca4bc2..5cccf80ffa 100644 --- a/tools/components/recipes.json +++ b/tools/components/recipes.json @@ -8,6 +8,7 @@ "tools/linuxfs/desktop", "tools/linuxfs/licenses", "tools/linuxfs/uruntime.env", + "tools/linuxfs/unwrap-dwarfs.sh", "tools/gamescope/release.env", "tools/wlroots/release.env", "tools/mangoapp", diff --git a/tools/components/recipes/runtime.sh b/tools/components/recipes/runtime.sh index aa5273d270..9de7efba18 100644 --- a/tools/components/recipes/runtime.sh +++ b/tools/components/recipes/runtime.sh @@ -26,6 +26,13 @@ echo "${URUNTIME_SHA256} uruntime" | sha256sum -c - install -Dm644 uruntime "$D/usr/local/lib/droiddeck/uruntime" install -Dm644 tools/linuxfs/licenses/uruntime-LICENSE "$D/usr/local/share/licenses/uruntime/LICENSE" rm uruntime +curl -fsSL --retry 5 --retry-all-errors --connect-timeout 20 -o dwarfs-wrapper "https://github.com/mhx/dwarfs/releases/download/${DWARFS_VERSION}/${DWARFS_ASSET}" +echo "${DWARFS_SHA256} dwarfs-wrapper" | sha256sum -c - +bash tools/linuxfs/unwrap-dwarfs.sh dwarfs-wrapper dwarfsextract +echo "${DWARFS_PAYLOAD_SHA256} dwarfsextract" | sha256sum -c - +install -Dm644 dwarfsextract "$D/usr/local/lib/droiddeck/dwarfsextract" +install -Dm644 tools/linuxfs/licenses/dwarfs-LICENSE "$D/usr/local/share/licenses/dwarfs/LICENSE" +rm dwarfs-wrapper dwarfsextract M="$D/usr/local/lib/mangoapp" mkdir -p "$M" mango-pkgs grep -v '^#' tools/mangoapp/packages.txt | while read -r sum url; do diff --git a/tools/linuxfs/licenses/dwarfs-LICENSE b/tools/linuxfs/licenses/dwarfs-LICENSE new file mode 100644 index 0000000000..747b40c737 --- /dev/null +++ b/tools/linuxfs/licenses/dwarfs-LICENSE @@ -0,0 +1,49 @@ +Parts of the DwarFS project are licensed under the MIT license, while others are +licensed under the GPL-3.0 license. In general, the code used to *read* DwarFS +images is licensed under the MIT license, while the code used to *write* DwarFS +images is licensed under the GPL-3.0 license. Also, all testing/benchmarking +code is currently licensed under the GPL-3.0 license. + +That means you can use `mkdwarfs` to create images and then use these images +with only the MIT-licensed code. + +The following libraries and associated header files are licensed under the +MIT license: + +- `dwarfs_common` +- `dwarfs_compressor` +- `dwarfs_decompressor` +- `dwarfs_extractor` +- `dwarfs_reader` + +The following libraries and associated header files are licensed under the +GPL-3.0 license: + +- `dwarfs_rewrite` +- `dwarfs_writer` + +Each header and source file should contain an SPDX identifier near the top +of the file. + +Please also check the licenses of the projects that DwarFS depends on. + +---- + +MIT License + +Copyright (c) Marcus Holland-Moritz + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the +following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO +EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex b/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex index a25b755cee..af236125f7 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex @@ -27,6 +27,7 @@ GAME_ENVIRONMENT = os.path.join(HOME, ".config", "droiddeck", "game-environment. BIN_DIR = os.path.dirname(os.path.abspath(__file__)) PRELOADS = "/usr/local/lib/droiddeck-fex" URUNTIME = "/usr/local/lib/droiddeck/uruntime" +DWARFSEXTRACT = "/usr/local/lib/droiddeck/dwarfsextract" HOST_PRELOAD = "/etc/ld.so.preload" FEX_APPID = "3127680" OWN_FEX = "/usr/local" @@ -824,6 +825,30 @@ def extracted(): return os.path.isdir("squashfs-root") +def dwarfs_image(image): + try: + offset = appimage_offset(image) + with open(image, "rb") as f: + f.seek(offset) + return f.read(6) == b"DWARFS" + except (OSError, ValueError, struct.error): + return False + + +def dwarfs_extract(image): + clear_extracted() + os.mkdir("squashfs-root") + with open(image, "rb") as source: + status = subprocess.call([DWARFSEXTRACT, "--input", "/proc/self/fd/%d" % source.fileno(), + "--image-offset=%d" % appimage_offset(image), "--output", "squashfs-root", + "--log-level=error"], stdout=subprocess.DEVNULL, pass_fds=(source.fileno(),)) + if status == 0 and extracted(): + return True + say("dwarfsextract could not extract it (status %d)" % status) + clear_extracted() + return False + + def want_fex(): with locked(): update_own_fex() @@ -869,6 +894,10 @@ def extract(image): return 0 say("uruntime could not extract it (status %d)" % status) clear_extracted() + if os.access(DWARFSEXTRACT, os.X_OK) and dwarfs_image(image) and dwarfs_extract(image): + if x86: + want_fex() + return 0 fex = prepare() if x86 else None if fex is not None: status = subprocess.call([fex["bin"], image, "--appimage-extract"], stdout=subprocess.DEVNULL, diff --git a/tools/linuxfs/unwrap-dwarfs.sh b/tools/linuxfs/unwrap-dwarfs.sh new file mode 100755 index 0000000000..2956967667 --- /dev/null +++ b/tools/linuxfs/unwrap-dwarfs.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -euo pipefail +wrapper=${1:?usage: unwrap-dwarfs.sh WRAPPER OUTPUT} +output=${2:?usage: unwrap-dwarfs.sh WRAPPER OUTPUT} +[ "$(tail -c 32 "$wrapper" | head -c 8)" = "SQUEEZE!" ] || { echo "unwrap-dwarfs.sh: $wrapper has no SQUEEZE! trailer" >&2; exit 1; } +packed=$(tail -c 16 "$wrapper" | od -An -tu8 -N8 | tr -d ' ') +[ "$packed" -gt 0 ] && [ "$packed" -le $(( $(wc -c < "$wrapper") - 32 )) ] || { echo "unwrap-dwarfs.sh: bad payload size in $wrapper" >&2; exit 1; } +tail -c $((packed + 32)) "$wrapper" | head -c "$packed" | zstd -dcq > "$output" diff --git a/tools/linuxfs/uruntime.env b/tools/linuxfs/uruntime.env index f1b445d860..55e73d3eff 100644 --- a/tools/linuxfs/uruntime.env +++ b/tools/linuxfs/uruntime.env @@ -1,3 +1,7 @@ URUNTIME_VERSION=v0.8.1 URUNTIME_ASSET=uruntime-appimage-lite-aarch64 URUNTIME_SHA256=8485ae20eb0bfd4eaeac38d7fd7f78e153b391c718cf33ff07879605683be1ea +DWARFS_VERSION=v0.15.7 +DWARFS_ASSET=dwarfs-fuse-extract-0.15.7-Linux-aarch64 +DWARFS_SHA256=edb698186db6b162c755770ffabfcc05482bb7105a716fd943548e64244b0fd2 +DWARFS_PAYLOAD_SHA256=cc3b3e342ca6537139d8c90d3c0a00236cf786bb61bdccf019e5ed0ca5917a7a diff --git a/tools/release/runtime_inputs.py b/tools/release/runtime_inputs.py index 440c682cd8..4b2da89133 100644 --- a/tools/release/runtime_inputs.py +++ b/tools/release/runtime_inputs.py @@ -99,7 +99,7 @@ def required(): for name in ['turnip26.3.0-a6xx', 'turnip26.3.0-quest2']] paths += ['assets/linuxfs/' + name for name in ['libfakeinput.so', 'libddsession.so', 'libddfastpath.so', 'libddnatv-hook.so', 'libssbs.so', 'usr/local/bin/droiddeck-clipboard', - 'usr/local/bin/gamescope', 'usr/local/lib/droiddeck/uruntime', + 'usr/local/bin/gamescope', 'usr/local/lib/droiddeck/uruntime', 'usr/local/lib/droiddeck/dwarfsextract', 'usr/local/lib/droiddeck-pipewire.tzst']] for arch in ['x86_64', 'i386']: paths += ['assets/linuxfs/' + arch + '/' + lib for lib in ['libfakeinput.so', 'libddsession.so']] diff --git a/tools/tests/test_droiddeck_fex.py b/tools/tests/test_droiddeck_fex.py index 993d668d95..628fcd57ef 100644 --- a/tools/tests/test_droiddeck_fex.py +++ b/tools/tests/test_droiddeck_fex.py @@ -1090,6 +1090,61 @@ class ExtractTest(FexTestCase): self.assertNotIn("no unsquashfs", said) self.assertFalse(os.path.lexists("squashfs-root")) + def runtime_elf(self): + head = bytearray(elf(183)) + struct.pack_into("&2\nexit 1\n") + with mock.patch.dict(os.environ, {"DDNATV_ROOT": str(self.tmp / "rootfs")}), \ + mock.patch.dict(G, {"URUNTIME": tool, "DWARFSEXTRACT": reader}), \ + mock.patch("shutil.which", return_value=None): + status, said = self.quiet(FEX["extract"], "image.AppImage") + self.assertEqual(status, 0) + self.assertIn("uruntime could not extract it (status 1)", said) + self.assertNotIn("dwarfsextract could not", said) + self.assertTrue(Path("squashfs-root/AppRun").is_file()) + self.assertFalse((self.home / ".config/droiddeck/fex-wanted").exists()) + + def test_a_dwarfs_image_the_runtime_unpacks_never_runs_dwarfsextract(self): + reader = self.dwarfs("touch squashfs-root/AppRun\n") + tool = self.uruntime("mkdir -p AppDir && touch AppDir/AppRun\n") + with mock.patch.dict(G, {"URUNTIME": tool, "DWARFSEXTRACT": reader}): + status, said = self.quiet(FEX["extract"], "image.AppImage") + self.assertEqual((status, said), (0, "")) + self.assertFalse(self.ran.exists()) + + def test_a_dwarfsextract_failure_leaves_nothing_unpacked(self): + reader = self.dwarfs("mkdir -p squashfs-root/usr\nexit 3\n") + tool = self.uruntime("exit 1\n") + with mock.patch.dict(G, {"URUNTIME": tool, "DWARFSEXTRACT": reader}), \ + mock.patch("shutil.which", return_value=None): + status, said = self.quiet(FEX["extract"], "image.AppImage") + self.assertEqual(status, 1) + self.assertTrue(self.ran.exists()) + self.assertIn("dwarfsextract could not extract it (status 3)", said) + self.assertFalse(os.path.lexists("squashfs-root")) + + def test_a_squashfs_image_still_goes_to_unsquashfs(self): + reader = self.dwarfs("exit 0\n") + self.write(self.image, self.runtime_elf() + b"hsqs" + b"payload", 0o755) + tool = self.uruntime("exit 1\n") + with mock.patch.dict(G, {"DWARFSEXTRACT": reader}): + status, said, commands = self.seven_zip(tool, {"unsquashfs": "/usr/bin/unsquashfs", "7z": "/usr/bin/7z"}) + self.assertEqual(status, 0) + self.assertNotIn("dwarfsextract", said) + self.assertEqual(["/usr/bin/unsquashfs", "/usr/bin/7z"], [c[0] for c in commands]) + class LaunchTest(FexTestCase): def test_the_guest_environment(self): diff --git a/tools/tests/test_unwrap_dwarfs.py b/tools/tests/test_unwrap_dwarfs.py new file mode 100644 index 0000000000..0c2676eaa9 --- /dev/null +++ b/tools/tests/test_unwrap_dwarfs.py @@ -0,0 +1,45 @@ +import struct +import subprocess +import tempfile +import unittest +from pathlib import Path + +SCRIPT = Path(__file__).resolve().parents[1] / "linuxfs/unwrap-dwarfs.sh" + + +class UnwrapDwarfsTest(unittest.TestCase): + def setUp(self): + self.temp = tempfile.TemporaryDirectory() + self.addCleanup(self.temp.cleanup) + self.dir = Path(self.temp.name) + self.output = self.dir / "dwarfsextract" + + def wrapper(self, payload, magic=b"SQUEEZE!", packed=None): + compressed = subprocess.run(["zstd", "-q", "-c"], input=payload, capture_output=True, check=True).stdout + size = len(compressed) if packed is None else packed + path = self.dir / "wrapper" + path.write_bytes(b"\x7fELF stub" * 100 + compressed + magic + struct.pack("