mirror of
https://github.com/Kicksecure/security-misc.git
synced 2025-12-16 05:23:48 -05:00
Merge remote-tracking branch 'ArrayBolt3/arraybolt3/emerg-shutdown'
This commit is contained in:
commit
4ba029471e
11 changed files with 1181 additions and 0 deletions
13
README.md
13
README.md
|
|
@ -712,6 +712,19 @@ See:
|
||||||
* https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=860040
|
* https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=860040
|
||||||
* https://forums.whonix.org/t/cannot-use-pkexec/8129
|
* https://forums.whonix.org/t/cannot-use-pkexec/8129
|
||||||
|
|
||||||
|
## Emergency shutdown
|
||||||
|
|
||||||
|
- Forcibly powers off the system if the drive the system booted from is
|
||||||
|
removed from the system.
|
||||||
|
- Forcibly powers off the system if a user-configurable "panic key sequence"
|
||||||
|
is pressed (Ctrl+Alt+Delete by default).
|
||||||
|
- Forcibly powers off the system if
|
||||||
|
`sudo /run/emerg-shutdown --instant-shutdown` is called.
|
||||||
|
- Optional - Forcibly powers off the system if shutdown gets stuck for longer
|
||||||
|
than a user-configurable number of seconds (30 by default). Requires tuning
|
||||||
|
by the user to function properly, see notes in
|
||||||
|
`/etc/security-misc/emerg-shutdown/30_security_misc.conf`.
|
||||||
|
|
||||||
## Application-specific hardening
|
## Application-specific hardening
|
||||||
|
|
||||||
- Enables "`apt-get --error-on=any`" which makes apt exit non-zero for
|
- Enables "`apt-get --error-on=any`" which makes apt exit non-zero for
|
||||||
|
|
|
||||||
2
debian/control
vendored
2
debian/control
vendored
|
|
@ -20,6 +20,7 @@ Package: security-misc
|
||||||
Architecture: all
|
Architecture: all
|
||||||
Depends: adduser,
|
Depends: adduser,
|
||||||
apparmor-profile-dist,
|
apparmor-profile-dist,
|
||||||
|
build-essential,
|
||||||
dmsetup,
|
dmsetup,
|
||||||
helper-scripts,
|
helper-scripts,
|
||||||
libcap2-bin,
|
libcap2-bin,
|
||||||
|
|
@ -27,6 +28,7 @@ Depends: adduser,
|
||||||
libpam-modules-bin,
|
libpam-modules-bin,
|
||||||
libpam-runtime,
|
libpam-runtime,
|
||||||
libpam-umask,
|
libpam-umask,
|
||||||
|
memlockd,
|
||||||
python3,
|
python3,
|
||||||
secure-delete,
|
secure-delete,
|
||||||
sudo,
|
sudo,
|
||||||
|
|
|
||||||
33
etc/security-misc/emerg-shutdown/30_security_misc.conf
Normal file
33
etc/security-misc/emerg-shutdown/30_security_misc.conf
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
## Copyright (C) 2025 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
|
||||||
|
## See the file COPYING for copying conditions.
|
||||||
|
|
||||||
|
## Please use "/etc/security-misc/emerg-shutdown/50_user.conf" for your custom
|
||||||
|
## configuration, which will override the defaults found here.
|
||||||
|
## When Kicksecure is updated, this file may be overwritten.
|
||||||
|
|
||||||
|
## Set the key combo for forcing immediate shutdown. See the "Keys and
|
||||||
|
## buttons" section of "/usr/include/linux/input-event-codes.h" for possibly
|
||||||
|
## supported values. Not all keys are supported.
|
||||||
|
##
|
||||||
|
## All specified keys must be depressed at the same time to trigger a
|
||||||
|
## shutdown. Use a comma (",") to separate keys. If you want to alias certain
|
||||||
|
## keys to each other from emerg-shutdown's standpoint, use a pipe
|
||||||
|
## character("|").
|
||||||
|
##
|
||||||
|
## The default key sequence triggers a shutdown when Ctrl+Alt+Delete is
|
||||||
|
## pressed, allowing the use of either the left or right Ctrl and Alt keys.
|
||||||
|
EMERG_SHUTDOWN_KEYS="KEY_LEFTCTRL|KEY_RIGHTCTRL,KEY_LEFTALT|KEY_RIGHTALT,KEY_DELETE"
|
||||||
|
|
||||||
|
## Set the maximum number of seconds shutdown can take. If shutdown gets stuck
|
||||||
|
## for longer than this, the system will forcibly power down.
|
||||||
|
##
|
||||||
|
## NOTE: This requires ensure-shutdown.service to be enabled, which is not
|
||||||
|
## done by default. Enabling ensure-shutdown.service will cause shutdown to
|
||||||
|
## always take at least as long as systemd's DefaultTimeoutStopSec (which by
|
||||||
|
## default is 90 seconds). If you are going to enable ensure-shutdown.service,
|
||||||
|
## it is highly recommended to set DefaultTimeoutStopSec to a much smaller
|
||||||
|
## value, such as 5 seconds. The maximum shutdown time set here should be at
|
||||||
|
## least 10 seconds *longer* than DefaultTimeoutStopSec, to give normal
|
||||||
|
## shutdown a chance to actually succeed before forcibly shutting down the
|
||||||
|
## system.
|
||||||
|
ENSURE_SHUTDOWN_TIMEOUT=30
|
||||||
|
|
@ -17,3 +17,7 @@ disable proc-hidepid.service
|
||||||
## Disable due to issues. See:
|
## Disable due to issues. See:
|
||||||
## https://github.com/Kicksecure/security-misc/issues/159
|
## https://github.com/Kicksecure/security-misc/issues/159
|
||||||
disable harden-module-loading.service
|
disable harden-module-loading.service
|
||||||
|
|
||||||
|
## Disable due to timing difficulties. See:
|
||||||
|
## https://github.com/systemd/systemd/issues/38261#issuecomment-3134580852
|
||||||
|
disable ensure-shutdown.service
|
||||||
|
|
|
||||||
14
usr/lib/systemd/system/emerg-shutdown.service
Normal file
14
usr/lib/systemd/system/emerg-shutdown.service
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
## Copyright (C) 2025 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
|
||||||
|
## See the file COPYING for copying conditions.
|
||||||
|
|
||||||
|
[Unit]
|
||||||
|
Description=Emergency shutdown when boot media is removed
|
||||||
|
Documentation=https://github.com/Kicksecure/security-misc
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=notify
|
||||||
|
ExecStart=/usr/libexec/security-misc/emerg-shutdown
|
||||||
|
NotifyAccess=main
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
18
usr/lib/systemd/system/ensure-shutdown.service
Normal file
18
usr/lib/systemd/system/ensure-shutdown.service
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
## Copyright (C) 2025 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
|
||||||
|
## See the file COPYING for copying conditions.
|
||||||
|
|
||||||
|
[Unit]
|
||||||
|
Description=Forcibly shut down the system if normal shutdown gets stuck
|
||||||
|
Documentation=https://github.com/Kicksecure/security-misc
|
||||||
|
Wants=emerg-shutdown.service
|
||||||
|
After=emerg-shutdown.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
RemainAfterExit=true
|
||||||
|
ExecStart=/usr/libexec/security-misc/ensure-shutdown
|
||||||
|
ExecStop=bash -c -- 'echo "d" > /run/emerg-shutdown-trigger'
|
||||||
|
KillMode=process
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
9
usr/lib/udev/rules.d/95-emerg-shutdown.rules
Normal file
9
usr/lib/udev/rules.d/95-emerg-shutdown.rules
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
SUBSYSTEM!="input", GOTO="end"
|
||||||
|
|
||||||
|
# new keyboard or mouse attached or removed, restart emerg-shutdown
|
||||||
|
KERNEL=="event*", ACTION=="add", ENV{ID_INPUT_KEYBOARD}=="1", RUN+="/usr/bin/systemctl restart emerg-shutdown.service"
|
||||||
|
KERNEL=="event*", ACTION=="add", ENV{ID_INPUT_KEYBOARD}=="1", GOTO="end"
|
||||||
|
KERNEL=="event*", ACTION=="remove", ENV{ID_INPUT_KEYBOARD}=="1", RUN+="/usr/bin/systemctl restart emerg-shutdown.service"
|
||||||
|
KERNEL=="event*", ACTION=="remove", ENV{ID_INPUT_KEYBOARD}=="1", GOTO="end"
|
||||||
|
|
||||||
|
LABEL="end"
|
||||||
52
usr/libexec/security-misc/emerg-shutdown
Executable file
52
usr/libexec/security-misc/emerg-shutdown
Executable file
|
|
@ -0,0 +1,52 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Copyright (C) 2025 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
|
||||||
|
# See the file COPYING for copying conditions.
|
||||||
|
|
||||||
|
set -o errexit
|
||||||
|
set -o nounset
|
||||||
|
set -o errtrace
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
|
## Make sure globs sort in a predictable, reproducible fashion
|
||||||
|
export LC_ALL=C
|
||||||
|
|
||||||
|
## Read emergency shutdown key configuration
|
||||||
|
for config_file in /etc/security-misc/emerg-shutdown/*.conf; do
|
||||||
|
source "${config_file}"
|
||||||
|
done
|
||||||
|
if [ -z "${EMERG_SHUTDOWN_KEYS}" ]; then
|
||||||
|
## Default to Ctrl+Alt+Delete if nothing else is set
|
||||||
|
EMERG_SHUTDOWN_KEYS="KEY_LEFTCTRL|KEY_RIGHTCTRL,KEY_LEFTALT|KEY_RIGHTALT,KEY_DELETE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Find the devices that make up the root device
|
||||||
|
readarray -t root_devices < <(/usr/libexec/helper-scripts/get-backing-devices-for-mountpoint '/') || true;
|
||||||
|
if [ "${#root_devices[@]}" = '0' ] \
|
||||||
|
|| [ "${root_devices[0]}" == '' ]; then
|
||||||
|
## /dev/sda1 might be the right one...
|
||||||
|
root_devices[0]='/dev/sda1'
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Build the actual emerg-shutdown executable
|
||||||
|
if [ ! -f '/run/emerg-shutdown' ]; then
|
||||||
|
gcc \
|
||||||
|
-o \
|
||||||
|
/run/emerg-shutdown \
|
||||||
|
-static \
|
||||||
|
/usr/src/security-misc/emerg-shutdown.c \
|
||||||
|
|| {
|
||||||
|
printf "%s\n" 'Could not compile force-shutdown executable!'
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
|
||||||
|
systemd-notify --ready
|
||||||
|
|
||||||
|
## memlockd daemonizes itself, so no need to background it.
|
||||||
|
memlockd -c /usr/share/security-misc/security-misc-memlockd.cfg || true
|
||||||
|
|
||||||
|
## Launch emerg-shutdown
|
||||||
|
OLDIFS="$IFS"
|
||||||
|
IFS=','
|
||||||
|
/run/emerg-shutdown "--devices=${root_devices[*]}" "--keys=${EMERG_SHUTDOWN_KEYS}"
|
||||||
28
usr/libexec/security-misc/ensure-shutdown
Executable file
28
usr/libexec/security-misc/ensure-shutdown
Executable file
|
|
@ -0,0 +1,28 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Copyright (C) 2025 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
|
||||||
|
# See the file COPYING for copying conditions.
|
||||||
|
|
||||||
|
set -o errexit
|
||||||
|
set -o nounset
|
||||||
|
set -o errtrace
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
|
source /usr/libexec/helper-scripts/strings.bsh
|
||||||
|
|
||||||
|
## Make sure globs sort in a predictable, reproducible fashion
|
||||||
|
export LC_ALL=C
|
||||||
|
|
||||||
|
## Read emergency shutdown key configuration
|
||||||
|
for config_file in /etc/security-misc/emerg-shutdown/*.conf; do
|
||||||
|
source "${config_file}"
|
||||||
|
done
|
||||||
|
if [ -z "${ENSURE_SHUTDOWN_TIMEOUT}" ] \
|
||||||
|
|| ! is_whole_number "${ENSURE_SHUTDOWN_TIMEOUT}"; then
|
||||||
|
ENSURE_SHUTDOWN_TIMEOUT=30;
|
||||||
|
fi
|
||||||
|
|
||||||
|
/run/emerg-shutdown --monitor-fifo "--timeout=${ENSURE_SHUTDOWN_TIMEOUT}" &
|
||||||
|
sleep 1
|
||||||
|
disown
|
||||||
|
exit 0
|
||||||
2
usr/share/security-misc/security-misc-memlockd.cfg
Normal file
2
usr/share/security-misc/security-misc-memlockd.cfg
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
# Lock systemd and all of its library dependencies into memory
|
||||||
|
+/usr/bin/systemd
|
||||||
1006
usr/src/security-misc/emerg-shutdown.c
Normal file
1006
usr/src/security-misc/emerg-shutdown.c
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue