Skip to content

Commit e802ee9

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

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

qubes/backup.py

Lines changed: 9 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,14 @@ 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).is_relative_to(home_dir):
460+
raise qubes.exc.QubesException(
461+
"Can not backup dom0 home directory to itself!"
462+
)
463+
455464
# Home dir should have only user-owned files, so fix it now
456465
# to prevent permissions problems - some root-owned files can
457466
# left after 'sudo bash' and similar commands

qubes/tests/integ/backup.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,12 @@ def make_backup(self, vms, target=None, expect_failure=False, **kwargs):
198198
if target is None:
199199
target = self.backupdir
200200
try:
201-
backup = qubes.backup.Backup(self.app, vms, **kwargs)
201+
backup = qubes.backup.Backup(
202+
self.app,
203+
vms,
204+
target_dir=target,
205+
**kwargs
206+
)
202207
except qubes.exc.QubesException as e:
203208
if not expect_failure:
204209
self.fail("QubesException during backup_prepare: %s" % str(e))
@@ -575,6 +580,14 @@ def test_100_backup_dom0_no_restore(self):
575580
self.make_backup([self.app.domains[0]])
576581
# TODO: think of some safe way to test restore...
577582

583+
def test_101_backup_dom0_to_homedir(self):
584+
# Test of backup into dom0 home itself results in error...
585+
with self.assertRaises(qubes.exc.QubesException):
586+
self.make_backup([self.app.domains[0]])
587+
with self.assertRaises(qubes.exc.QubesException):
588+
self.backupdir = os.environ["HOME"]
589+
self.make_backup([self.app.domains[0]])
590+
578591
def test_200_restore_over_existing_directory(self):
579592
"""
580593
Regression test for #1386

0 commit comments

Comments
 (0)