mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-25 07:46:01 +00:00
fix(desktop): package updates that set file capabilities finish without proot (#3151)
This commit is contained in:
1 parent
9be131cf6d
commit
826853fff5
7 files changed
+130
-7
No files matched your search
@@ -154,6 +154,7 @@ object SessionFiles {
|
||||
"usr/local/bin/droiddeck-emulators" to "usr/local/bin/droiddeck-emulators",
|
||||
"usr/local/bin/droiddeck-snap-run" to "usr/local/bin/droiddeck-snap-run",
|
||||
"usr/local/bin/droiddeck-snap-confine" to "usr/local/bin/droiddeck-snap-confine",
|
||||
"usr/local/bin/droiddeck-diversion-stub" to "usr/local/bin/droiddeck-diversion-stub",
|
||||
"usr/local/bin/droiddeck-snapctl" to "usr/local/bin/droiddeck-snapctl",
|
||||
"usr/local/bin/droiddeck-systemd-run" to "usr/local/bin/systemd-run",
|
||||
"usr/local/bin/droiddeck-snap-cli" to "usr/local/bin/snap",
|
||||
|
||||
@@ -28,6 +28,8 @@ find "$XDG_RUNTIME_DIR" -mindepth 1 -maxdepth 1 ! -name 'wayland-0*' ! -name 'ke
|
||||
chmod 700 "$XDG_RUNTIME_DIR" 2>/dev/null
|
||||
mkdir -p /tmp/.X11-unix /tmp/.ICE-unix && chmod 1777 /tmp/.X11-unix /tmp/.ICE-unix 2>/dev/null
|
||||
export DD_DESKTOP=1
|
||||
sh /usr/local/bin/droiddeck-diversion-stub /usr/bin/pkexec /usr/local/bin/pkexec migrate
|
||||
sh /usr/local/bin/droiddeck-diversion-stub /usr/lib/snapd/snap-confine /usr/local/bin/droiddeck-snap-confine migrate
|
||||
ln -sf /usr/local/bin/droiddeck-steam-launch /usr/local/bin/steamdeck-steam 2>/dev/null
|
||||
ln -sf /usr/local/bin/droiddeck-steam-shim /usr/local/bin/steam 2>/dev/null
|
||||
python3 /usr/local/bin/droiddeck-desktop-games 2>&1 | sed 's/^/[games] /'
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
path=$1 target=$2 mode=$3
|
||||
if [ "$mode" = migrate ]; then
|
||||
resolved=$(readlink -f "$target") || exit 0
|
||||
[ -n "$resolved" ] && [ -L "$path" ] && [ "$(readlink -f "$path")" = "$resolved" ] || exit 0
|
||||
elif [ "$mode" != install ]; then
|
||||
exit 1
|
||||
fi
|
||||
tmp=$(mktemp "${path}.XXXXXX")
|
||||
trap 'rm -f "$tmp"' EXIT
|
||||
printf '#!/bin/sh\nexec %s "$@"\n' "$target" > "$tmp"
|
||||
chmod 755 "$tmp"
|
||||
mv -f "$tmp" "$path"
|
||||
@@ -505,7 +505,7 @@ int is_selinux_enabled(void) { return 0; }
|
||||
ssize_t getxattr(const char *path, const char *name, void *value, size_t size) {
|
||||
static ssize_t (*orig_getxattr)(const char *, const char *, void *, size_t) = NULL;
|
||||
if (!orig_getxattr) orig_getxattr = (ssize_t (*)(const char *, const char *, void *, size_t))dlsym(RTLD_NEXT, "getxattr");
|
||||
if (is_selinux_xattr(name)) {
|
||||
if (is_selinux_xattr(name) || (name && strcmp(name, "security.capability") == 0)) {
|
||||
errno = ENODATA;
|
||||
return -1;
|
||||
}
|
||||
@@ -516,7 +516,7 @@ ssize_t getxattr(const char *path, const char *name, void *value, size_t size) {
|
||||
ssize_t lgetxattr(const char *path, const char *name, void *value, size_t size) {
|
||||
static ssize_t (*orig_lgetxattr)(const char *, const char *, void *, size_t) = NULL;
|
||||
if (!orig_lgetxattr) orig_lgetxattr = (ssize_t (*)(const char *, const char *, void *, size_t))dlsym(RTLD_NEXT, "lgetxattr");
|
||||
if (is_selinux_xattr(name)) {
|
||||
if (is_selinux_xattr(name) || (name && strcmp(name, "security.capability") == 0)) {
|
||||
errno = ENODATA;
|
||||
return -1;
|
||||
}
|
||||
@@ -543,7 +543,7 @@ ssize_t llistxattr(const char *path, char *list, size_t size) {
|
||||
ssize_t fgetxattr(int fd, const char *name, void *value, size_t size) {
|
||||
static ssize_t (*orig_fgetxattr)(int, const char *, void *, size_t) = NULL;
|
||||
if (!orig_fgetxattr) orig_fgetxattr = (ssize_t (*)(int, const char *, void *, size_t))dlsym(RTLD_NEXT, "fgetxattr");
|
||||
if (is_selinux_xattr(name)) {
|
||||
if (is_selinux_xattr(name) || (name && strcmp(name, "security.capability") == 0)) {
|
||||
errno = ENODATA;
|
||||
return -1;
|
||||
}
|
||||
@@ -558,6 +558,7 @@ ssize_t flistxattr(int fd, char *list, size_t size) {
|
||||
}
|
||||
|
||||
int setxattr(const char *path, const char *name, const void *value, size_t size, int flags) {
|
||||
if (name && strcmp(name, "security.capability") == 0) return 0;
|
||||
static int (*orig_setxattr)(const char *, const char *, const void *, size_t, int) = NULL;
|
||||
if (!orig_setxattr) orig_setxattr = (int (*)(const char *, const char *, const void *, size_t, int))dlsym(RTLD_NEXT, "setxattr");
|
||||
char pbuf[PATH_MAX];
|
||||
@@ -565,6 +566,7 @@ int setxattr(const char *path, const char *name, const void *value, size_t size,
|
||||
}
|
||||
|
||||
int lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags) {
|
||||
if (name && strcmp(name, "security.capability") == 0) return 0;
|
||||
static int (*orig_lsetxattr)(const char *, const char *, const void *, size_t, int) = NULL;
|
||||
if (!orig_lsetxattr) orig_lsetxattr = (int (*)(const char *, const char *, const void *, size_t, int))dlsym(RTLD_NEXT, "lsetxattr");
|
||||
char pbuf[PATH_MAX];
|
||||
@@ -572,6 +574,7 @@ int lsetxattr(const char *path, const char *name, const void *value, size_t size
|
||||
}
|
||||
|
||||
int removexattr(const char *path, const char *name) {
|
||||
if (name && strcmp(name, "security.capability") == 0) return 0;
|
||||
static int (*orig_removexattr)(const char *, const char *) = NULL;
|
||||
if (!orig_removexattr) orig_removexattr = (int (*)(const char *, const char *))dlsym(RTLD_NEXT, "removexattr");
|
||||
char pbuf[PATH_MAX];
|
||||
@@ -579,12 +582,27 @@ int removexattr(const char *path, const char *name) {
|
||||
}
|
||||
|
||||
int lremovexattr(const char *path, const char *name) {
|
||||
if (name && strcmp(name, "security.capability") == 0) return 0;
|
||||
static int (*orig_lremovexattr)(const char *, const char *) = NULL;
|
||||
if (!orig_lremovexattr) orig_lremovexattr = (int (*)(const char *, const char *))dlsym(RTLD_NEXT, "lremovexattr");
|
||||
char pbuf[PATH_MAX];
|
||||
return orig_lremovexattr ? orig_lremovexattr(rewrite_path(path, pbuf, sizeof(pbuf)), name) : -1;
|
||||
}
|
||||
|
||||
int fsetxattr(int fd, const char *name, const void *value, size_t size, int flags) {
|
||||
static int (*orig)(int, const char *, const void *, size_t, int) = NULL;
|
||||
if (name && strcmp(name, "security.capability") == 0) return 0;
|
||||
if (!orig) orig = dlsym(RTLD_NEXT, "fsetxattr");
|
||||
return orig ? orig(fd, name, value, size, flags) : -1;
|
||||
}
|
||||
|
||||
int fremovexattr(int fd, const char *name) {
|
||||
static int (*orig)(int, const char *) = NULL;
|
||||
if (name && strcmp(name, "security.capability") == 0) return 0;
|
||||
if (!orig) orig = dlsym(RTLD_NEXT, "fremovexattr");
|
||||
return orig ? orig(fd, name) : -1;
|
||||
}
|
||||
|
||||
// Hook symlink
|
||||
int symlink(const char *target, const char *linkpath) {
|
||||
static int (*orig_symlink)(const char *, const char *) = NULL;
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from tools.tests.test_usr2_preload import runner
|
||||
|
||||
TOOLS = Path(__file__).resolve().parents[1]
|
||||
STUB = TOOLS / 'linuxfs/overlay/usr/local/bin/droiddeck-diversion-stub'
|
||||
PROBE = r'''
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/xattr.h>
|
||||
#include <unistd.h>
|
||||
int main(int argc, char **argv) {
|
||||
int fd = open(argv[1], O_RDWR);
|
||||
char value[] = "test", out[8];
|
||||
if (fd < 0) return 1;
|
||||
if (setxattr(argv[1], "security.capability", value, 4, 0) ||
|
||||
lsetxattr(argv[1], "security.capability", value, 4, 0) ||
|
||||
fsetxattr(fd, "security.capability", value, 4, 0)) return 2;
|
||||
if (getxattr(argv[1], "security.capability", out, 8) != -1 || errno != ENODATA ||
|
||||
lgetxattr(argv[1], "security.capability", out, 8) != -1 || errno != ENODATA ||
|
||||
fgetxattr(fd, "security.capability", out, 8) != -1 || errno != ENODATA) return 3;
|
||||
if (removexattr(argv[1], "security.capability") ||
|
||||
lremovexattr(argv[1], "security.capability") ||
|
||||
fremovexattr(fd, "security.capability")) return 4;
|
||||
if (fsetxattr(fd, "user.ddtest", value, 4, 0) ||
|
||||
fgetxattr(fd, "user.ddtest", out, 8) != 4 ||
|
||||
fremovexattr(fd, "user.ddtest")) return 5;
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
'''
|
||||
|
||||
class DiversionCapabilitiesTest(unittest.TestCase):
|
||||
def test_stubs_and_migration(self):
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
path = Path(d) / 'entry'
|
||||
target = Path(d) / 'target'
|
||||
target.write_text('#!/bin/sh\nprintf "%s\\n" "$@"\n')
|
||||
target.chmod(0o755)
|
||||
path.symlink_to(target.name)
|
||||
subprocess.run(['sh', str(STUB), str(path), str(target), 'migrate'], check=True)
|
||||
self.assertFalse(path.is_symlink())
|
||||
self.assertEqual(path.stat().st_mode & 0o777, 0o755)
|
||||
self.assertEqual(subprocess.check_output([str(path), 'one two'], text=True), 'one two\n')
|
||||
before = path.read_bytes()
|
||||
subprocess.run(['sh', str(STUB), str(path), str(target), 'migrate'], check=True)
|
||||
self.assertEqual(path.read_bytes(), before)
|
||||
path.unlink()
|
||||
path.symlink_to('other')
|
||||
subprocess.run(['sh', str(STUB), str(path), str(target), 'migrate'], check=True)
|
||||
self.assertEqual(os.readlink(path), 'other')
|
||||
subprocess.run(['sh', str(STUB), str(path), str(target), 'install'], check=True)
|
||||
self.assertFalse(path.is_symlink())
|
||||
self.assertEqual(path.read_bytes(), before)
|
||||
|
||||
def test_capability_xattrs_and_other_attributes(self):
|
||||
cc, prefix = runner()
|
||||
if cc is None:
|
||||
self.skipTest('no aarch64 compiler and runner')
|
||||
if not shutil.which('aarch64-linux-gnu-gcc') and not (shutil.which('clang') and shutil.which('ld.lld')):
|
||||
self.skipTest('no aarch64 cross compiler for the hook build')
|
||||
with tempfile.TemporaryDirectory(dir='/tmp') as d:
|
||||
root = Path(d)
|
||||
hook, source, probe, target = (root / name for name in ('hook.so', 'probe.c', 'probe', 'file'))
|
||||
subprocess.run(['bash', str(TOOLS / 'nativeguest/build.sh'), str(hook), cc], check=True, capture_output=True)
|
||||
source.write_text(PROBE)
|
||||
subprocess.run([cc, '-o', str(probe), str(source)], check=True)
|
||||
target.touch()
|
||||
env = {k: v for k, v in os.environ.items() if k not in ('LD_PRELOAD', 'DDNATV_ROOT')}
|
||||
variables = {'LD_PRELOAD': str(hook), 'DDNATV_ROOT': str(root)}
|
||||
if prefix:
|
||||
command = list(prefix) + [arg for k, v in variables.items() for arg in ('-E', f'{k}={v}')]
|
||||
else:
|
||||
command = []
|
||||
env.update(variables)
|
||||
result = subprocess.run(command + [str(probe), str(target)], env=env, capture_output=True, text=True)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertNotIn('security.capability', os.listxattr(target))
|
||||
@@ -29,6 +29,7 @@ sudo cp /etc/resolv.conf "$root/etc/resolv.conf"
|
||||
for m in dev dev/pts proc sys; do sudo mount --bind "/$m" "$root/$m"; done
|
||||
sudo mkdir -p "$root/tmp/droiddeck/debs"
|
||||
sudo cp -r "$here/." "$root/tmp/droiddeck/src"
|
||||
sudo cp "$here/../linuxfs/overlay/usr/local/bin/droiddeck-diversion-stub" "$root/tmp/droiddeck/src/diversion-stub"
|
||||
sudo cp "$debs"/*.deb "$root/tmp/droiddeck/debs/"
|
||||
base_url=${DESKTOP_BASE_URL:-https://github.com/Droid-Deck/DroidDeck-Components/releases/download/$runtime_id}
|
||||
desktop_id=$runtime_id-desktop
|
||||
|
||||
@@ -85,10 +85,14 @@ install_turnip() {
|
||||
}
|
||||
|
||||
divert_to() {
|
||||
local path=$1 target=$2 owner=$3
|
||||
local path=$1 target=$2 owner=$3 kind=${4:-link}
|
||||
[ -e "$path" ] || [ -L "$path" ] || return 0
|
||||
dpkg-divert --package "$owner" --rename --divert "$path.distrib" --add "$path"
|
||||
ln -sf "$target" "$path"
|
||||
if [ "$kind" = stub ]; then
|
||||
sh "$here/diversion-stub" "$path" "$target" install
|
||||
else
|
||||
ln -sf "$target" "$path"
|
||||
fi
|
||||
}
|
||||
|
||||
record_apt_state() {
|
||||
@@ -179,8 +183,8 @@ grep -v '^$' "$here/packages-desktop.txt" | xargs apt-get install -y firefox
|
||||
install_held
|
||||
build_package droiddeck-desktop "$here/overlay-desktop" "$here/protected-desktop.txt" "DroidDeck's Plasma desktop"
|
||||
|
||||
divert_to /usr/bin/pkexec /usr/local/bin/pkexec droiddeck-desktop
|
||||
divert_to /usr/lib/snapd/snap-confine /usr/local/bin/droiddeck-snap-confine droiddeck-desktop
|
||||
divert_to /usr/bin/pkexec /usr/local/bin/pkexec droiddeck-desktop stub
|
||||
divert_to /usr/lib/snapd/snap-confine /usr/local/bin/droiddeck-snap-confine droiddeck-desktop stub
|
||||
mkdir -p /snap/bin /var/lib/snapd/desktop/applications
|
||||
rm -rf /etc/skel/Desktop
|
||||
finish
|
||||
Reference in new issue
Block a user