Skip to content

Commit 98a9903

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

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

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 ["", "~"] or Path(
459+
self.target_dir
460+
).is_relative_to(home_dir):
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: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ 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, vms, target_dir=target, **kwargs
203+
)
202204
except qubes.exc.QubesException as e:
203205
if not expect_failure:
204206
self.fail("QubesException during backup_prepare: %s" % str(e))
@@ -207,7 +209,6 @@ def make_backup(self, vms, target=None, expect_failure=False, **kwargs):
207209

208210
if "passphrase" not in kwargs:
209211
backup.passphrase = "qubes"
210-
backup.target_dir = target
211212

212213
try:
213214
self.loop.run_until_complete(backup.backup_do())
@@ -575,6 +576,17 @@ def test_100_backup_dom0_no_restore(self):
575576
self.make_backup([self.app.domains[0]])
576577
# TODO: think of some safe way to test restore...
577578

579+
def test_101_backup_dom0_to_dom0_home(self):
580+
# Assure backing up dom0 to dom0 home itself is refused...
581+
local_user = grp.getgrnam("qubes").gr_mem[0]
582+
home_dir = pwd.getpwnam(local_user).pw_dir
583+
with self.assertRaises(qubes.exc.QubesException):
584+
self.make_backup([self.app.domains[0]], target=home_dir)
585+
with self.assertRaises(qubes.exc.QubesException):
586+
self.make_backup(
587+
[self.app.domains[0]], target=os.path.join(home_dir, "somedir")
588+
)
589+
578590
def test_200_restore_over_existing_directory(self):
579591
"""
580592
Regression test for #1386

0 commit comments

Comments
 (0)