Skip to content

Commit 039514b

Browse files
committed
Prevent backing up dom0 to itself (in home dir)
resolves: QubesOS/qubes-issues#10127
1 parent a930d4e commit 039514b

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

qubes/backup.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import itertools
2929
import logging
3030
import os
31+
from pathlib import Path
3132
import pwd
3233
import shutil
3334
import stat
@@ -452,6 +453,15 @@ def get_files_to_backup(self):
452453
if 0 in [vm.qid for vm in self.vms_for_backup]:
453454
local_user = grp.getgrnam("qubes").gr_mem[0]
454455
home_dir = pwd.getpwnam(local_user).pw_dir
456+
457+
# Checking if target is not user home directory in dom0
458+
if self.target_dir in ["", "~", None] \
459+
or Path(self.target_dir) == Path(home_dir) \
460+
or Path(home_dir) in Path(self.target_dir).parents:
461+
raise qubes.exc.QubesException(
462+
"Can not backup dom0 home directory to itself!"
463+
)
464+
455465
# Home dir should have only user-owned files, so fix it now
456466
# to prevent permissions problems - some root-owned files can
457467
# left after 'sudo bash' and similar commands

qubes/tests/integ/backup.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,11 @@ def test_100_backup_dom0_no_restore(self):
575575
self.make_backup([self.app.domains[0]])
576576
# TODO: think of some safe way to test restore...
577577

578+
def test_101_backup_dom0_to_homedir(self):
579+
# Test of backup into dom0 home itself results in error...
580+
with self.assertRaises(qubes.exc.QubesException):
581+
self.make_backup([self.app.domains[0]])
582+
578583
def test_200_restore_over_existing_directory(self):
579584
"""
580585
Regression test for #1386

0 commit comments

Comments
 (0)