Skip to content

Commit fcdad08

Browse files
committed
Merge remote-tracking branch 'origin/pr/731'
* origin/pr/731: Prevent backing up dom0 to itself (in home dir)
2 parents 44aea37 + 301e66f commit fcdad08

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
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 ["", "~"] 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: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import sys
3030

3131
import asyncio
32+
import grp
33+
import pwd
3234

3335
import qubes
3436
import qubes.backup
@@ -198,7 +200,9 @@ def make_backup(self, vms, target=None, expect_failure=False, **kwargs):
198200
if target is None:
199201
target = self.backupdir
200202
try:
201-
backup = qubes.backup.Backup(self.app, vms, **kwargs)
203+
backup = qubes.backup.Backup(
204+
self.app, vms, target_dir=target, **kwargs
205+
)
202206
except qubes.exc.QubesException as e:
203207
if not expect_failure:
204208
self.fail("QubesException during backup_prepare: %s" % str(e))
@@ -207,7 +211,6 @@ def make_backup(self, vms, target=None, expect_failure=False, **kwargs):
207211

208212
if "passphrase" not in kwargs:
209213
backup.passphrase = "qubes"
210-
backup.target_dir = target
211214

212215
try:
213216
self.loop.run_until_complete(backup.backup_do())
@@ -575,6 +578,21 @@ def test_100_backup_dom0_no_restore(self):
575578
self.make_backup([self.app.domains[0]])
576579
# TODO: think of some safe way to test restore...
577580

581+
def test_101_backup_dom0_to_dom0_home(self):
582+
# Assure backing up dom0 to dom0 home itself is refused...
583+
local_user = grp.getgrnam("qubes").gr_mem[0]
584+
home_dir = pwd.getpwnam(local_user).pw_dir
585+
with self.assertRaises(qubes.exc.QubesException):
586+
self.make_backup(
587+
[self.app.domains[0]], target=home_dir, expect_failure=True
588+
)
589+
with self.assertRaises(qubes.exc.QubesException):
590+
self.make_backup(
591+
[self.app.domains[0]],
592+
target=os.path.join(home_dir, "somedir"),
593+
expect_failure=True,
594+
)
595+
578596
def test_200_restore_over_existing_directory(self):
579597
"""
580598
Regression test for #1386

0 commit comments

Comments
 (0)