-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remount /home /tmp /dev/shm /run with nosuid,nodev (default) and noex…
- Loading branch information
Patrick Schleizer
committed
Dec 6, 2019
1 parent
8cf5ed9
commit 470cad6
Showing
3 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
## Copyright (C) 2012 - 2019 ENCRYPTED SUPPORT LP <adrelanos@riseup.net> | ||
## See the file COPYING for copying conditions. | ||
|
||
[Unit] | ||
Description=remount /home /tmp /dev/shm /run with nosuid,nodev (default) and noexec (opt-in) | ||
Documentation=https://github.com/Whonix/security-misc | ||
DefaultDependencies=no | ||
Before=sysinit.target | ||
Requires=local-fs.target | ||
After=local-fs.target | ||
|
||
[Service] | ||
Type=oneshot | ||
ExecStart=/usr/lib/security-misc/remount-secure | ||
|
||
[Install] | ||
WantedBy=sysinit.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/bin/bash | ||
|
||
## Copyright (C) 2019 - 2019 ENCRYPTED SUPPORT LP <adrelanos@riseup.net> | ||
## See the file COPYING for copying conditions. | ||
|
||
## noexec in /tmp and/or /home can break some malware but also legitimate | ||
## applications. | ||
|
||
set -e | ||
|
||
if [ -f /usr/lib/helper-scripts/pre.bsh ]; then | ||
## pre.bsh would `source` the following folders: | ||
## /etc/remount-secure_pre.d/*.conf | ||
## /usr/local/etc/remount-secure_pre.d/*.conf | ||
source /usr/lib/helper-scripts/pre.bsh | ||
fi | ||
|
||
if [ -e /etc/remount-disable ]; then | ||
echo "$0: /etc/remount-disable exists. Doing nothing." | ||
exit 0 | ||
fi | ||
|
||
if [ -e /etc/noexec ]; then | ||
noexec=true | ||
echo "$0: Will remount with noexec." | ||
exit 0 | ||
fi | ||
|
||
mkdir --parents "/var/run/remount-secure" | ||
|
||
if [ "$noexec" = "true" ]; then | ||
noexec_maybe=",noexec" | ||
fi | ||
|
||
exit_code=0 | ||
|
||
home() { | ||
if [ -e "/var/run/remount-secure/${FUNCNAME}" ]; then | ||
return 0 | ||
fi | ||
mount -o remount,nosuid,nodev$noexec_maybe /home || exit_code=2 | ||
touch "/var/run/remount-secure/${FUNCNAME}" | ||
} | ||
|
||
run() { | ||
if [ -e "/var/run/remount-secure/${FUNCNAME}" ]; then | ||
return 0 | ||
fi | ||
## https://lists.freedesktop.org/archives/systemd-devel/2015-February/028456.html | ||
mount -o remount,nosuid,nodev$noexec_maybe /run || exit_code=3 | ||
touch "/var/run/remount-secure/${FUNCNAME}" | ||
} | ||
|
||
shm() { | ||
if [ -e "/var/run/remount-secure/${FUNCNAME}" ]; then | ||
return 0 | ||
fi | ||
mount -o remount,nosuid,nodev$noexec_maybe /dev/shm || exit_code=4 | ||
touch "/var/run/remount-secure/${FUNCNAME}" | ||
} | ||
|
||
tmp() { | ||
if [ -e "/var/run/remount-secure/${FUNCNAME}" ]; then | ||
return 0 | ||
fi | ||
mount -o nosuid,nodev$noexec_maybe --bind /tmp /tmp || exit_code=5 | ||
touch "/var/run/remount-secure/${FUNCNAME}" | ||
} | ||
|
||
end() { | ||
exit $exit_code | ||
} | ||
|
||
main() { | ||
home "$@" | ||
run "$@" | ||
shm "$@" | ||
tmp "$@" | ||
end "$@" | ||
} | ||
|
||
main "$@" |