From a2c3acd1987831f601df0b7e73a3ed1bd388bcb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Hernane?= <137581946+Josehbr@users.noreply.github.com> Date: Fri, 2 Oct 2026 16:13:14 -0300 Subject: [PATCH 1/4] Harden omarchy-refresh-limine's privileged read against a caller-controlled OMARCHY_PATH --- bin/omarchy-refresh-limine | 26 +++++++++++++++++++++-- test/shell.d/security-source-root-test.sh | 14 +++++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/bin/omarchy-refresh-limine b/bin/omarchy-refresh-limine index 1837d9e4f962..de4eaaedd4de 100755 --- a/bin/omarchy-refresh-limine +++ b/bin/omarchy-refresh-limine @@ -1,8 +1,28 @@ -#!/bin/bash +#!/bin/bash -p # omarchy:summary=Overwrite the user config for the Limine bootloader and rebuild it. # omarchy:requires-sudo=true +# Privileged Bash startup prevents BASH_ENV and exported functions from running +# before the environment can be sanitized. +if [[ $- != *p* ]]; then + echo "Refusing an unsafe Bash startup." >&2 + exit 126 +fi + +security_entrypoint=$(/usr/bin/readlink -e -- "${BASH_SOURCE[0]}") || exit 126 +source "${security_entrypoint%/*}/omarchy-security-functions" || exit 126 +omarchy_security_require_privileged_bash_startup || exit 126 +set -e +omarchy_security_sanitize_bash_environment "$0" "$@" +omarchy_security_require_source_root "$0" +# Root copies bootloader config out of $OMARCHY_PATH into /boot, so the same +# source-root rule the other privileged refresh commands apply binds that read +# to the packaged tree (or an omarchy dev link'ed checkout) rather than to +# whatever a caller's environment points at. +omarchy_security_install_sudo_cleanup_traps +omarchy_security_revoke_sudo_timestamp || exit 1 + legacy_uki="/boot/EFI/Linux/$(cat /etc/machine-id)_linux.efi" if sudo test -f /boot/EFI/Linux/omarchy_linux.efi && sudo test -f "$legacy_uki"; then @@ -11,7 +31,9 @@ if sudo test -f /boot/EFI/Linux/omarchy_linux.efi && sudo test -f "$legacy_uki"; fi echo "Resetting limine config" -sudo mv /boot/limine.conf /boot/limine.conf.bak +if sudo test -f /boot/limine.conf; then + sudo mv /boot/limine.conf /boot/limine.conf.bak +fi sudo cp "$OMARCHY_PATH/default/limine/limine.conf" /boot/limine.conf diff --git a/test/shell.d/security-source-root-test.sh b/test/shell.d/security-source-root-test.sh index 25ff2e98a85d..b4fd616700b0 100755 --- a/test/shell.d/security-source-root-test.sh +++ b/test/shell.d/security-source-root-test.sh @@ -51,7 +51,7 @@ pass "a package link must resolve to its named command" # Run the protected entrypoints themselves with a mismatched root. These must # stop before any sudo or operational fixture command, not merely validate in # an isolated library test. -for command in omarchy-update omarchy-refresh-pacman omarchy-update-stay-awake omarchy-channel-set; do +for command in omarchy-update omarchy-refresh-pacman omarchy-update-stay-awake omarchy-channel-set omarchy-refresh-limine; do rm -f "$SUDO_TEST_ROOT/bin/$command" copy_boundary_file "bin/$command" for root in "$boundary_tmp/other-root" .; do @@ -59,7 +59,19 @@ for command in omarchy-update omarchy-refresh-pacman omarchy-update-stay-awake o if OMARCHY_PATH="$root" "$SUDO_TEST_ROOT/bin/$command" >"$boundary_tmp/output" 2>&1; then fail "$command accepted a mismatched root" fi + if [[ $command == "omarchy-refresh-limine" ]]; then + grep -q 'OMARCHY_PATH does not match this Omarchy command\.' "$boundary_tmp/output" || + fail "$command did not report the source-root rejection" "$(<"$boundary_tmp/output")" + fi [[ ! -s $SUDO_TEST_LOG ]] || fail "$command ran work before rejecting its root" done + if [[ $command == "omarchy-refresh-limine" ]]; then + reset_boundary + if /usr/bin/bash "$SUDO_TEST_ROOT/bin/$command" -p >"$boundary_tmp/output" 2>&1; then + fail "$command accepted a decoy privileged-mode argument" + fi + [[ ! -s $SUDO_TEST_LOG ]] || fail "$command ran work from an ordinary Bash launch" + pass "$command rejects an ordinary Bash launch before work" + fi pass "$command rejects mismatched and relative roots before work" done From ca7b98e92695e1aa05466efc30b0712f719df677 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Hernane?= <137581946+Josehbr@users.noreply.github.com> Date: Fri, 2 Oct 2026 16:29:22 -0300 Subject: [PATCH 2/4] Test successful Limine refresh with and without an existing config --- test/shell.d/refresh-limine-test.sh | 72 +++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 test/shell.d/refresh-limine-test.sh diff --git a/test/shell.d/refresh-limine-test.sh b/test/shell.d/refresh-limine-test.sh new file mode 100755 index 000000000000..58307845c43b --- /dev/null +++ b/test/shell.d/refresh-limine-test.sh @@ -0,0 +1,72 @@ +#!/bin/bash + +set -euo pipefail + +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" +source "$SHELL_TEST_DIR/fixtures/sudo-boundary-test.sh" + +copy_boundary_file bin/omarchy-refresh-limine + +# Keep every bootloader operation inside the fixture. The sudo stand-in logs +# each request and runs only commands against these temporary paths. +boot_dir="$boundary_tmp/boot" +mkdir -p "$boot_dir" "$SUDO_TEST_ROOT/default/limine" +printf 'fixture-machine\n' >"$boundary_tmp/machine-id" +printf 'new limine config\n' >"$SUDO_TEST_ROOT/default/limine/limine.conf" +python3 - "$SUDO_TEST_ROOT/bin/omarchy-refresh-limine" "$boot_dir" "$boundary_tmp/machine-id" <<'PY' +import sys +from pathlib import Path + +script, boot_dir, machine_id = map(Path, sys.argv[1:]) +text = script.read_text().replace('/boot', str(boot_dir)).replace('/etc/machine-id', str(machine_id)) +script.write_text(text) +PY +ln -s test-step "$SUDO_TEST_ROOT/bin/limine-update" +ln -s test-step "$SUDO_TEST_ROOT/bin/limine-snapper-sync" +# The shared fixture stubs cp for update tests; this test needs the real copy +# to verify the staged config reaches its temporary boot directory. +rm "$SUDO_TEST_ROOT/bin/cp" + +for initial_config in present missing; do + reset_boundary + rm -f "$boot_dir/limine.conf" "$boot_dir/limine.conf.bak" + if [[ $initial_config == "present" ]]; then + printf 'old limine config\n' >"$boot_dir/limine.conf" + fi + + PATH="$SUDO_TEST_ROOT/bin:$PATH" "$SUDO_TEST_ROOT/bin/omarchy-refresh-limine" >"$boundary_tmp/output" 2>&1 || + fail "refresh failed with $initial_config boot config" "$(<"$boundary_tmp/output")" + + [[ $(<"$boot_dir/limine.conf") == "new limine config" ]] || fail "refresh did not copy the default config" + if [[ $initial_config == "present" ]]; then + [[ $(<"$boot_dir/limine.conf.bak") == "old limine config" ]] || fail "refresh did not back up the existing config" + else + [[ ! -e $boot_dir/limine.conf.bak ]] || fail "refresh made a backup without an existing config" + fi + + python3 - "$SUDO_TEST_LOG" "$initial_config" "$boot_dir" "$SUDO_TEST_ROOT" <<'PY' +import sys +from pathlib import Path + +log, initial_config, boot_dir, root = sys.argv[1:] +events = Path(log).read_text().splitlines() +expected = [ + 'sudo -k', + f'sudo test -f {boot_dir}/EFI/Linux/omarchy_linux.efi', + f'sudo test -f {boot_dir}/limine.conf', +] +if initial_config == 'present': + expected.append(f'sudo mv {boot_dir}/limine.conf {boot_dir}/limine.conf.bak') +expected += [ + f'sudo cp {root}/default/limine/limine.conf {boot_dir}/limine.conf', + 'sudo limine-update', + 'step:limine-update ', + 'sudo limine-snapper-sync', + 'step:limine-snapper-sync ', + 'sudo -k', +] +assert events == expected, (events, expected) +PY + assert_boundary_cold "refresh with $initial_config boot config" + pass "refresh with $initial_config boot config copies and rebuilds, then revokes sudo" +done From c3b5dbe4ff683f8abacca2b93a6b6132bfcd5575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Hernane?= <137581946+Josehbr@users.noreply.github.com> Date: Tue, 6 Oct 2026 12:16:56 -0300 Subject: [PATCH 3/4] Keep the sudo boundary fixture out of TMPDIRs containing spaces copy_boundary_file splices fixture paths into the copied script text, quoted or not, so a runner TMPDIR with whitespace broke the sudo stand-in before any assertion ran. Fall back to /tmp for the fixture root in that case. Co-Authored-By: Claude Sonnet 5.5 --- test/shell.d/fixtures/sudo-boundary-test.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/shell.d/fixtures/sudo-boundary-test.sh b/test/shell.d/fixtures/sudo-boundary-test.sh index 1fb123d097ca..b28358777e84 100644 --- a/test/shell.d/fixtures/sudo-boundary-test.sh +++ b/test/shell.d/fixtures/sudo-boundary-test.sh @@ -2,7 +2,11 @@ # Test the real orchestration with fixed privileged paths redirected to harmless # stand-ins. No host sudo, package transaction, namespace root, or exploit runs. -boundary_tmp=$(mktemp -d) +# copy_boundary_file splices fixture paths into script text, quoted or not, so +# the fixture root must not contain whitespace even if the runner's TMPDIR does. +boundary_tmp_base=${TMPDIR:-/tmp} +[[ $boundary_tmp_base != *[[:space:]]* ]] || boundary_tmp_base=/tmp +boundary_tmp=$(TMPDIR=$boundary_tmp_base mktemp -d) trap 'rm -rf "$boundary_tmp"' EXIT export SUDO_TEST_ROOT="$boundary_tmp/omarchy" export SUDO_TEST_LOG="$boundary_tmp/events" From d7138c329e594e4b644ab68e411d81fae0d6cab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Hernane?= <137581946+Josehbr@users.noreply.github.com> Date: Tue, 6 Oct 2026 12:16:56 -0300 Subject: [PATCH 4/4] Run omarchy-refresh-limine's sudo steps behind the command-scoped wrapper The other privileged entrypoints authorize once and then run behind the sudo-no-update wrapper with a fixed PATH. Do the same here so sudo does not resolve from the caller's PATH and no step refreshes the cached credential. The test now expects the single authorization followed by -N invocations. Co-Authored-By: Claude Sonnet 5.5 --- bin/omarchy-refresh-limine | 4 ++++ test/shell.d/refresh-limine-test.sh | 14 ++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/bin/omarchy-refresh-limine b/bin/omarchy-refresh-limine index de4eaaedd4de..71e710f82d8a 100755 --- a/bin/omarchy-refresh-limine +++ b/bin/omarchy-refresh-limine @@ -22,6 +22,10 @@ omarchy_security_require_source_root "$0" # whatever a caller's environment points at. omarchy_security_install_sudo_cleanup_traps omarchy_security_revoke_sudo_timestamp || exit 1 +# Authorize once, then run the privileged steps behind the command-scoped sudo +# wrapper so they reuse that timestamp and sudo resolves from a fixed PATH. +/usr/bin/sudo /usr/bin/true || exit 1 +omarchy_security_enable_no_update_sudo legacy_uki="/boot/EFI/Linux/$(cat /etc/machine-id)_linux.efi" diff --git a/test/shell.d/refresh-limine-test.sh b/test/shell.d/refresh-limine-test.sh index 58307845c43b..048f7b011011 100755 --- a/test/shell.d/refresh-limine-test.sh +++ b/test/shell.d/refresh-limine-test.sh @@ -52,16 +52,18 @@ log, initial_config, boot_dir, root = sys.argv[1:] events = Path(log).read_text().splitlines() expected = [ 'sudo -k', - f'sudo test -f {boot_dir}/EFI/Linux/omarchy_linux.efi', - f'sudo test -f {boot_dir}/limine.conf', + 'sudo /usr/bin/true', + 'sudo -h', + f'sudo -N test -f {boot_dir}/EFI/Linux/omarchy_linux.efi', + f'sudo -N test -f {boot_dir}/limine.conf', ] if initial_config == 'present': - expected.append(f'sudo mv {boot_dir}/limine.conf {boot_dir}/limine.conf.bak') + expected.append(f'sudo -N mv {boot_dir}/limine.conf {boot_dir}/limine.conf.bak') expected += [ - f'sudo cp {root}/default/limine/limine.conf {boot_dir}/limine.conf', - 'sudo limine-update', + f'sudo -N cp {root}/default/limine/limine.conf {boot_dir}/limine.conf', + 'sudo -N limine-update', 'step:limine-update ', - 'sudo limine-snapper-sync', + 'sudo -N limine-snapper-sync', 'step:limine-snapper-sync ', 'sudo -k', ]