Skip to content

incusd/device/unix_hotplug: Prevent duplicate uevent injection#2679

Merged
stgraber merged 1 commit intolxc:mainfrom
zgttotev:uevents
Nov 21, 2025
Merged

incusd/device/unix_hotplug: Prevent duplicate uevent injection#2679
stgraber merged 1 commit intolxc:mainfrom
zgttotev:uevents

Conversation

@zgttotev
Copy link
Copy Markdown
Contributor

@zgttotev zgttotev commented Nov 20, 2025

Duplicate remove uevents are injected into LXC containers when more than one unix-hotplug device is configured. The add uevent has a guard for the correct vendor/product device uevents but this doesn't work with remove because it lacks these fields. But, if no devices are marked for unmounting, we can exit early and avoid duplication.

Example scenario: two unix-hotplugs where one matches the hidraw0 device
Before (container udevadm monitor -k):

KERNEL[1297805.870598] add      /devices/platform/vhci_hcd.0/usb1/1-2 (usb)
KERNEL[1297805.972898] add      /devices/platform/vhci_hcd.0/usb1/1-2/1-2:1.0/0003:1050:0402.0008/hidraw/hidraw0 (hidraw)

KERNEL[1297728.343559] remove   /devices/platform/vhci_hcd.0/usb1/1-2/1-2:1.0/usbmisc/hiddev0 (usbmisc)
KERNEL[1297728.355734] remove   /devices/platform/vhci_hcd.0/usb1/1-2/1-2:1.0/usbmisc/hiddev0 (usbmisc)
KERNEL[1297728.410647] remove   /devices/platform/vhci_hcd.0/usb1/1-2/1-2:1.0/0003:1050:0402.0007/hidraw/hidraw0 (hidraw)
KERNEL[1297728.424289] remove   /devices/platform/vhci_hcd.0/usb1/1-2/1-2:1.0/0003:1050:0402.0007/hidraw/hidraw0 (hidraw)
KERNEL[1297728.559130] remove   /devices/platform/vhci_hcd.0/usb1/1-2 (usb)
KERNEL[1297728.593145] remove   /devices/platform/vhci_hcd.0/usb1/1-2 (usb)

After:

KERNEL[1302813.707669] add      /devices/platform/vhci_hcd.0/usb1/1-1 (usb)
KERNEL[1302813.796387] add      /devices/platform/vhci_hcd.0/usb1/1-1/1-1:1.0/0003:1050:0402.000C/hidraw/hidraw0 (hidraw)

KERNEL[1302839.881288] remove   /devices/platform/vhci_hcd.0/usb1/1-1/1-1:1.0/0003:1050:0402.000C/hidraw/hidraw0 (hidraw)
KERNEL[1302839.968908] remove   /devices/platform/vhci_hcd.0/usb1/1-1 (usb)

Duplicate remove uevents are injected into LXC containers when more than
one unix-hotplug device is configured. The add uevent has a guard for
the correct vendor/product device uevents but this doesn't work with
remove because it lacks these fields. But, if no devices are marked for
unmounting, we can exit early and avoid duplication.

Example scenario: two unix-hotplugs where one matches the hidraw0 device
Before (container udevadm monitor -k):

KERNEL[1297805.870598] add      /devices/platform/vhci_hcd.0/usb1/1-2 (usb)
KERNEL[1297805.972898] add      /devices/platform/vhci_hcd.0/usb1/1-2/1-2:1.0/0003:1050:0402.0008/hidraw/hidraw0 (hidraw)

KERNEL[1297728.343559] remove   /devices/platform/vhci_hcd.0/usb1/1-2/1-2:1.0/usbmisc/hiddev0 (usbmisc)
KERNEL[1297728.355734] remove   /devices/platform/vhci_hcd.0/usb1/1-2/1-2:1.0/usbmisc/hiddev0 (usbmisc)
KERNEL[1297728.410647] remove   /devices/platform/vhci_hcd.0/usb1/1-2/1-2:1.0/0003:1050:0402.0007/hidraw/hidraw0 (hidraw)
KERNEL[1297728.424289] remove   /devices/platform/vhci_hcd.0/usb1/1-2/1-2:1.0/0003:1050:0402.0007/hidraw/hidraw0 (hidraw)
KERNEL[1297728.559130] remove   /devices/platform/vhci_hcd.0/usb1/1-2 (usb)
KERNEL[1297728.593145] remove   /devices/platform/vhci_hcd.0/usb1/1-2 (usb)

After:

KERNEL[1302813.707669] add      /devices/platform/vhci_hcd.0/usb1/1-1 (usb)
KERNEL[1302813.796387] add      /devices/platform/vhci_hcd.0/usb1/1-1/1-1:1.0/0003:1050:0402.000C/hidraw/hidraw0 (hidraw)

KERNEL[1302839.881288] remove   /devices/platform/vhci_hcd.0/usb1/1-1/1-1:1.0/0003:1050:0402.000C/hidraw/hidraw0 (hidraw)
KERNEL[1302839.968908] remove   /devices/platform/vhci_hcd.0/usb1/1-1 (usb)

Signed-off-by: Gabriel Totev <[email protected]>
@zgttotev zgttotev requested a review from stgraber as a code owner November 20, 2025 23:49
@stgraber stgraber merged commit 8babc46 into lxc:main Nov 21, 2025
36 of 38 checks passed
@zgttotev zgttotev deleted the uevents branch November 21, 2025 02:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants