Update vm-sudo-protect.sh

Avoids using fstab mountpoint and enables using `vm-sudo-protect-root` as Qubes service.
This commit is contained in:
tasket 2017-04-20 19:33:44 -04:00 committed by GitHub
parent 8dfdc2150e
commit b3f46e3307

View File

@ -1,5 +1,8 @@
#!/bin/sh
## Protect startup of Qubes VMs from /rw scripts ##
## https://github.com/tasket/Qubes-VM-hardening ##
# Define sh, bash, X and desktop init scripts
# to be protected
chfiles=".bashrc .bash_profile .bash_login .bash_logout .profile \
@ -7,8 +10,9 @@ chfiles=".bashrc .bash_profile .bash_login .bash_logout .profile \
chdirs=".config/autostart .config/plasma-workspace/env .config/plasma-workspace/shutdown \
.config/autostart-scripts"
mkdir -p /rw
if [ -e /dev/xvdb ] && mount /rw ; then
rw=/mnt/rwtmp
mkdir -p $rw
if [ -e /dev/xvdb ] && mount /dev/xvdb $rw ; then
echo Good rw mount.
else
exit 0
@ -18,12 +22,12 @@ fi
# Activated by presence of /etc/defaults/vms/vms.all dir.
# Contents of vms/vms.all and vms/hostname will be copied.
defdir="/etc/default/vms"
rootdirs="/rw/config /rw/usrlocal /rw/bind-dirs"
if [ -d $defdir/vms.all ] && [ `qubesdb-read /qubes-vm-persistence` = "rw-only" ]; then
rootdirs="$rw/config $rw/usrlocal $rw/bind-dirs"
if [ -e /var/run/qubes-service/vm-sudo-protect-root ] && [ `qubesdb-read /qubes-vm-persistence` = "rw-only" ]; then
rm -rf $rootdirs
# make user scripts temporarily mutable, in case 'rw/home/user'
# files exist in defdir...
cd /rw/home/user
cd $rw/home/user
chattr -R -f -i $chfiles $chdirs || true
# copy..
cp -af $defdir/vms.all/* / || true
@ -33,11 +37,11 @@ if [ -d $defdir/vms.all ] && [ `qubesdb-read /qubes-vm-persistence` = "rw-only"
fi
# Make user scripts immutable
cd /rw/home/user
cd $rw/home/user
mkdir -p $chdirs ||true
touch $chfiles || true
chattr -R -f +i $chfiles $chdirs || true
touch /rw/home/user/FIXED || true
touch $rw/home/user/FIXED || true
cd /
umount /rw
umount $rw && rmdir $rw