mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 23:36:04 +00:00
fix(appimage): DwarFS AppImages unpack without proot (#3161)
This commit is contained in:
1 parent
f934feb457
commit
43ff1db06b
12 files changed
+208
-1
No files matched your search
@@ -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/<pid>/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.
|
||||
|
||||
@@ -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('/')
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
@@ -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,
|
||||
|
||||
Executable
+8
@@ -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"
|
||||
@@ -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
|
||||
@@ -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']]
|
||||
|
||||
@@ -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("<Q", head, 0x28, len(head))
|
||||
return bytes(head)
|
||||
|
||||
def dwarfs(self, body):
|
||||
self.write(self.image, self.runtime_elf() + b"DWARFS\x02\x05payload", 0o755)
|
||||
self.ran = self.tmp / "dwarfsextract-ran"
|
||||
return str(self.write(self.tmp / "dwarfsextract", "#!/bin/sh\ntouch %s\n%s" % (self.ran, body), 0o755))
|
||||
|
||||
def test_a_dwarfs_image_the_runtime_cannot_unpack_is_read_through_its_open_descriptor(self):
|
||||
reader = self.dwarfs(
|
||||
'[ "$1 $3 $4 $5" = "--input --image-offset=64 --output squashfs-root" ] || exit 9\n'
|
||||
'case $2 in /proc/self/fd/*) ;; *) exit 8 ;; esac\n'
|
||||
'cmp -s "$2" "%s" || exit 7\ntouch squashfs-root/AppRun\n' % self.image)
|
||||
tool = self.uruntime("echo 'Failed to execute dwarfsextract: EACCES: Permission denied' >&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):
|
||||
|
||||
@@ -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("<QQQ", len(payload), size, 0))
|
||||
return path
|
||||
|
||||
def unwrap(self, wrapper):
|
||||
return subprocess.run(["bash", str(SCRIPT), str(wrapper), str(self.output)], capture_output=True, text=True)
|
||||
|
||||
def test_the_payload_behind_the_stub_is_unpacked(self):
|
||||
payload = b"\x7fELF" + bytes(range(256)) * 64
|
||||
run = self.unwrap(self.wrapper(payload))
|
||||
self.assertEqual(run.returncode, 0, run.stderr)
|
||||
self.assertEqual(self.output.read_bytes(), payload)
|
||||
|
||||
def test_a_file_without_the_trailer_is_refused(self):
|
||||
run = self.unwrap(self.wrapper(b"payload", magic=b"NOTSQZ!!"))
|
||||
self.assertNotEqual(run.returncode, 0)
|
||||
self.assertIn("no SQUEEZE! trailer", run.stderr)
|
||||
|
||||
def test_a_payload_size_beyond_the_file_is_refused(self):
|
||||
run = self.unwrap(self.wrapper(b"payload", packed=1 << 40))
|
||||
self.assertNotEqual(run.returncode, 0)
|
||||
self.assertIn("bad payload size", run.stderr)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user