Skip to content

Commit 2b0422a

Browse files
committed
Merge remote-tracking branch 'ArrayBolt3/arraybolt3/trixie'
2 parents f5e6783 + 545c943 commit 2b0422a

6 files changed

Lines changed: 77 additions & 66 deletions

File tree

‎debian/security-misc-shared.install‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ usr/lib/systemd/system/usbguard.service.d/30_security-misc.conf#security-misc-sh
106106
usr/lib/systemd/system/user@.service.d/sysfs.conf#security-misc-shared => /usr/lib/systemd/system/user@.service.d/sysfs.conf
107107
usr/lib/systemd/user/fm-shim.service#security-misc-shared => /usr/lib/systemd/user/fm-shim.service
108108
usr/lib/systemd/user/usbguard-notifier.service.d/30_security-misc.conf#security-misc-shared => /usr/lib/systemd/user/usbguard-notifier.service.d/30_security-misc.conf
109-
usr/lib/udev/rules.d/70-udisks-ignore-optical.rules#security-misc-shared => /usr/lib/udev/rules.d/70-udisks-ignore-optical.rules
110109
usr/lib/udev/rules.d/95-emerg-shutdown.rules#security-misc-shared => /usr/lib/udev/rules.d/95-emerg-shutdown.rules
111110
usr/libexec/security-misc/askpass#security-misc-shared => /usr/libexec/security-misc/askpass
112111
usr/libexec/security-misc/block-unsafe-logins#security-misc-shared => /usr/libexec/security-misc/block-unsafe-logins

‎usr/lib/systemd/system/emerg-shutdown.service#security-misc-shared‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
## Copyright (C) 2025 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
22
## See the file COPYING for copying conditions.
33

4+
## WARNING: Do not add ANY "Requires" dependencies to this unit. If a required
5+
## dependency terminates, systemd will terminate emerg-shutdown, and many
6+
## services crash when the boot drive is removed. Use "Wants" instead.
7+
48
[Unit]
59
Description=Emergency shutdown when boot media is removed
610
Documentation=https://github.com/Kicksecure/security-misc
711
DefaultDependencies=no
812
Before=sysinit.target
9-
Requires=systemd-udevd.service
13+
Wants=systemd-udevd.service
1014
After=systemd-udevd.service
11-
Requires=local-fs.target
15+
Wants=local-fs.target
1216
After=local-fs.target
1317
ConditionPathExists=!/usr/share/qubes/marker-vm
1418
## Do not run emerg-shutdown.service in case 'rd.live.ram' or 'rd.live.ram=1'

‎usr/lib/udev/rules.d/70-udisks-ignore-optical.rules#security-misc-shared‎

Lines changed: 0 additions & 16 deletions
This file was deleted.

‎usr/libexec/security-misc/hide-hardware-info#security-misc-shared‎

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ set -o pipefail
1010
shopt -s nullglob
1111

1212
run_cmd() {
13-
echo "INFO: normal executing : $@"
13+
printf '%s\n' "INFO: normal executing : $@"
1414
"$@"
1515
}
1616

1717
run_cmd_whitelist() {
18-
echo "INFO: whitelist executing: $@"
18+
printf '%s\n' "INFO: whitelist executing: $@"
1919
"$@"
2020
}
2121

22-
echo "$0: INFO: START"
22+
printf '%s\n' "$0: INFO: START"
2323

