Skip to content

Commit

Permalink
Validate default_kernel global property on set
Browse files Browse the repository at this point in the history
  • Loading branch information
alimirjamali committed Aug 18, 2024
1 parent a1a023b commit 31daa6c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
29 changes: 28 additions & 1 deletion qubes/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,6 @@ def _default_pool(app):
return pool
raise AttributeError('Cannot determine default storage pool')


def _setter_pool(app, prop, value):
if isinstance(value, qubes.storage.Pool):
return value
Expand Down Expand Up @@ -674,6 +673,27 @@ def _setter_default_netvm(app, prop, value):
return value


def _validate_kernel(obj, name, kernel):
if not kernel:
return
dirname = os.path.join(
qubes.config.qubes_base_dir,
qubes.config.system_path['qubes_kernels_base_dir'],
kernel)
if not os.path.exists(dirname):
raise qubes.exc.QubesPropertyValueError(
obj, name, kernel,
'Kernel {!r} not installed'.format(
kernel))
for filename in ('vmlinuz',):
if not os.path.exists(os.path.join(dirname, filename)):
raise qubes.exc.QubesPropertyValueError(
obj, name, kernel,
'Kernel {!r} not properly installed: '
'missing {!r} file'.format(
kernel, filename))


class Qubes(qubes.PropertyHolder):
"""Main Qubes application
Expand Down Expand Up @@ -1593,3 +1613,10 @@ def on_property_set_default_dispvm(self, event, name, newvalue,
# resetting dispvm to its default value
vm.fire_event('property-reset:default_dispvm',
name='default_dispvm', oldvalue=oldvalue)

@qubes.events.handler('property-pre-set:default_kernel')
# pylint: disable-next=invalid-name
def on_property_pre_set_default_kernel(self, event, name, newvalue,
oldvalue=None):
# pylint: disable=unused-argument
_validate_kernel(self, 'default_kernel', newvalue)
16 changes: 16 additions & 0 deletions run-tests
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ if sudo --non-interactive "$name/ci/lvm-manage" setup-lvm vg$$/pool; then
CLEANUP_LVM=yes
fi

CLEANUP_KERNEL_POOL=
if [ ! -d "/var/lib/qubes/vm-kernels" ]; then
sudo mkdir --parents /var/lib/qubes/vm-kernels/dummy
sudo touch /var/lib/qubes/vm-kernels/dummy/vmlinuz
sudo mkdir --parents /var/lib/qubes/vm-kernels/1.0
sudo touch /var/lib/qubes/vm-kernels/1.0/vmlinuz
CLEANUP_KERNEL_POOL=yes
fi

: "${PYTHON:=python3}"
: "${TESTPYTHONPATH:=test-packages}"

Expand All @@ -32,6 +41,13 @@ export PYTHONPATH
"${PYTHON}" setup.py egg_info --egg-base "${TESTPYTHONPATH}"
"${PYTHON}" -m coverage run --rcfile=ci/coveragerc -m qubes.tests.run "$@"
retcode=$?
if [ -n "$CLEANUP_KERNEL_POOL" ]; then
sudo rm /var/lib/qubes/vm-kernels/dummy/vmlinuz
sudo rmdir /var/lib/qubes/vm-kernels/dummy
sudo rm /var/lib/qubes/vm-kernels/1.0/vmlinuz
sudo rmdir /var/lib/qubes/vm-kernels/1.0
sudo rmdir /var/lib/qubes/vm-kernels
fi
if [ -n "$CLEANUP_LVM" ]; then
sudo --non-interactive $(dirname "$0")/ci/lvm-manage cleanup-lvm "$DEFAULT_LVM_POOL"
fi
Expand Down

0 comments on commit 31daa6c

Please sign in to comment.