From d76b3186c493b89d3ff2b32e50c6aec665c40006 Mon Sep 17 00:00:00 2001 From: Piotr Bartman-Szwarc Date: Mon, 30 Sep 2024 11:27:20 +0200 Subject: [PATCH] q-dev: do not attach unknown device --- qubes/devices.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/qubes/devices.py b/qubes/devices.py index 61890e4ef..6bc2adc5f 100644 --- a/qubes/devices.py +++ b/qubes/devices.py @@ -66,7 +66,7 @@ from qubes.device_protocol import (Port, DeviceInfo, UnknownDevice, DeviceAssignment, VirtualDevice, AssignmentMode) - +from qubes.exc import ProtocolError DEVICE_DENY_LIST = "/etc/qubes/device-deny.list" @@ -197,7 +197,7 @@ async def attach(self, assignment: DeviceAssignment): """ if assignment.devclass != self._bus: - raise ValueError( + raise ProtocolError( f'Trying to attach {assignment.devclass} device ' f'when {self._bus} device expected.') @@ -207,10 +207,15 @@ async def attach(self, assignment: DeviceAssignment): " do you mean `assign`?") if len(assignment.devices) != 1: - raise ValueError( + raise ProtocolError( f'Cannot attach ambiguous {assignment.devclass} device.') device = assignment.device + + if isinstance(device, UnknownDevice): + raise ProtocolError(f"{device.devclass} device not recognized " + f"in {device.port_id} port.") + if device in [ass.device for ass in self.get_attached_devices()]: raise DeviceAlreadyAttached( 'device {!s} of class {} already attached to {!s}'.format(