2424
default_variables_set() {
2525
sysfs_whitelist=1
@@ -33,7 +33,7 @@ parse_configuration() {
3333
## Allows for disabling the whitelist.
3434
local i
3535
for i in /usr/local/etc/hide-hardware-info.d/*.conf /etc/hide-hardware-info.d/*.conf ; do
36-
bash -n "${i}"
36+
bash -n -- "${i}"
3737
source "${i}"
3838
done
3939
}
@@ -44,19 +44,19 @@ create_whitelist() {
4444
elif [ "${1}" = "cpuinfo" ]; then
4545
whitelist_path="/proc/cpuinfo"
4646
else
47-
echo "ERROR: ${1} is not a correct parameter."
47+
printf '%s\n' "ERROR: ${1} is not a correct parameter."
4848
exit 1
4949
fi
5050

51-
if grep -q "${1}" /etc/group; then
51+
if getent group -- "${1}" >/dev/null; then
5252
## Changing the permissions of /sys recursively
5353
## causes errors as the permissions of /sys/kernel/debug
5454
## and /sys/fs/cgroup cannot be changed.
55-
run_cmd_whitelist chgrp --quiet --recursive "${1}" "${whitelist_path}" || true
55+
run_cmd_whitelist chgrp --quiet --recursive -- "${1}" "${whitelist_path}" || true
5656

57-
run_cmd_whitelist chmod o-rwx "${whitelist_path}"
57+
run_cmd_whitelist chmod -- o-rwx "${whitelist_path}"
5858
else
59-
echo "ERROR: The ${1} group does not exist, the ${1} whitelist was not created."
59+
printf '%s\n' "ERROR: The ${1} group does not exist, the ${1} whitelist was not created."
6060
fi
6161
}
6262

@@ -78,25 +78,25 @@ for i in /proc/cpuinfo /proc/bus /proc/scsi /sys ; do
7878
if [ "${sysfs_whitelist}" = "1" ]; then
7979
create_whitelist sysfs
8080
else
81-
echo "INFO: The sysfs whitelist is not enabled. Some things may not work properly. Full sysfs hardening..."
82-
run_cmd chmod og-rwx /sys
81+
printf '%s\n' "INFO: The sysfs whitelist is not enabled. Some things may not work properly. Full sysfs hardening..."
82+
run_cmd chmod -- og-rwx /sys
8383
fi
8484
fi
8585
elif [ "${i}" = "/proc/cpuinfo" ]; then
8686
if [ "${cpuinfo_whitelist}" = "1" ]; then
8787
create_whitelist cpuinfo
8888
else
89-
echo "INFO: The cpuinfo whitelist is not enabled. Some things may not work properly. Full cpuinfo hardening..."
90-
run_cmd chmod og-rwx /proc/cpuinfo
89+
printf '%s\n' "INFO: The cpuinfo whitelist is not enabled. Some things may not work properly. Full cpuinfo hardening..."
90+
run_cmd chmod -- og-rwx /proc/cpuinfo
9191
fi
9292
else
93-
run_cmd chmod og-rwx "${i}"
93+
run_cmd chmod -- og-rwx "${i}"
9494
fi
9595
else
9696
## /proc/scsi doesn't exist on Debian so errors
9797
## are expected here.
9898
if ! [ "${i}" = "/proc/scsi" ]; then
99-
echo "ERROR: ${i} could not be found."
99+
printf '%s\n' "ERROR: ${i} could not be found."
100100
fi
101101
fi
102102
done
@@ -109,30 +109,30 @@ if [ "${sysfs}" = "1" ]; then
109109
## Using '|| true':
110110
## https://github.com/Kicksecure/security-misc/pull/108
111111
if [ "${sysfs_whitelist}" = "1" ]; then
112-
run_cmd chmod o-rwx "${i}" || true
112+
run_cmd chmod -- o-rwx "${i}" || true
113113
else
114-
run_cmd chmod og-rwx "${i}" || true
114+
run_cmd chmod -- og-rwx "${i}" || true
115115
fi
116116
done
117117

118118
## polkit needs stat access to /sys/fs/cgroup
119119
## to function properly
120-
run_cmd chmod o+rx /sys /sys/fs
120+
run_cmd chmod -- o+rx /sys /sys/fs
121121

122122
## on SELinux systems, at least /sys/fs/selinux
123123
## must be visible to unprivileged users, else
124124
## SELinux userspace utilities will not function
125125
## properly
126126
if [ -d /sys/fs/selinux ]; then
127-
echo "INFO: SELinux detected because folder /sys/fs/selinux exists. See also:"
128-
echo "https://www.kicksecure.com/wiki/Security-misc#selinux"
127+
printf '%s\n' "INFO: SELinux detected because folder /sys/fs/selinux exists. See also:"
128+
printf '%s\n' "https://www.kicksecure.com/wiki/Security-misc#selinux"
129129
if [ "${selinux}" = "1" ]; then
130-
run_cmd chmod o+rx /sys /sys/fs /sys/fs/selinux
131-
echo "INFO: SELinux mode enabled. Restrictions loosened slightly in order to allow userspace utilities to function."
130+
run_cmd chmod -- o+rx /sys /sys/fs /sys/fs/selinux
131+
printf '%s\n' "INFO: SELinux mode enabled. Restrictions loosened slightly in order to allow userspace utilities to function."
132132
else
133-
echo "INFO: SELinux detected, but SELinux mode is not enabled. Some userspace utilities may not work properly."
133+
printf '%s\n' "INFO: SELinux detected, but SELinux mode is not enabled. Some userspace utilities may not work properly."
134134
fi
135135
fi
136136
fi
137137

138-
echo "$0: INFO: END"
138+
printf '%s\n' "$0: INFO: END"

‎usr/libexec/security-misc/virusforget#security-misc-shared‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ parse_cmd_options() {
8686
exit 1
8787
fi
8888
if ! id -u "$user_name" >/dev/null 2>&1; then
89-
echo "ERROR: User '$user_name' does not appear to exist!"
89+
echo "ERROR: User '$user_name' does not appear to exist!" >&2
90+
exit 1
9091
fi
9192
}
9293

@@ -297,6 +298,13 @@ unexpected_file() {
297298
}
298299

299300
restore_file() {
301+
## An extraneous file has no baseline backup to restore from; the caller
302+
## has already removed it, which is the correct action. Return early so the
303+
## 'cp' below does not fail on the missing backup and abort the entire
304+
## '--clean' run (via 'set -e') on the first extraneous file encountered.
305+
if [ ! -e "$full_path_backup" ]; then
306+
return 0
307+
fi
300308
if [ "$test_mode" = "true" ]; then
301309
echo "Simulate restoring file... $full_path_original" >&2
302310
echo cp --no-dereference --archive "$full_path_backup" "$full_path_original"

‎usr/src/security-misc/emerg-shutdown.c#security-misc-shared‎

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,39 @@ trykill:
482482
exit(0);
483483
}
484484

485+
/* Ignore all signals, except SIGSEGV and (optionally) SIGTERM. */
486+
void ignore_signals(bool also_sigterm) {
487+
struct sigaction sigact_swallow = { 0 };
488+
int sig_idx = 0;
489+
490+
/* Swallow all signals that we can. */
491+
sigact_swallow.sa_handler = SIG_IGN;
492+
for (sig_idx = 1; sig_idx <= max_sig_num; sig_idx++) {
493+
if (sig_idx == SIGSTOP) {
494+
continue;
495+
}
496+
if (sig_idx == SIGKILL) {
497+
continue;
498+
}
499+
if (sig_idx == SIGSEGV) {
500+
continue;
501+
}
502+
if (sig_idx == SIGTERM && !also_sigterm) {
503+
continue;
504+
}
505+
if (sigaction(sig_idx, &sigact_swallow, NULL) == -1) {
506+
print(fd_stderr, "Failed to set up signal ignores!\n");
507+
exit(1);
508+
}
509+
}
510+
for (sig_idx = SIGRTMIN; sig_idx <= SIGRTMAX; sig_idx++) {
511+
if (sigaction(sig_idx, &sigact_swallow, NULL) == -1) {
512+
print(fd_stderr, "Failed to set up real-time signal ignores!\n");
513+
exit(1);
514+
}
515+
}
516+
}
517+
485518
/* Monitor for device removal and emergency shutdown key combos. */
486519
void hw_monitor(int argc, char **argv) {
487520
/* Working variables */
@@ -545,6 +578,8 @@ void hw_monitor(int argc, char **argv) {
545578
exit(1);
546579
}
547580

581+
ignore_signals(false); /* ignore all but SIGTERM */
582+
548583
console_fd = open("/dev/console", O_RDWR);
549584
if (console_fd == -1) {
550585
print(fd_stderr, "Could not open /dev/console!\n");
@@ -684,6 +719,7 @@ void hw_monitor(int argc, char **argv) {
684719
}
685720

686721
if (!bitset_get(key_flags, EV_KEY)) {
722+
close(tmp_fd);
687723
continue;
688724
}
689725

@@ -708,6 +744,7 @@ void hw_monitor(int argc, char **argv) {
708744
}
709745
}
710746
if (!supports_panic) {
747+
close(tmp_fd);
711748
continue;
712749
}
713750

@@ -950,8 +987,6 @@ void fifo_monitor(char **argv) {
950987
struct pollfd trigger_fifo_poll = { 0 };
951988
char trigger_fifo_charbuf = '\0';
952989
ssize_t trigger_fifo_readlen = 0;
953-
int sig_idx = 0;
954-
struct sigaction sigact_swallow = { 0 };
955990

956991
if (strncmp(argv[2], "--timeout=", strlen("--timeout=")) != 0) {
957992
print(fd_stderr, "Timeout not passed for --monitor-fifo!\n");
@@ -1007,26 +1042,7 @@ void fifo_monitor(char **argv) {
10071042
trigger_fifo_poll.fd = trigger_fifo_fd;
10081043
trigger_fifo_poll.events = POLLIN;
10091044

1010-
/* Swallow all signals that we can. */
1011-
sigact_swallow.sa_handler = SIG_IGN;
1012-
for (sig_idx = 1; sig_idx < max_sig_num; sig_idx++) {
1013-
if (sig_idx == SIGSTOP) {
1014-
continue;
1015-
}
1016-
if (sig_idx == SIGKILL) {
1017-
continue;
1018-
}
1019-
if (sigaction(sig_idx, &sigact_swallow, NULL) == -1) {
1020-
print(fd_stderr, "Failed to set up signal ignores!\n");
1021-
exit(1);
1022-
}
1023-
}
1024-
for (sig_idx = SIGRTMIN; sig_idx <= SIGRTMAX; sig_idx++) {
1025-
if (sigaction(sig_idx, &sigact_swallow, NULL) == -1) {
1026-
print(fd_stderr, "Failed to set up real-time signal ignores!\n");
1027-
exit(1);
1028-
}
1029-
}
1045+
ignore_signals(true); /* ignore even SIGTERM */
10301046

10311047
while (poll(&trigger_fifo_poll, 1, -1) != -1) {
10321048
trigger_fifo_readlen = read(trigger_fifo_fd, &trigger_fifo_charbuf, 1);

0 commit comments

Comments
 (0)