Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pr/541'
Browse files Browse the repository at this point in the history
* origin/pr/541:
  Relabel / and /rw if needed
  • Loading branch information
marmarek committed Jan 26, 2025
2 parents 70f5e44 + 31bb12a commit e1d1a5e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ install-init:
install -m 0644 init/functions $(DESTDIR)$(LIBDIR)/qubes/init/
ifneq ($(ENABLE_SELINUX),1)
rm -f $(DESTDIR)$(LIBDIR)/qubes/init/relabel-root.sh
rm -f $(DESTDIR)$(LIBDIR)/qubes/init/relabel-rw.sh
endif

# Systemd service files
Expand Down
12 changes: 12 additions & 0 deletions init/relabel-rw.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash --
set -eu
unset SELINUXTYPE
if [ -f /etc/selinux/config ]; then
# shellcheck disable=SC1091
. /etc/selinux/config
fi
ctx_file=/etc/selinux/${SELINUXTYPE:-targeted}/contexts/files/file_contexts
if [ "$ctx_file" -nt /rw/.autorelabel ]; then
restorecon -R /rw
touch "--reference=$ctx_file" /rw/.autorelabel
fi
1 change: 1 addition & 0 deletions rpm_spec/core-agent.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ a VM with SELinux enforcing, as is the default on Red Hat-family distributions.
%dir %_unitdir/selinux-autorelabel.service.d
%_unitdir/selinux-autorelabel.service.d/30_qubes.conf
/usr/lib/qubes/init/relabel-root.sh
/usr/lib/qubes/init/relabel-rw.sh

%postun selinux
if [ "$1" -eq 0 ]; then
Expand Down
3 changes: 2 additions & 1 deletion vm-systemd/qubes-relabel-root.service
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Description=Relabel /
After=qubes-sysinit.service
Requires=qubes-sysinit.service
ConditionSecurity=selinux
ConditionPathExists=!/.qubes-relabeled
ConditionPathExists=|/.autorelabel
ConditionPathExists=|!/.qubes-relabeled
ConditionPathExists=/run/qubes/persistent-full
DefaultDependencies=no
Conflicts=shutdown.target
Expand Down
8 changes: 3 additions & 5 deletions vm-systemd/qubes-relabel-rw.service
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
[Unit]
Description=Relabel /rw and /home
After=qubes-mount-dirs.service qubes-sysinit.service
Requires=qubes-mount-dirs.service qubes-sysinit.service
After=qubes-mount-dirs.service qubes-sysinit.service qubes-relabel-root.service
Requires=qubes-mount-dirs.service qubes-sysinit.service qubes-relabel-root.service
ConditionSecurity=selinux
ConditionPathExists=!/rw/.autorelabel
DefaultDependencies=no
Conflicts=selinux-autorelabel.service
Before=local-fs.target rw.mount home.mount qubes-gui-agent.service qubes-qrexec-agent.service

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/sbin/restorecon -RF /rw /home /usr/local
ExecStart=/bin/touch /rw/.autorelabel
ExecStart=/usr/lib/qubes/init/relabel-rw.sh

[Install]
WantedBy=multi-user.target

0 comments on commit e1d1a5e

Please sign in to comment.