Skip to content

Commit

Permalink
q-dev: do not attach unknown device
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrbartman committed Oct 15, 2024
1 parent 1999c2f commit d76b318
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions qubes/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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.')

Expand All @@ -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(
Expand Down

0 comments on commit d76b318

Please sign in to comment.