This commit is contained in:
2026-02-19 16:51:32 +01:00
parent 14a9e87423
commit 54178dce75
5 changed files with 50 additions and 17 deletions
+25 -5
View File
@@ -42,7 +42,10 @@ func createVHCIAttachment(_ context.Context, granted *protocol.DeviceGranted, _
return nil, -1, fmt.Errorf("VHCI attach: %w", err)
}
// The VHCI driver now owns vhciFD, so we don't close it
// The VHCI driver holds a kernel reference to the socket via sockfd_lookup,
// so we can close our copy of the fd to avoid leaking it.
unix.Close(vhciFD)
// Create a net.Conn from the tunnel FD
tunnelFile := fdToFile(tunnelFD, "usb-tunnel")
tunnelConn, err := net.FileConn(tunnelFile)
@@ -74,9 +77,9 @@ func fdToFile(fd int, name string) *os.File {
}
// fixVHCIDevicePermissions waits for the VHCI-attached device to create
// device nodes (e.g. /dev/video*) and sets them to world-accessible.
// VHCI-created devices don't get normal udev rules applied, so they
// default to root-only access.
// device nodes (e.g. /dev/video*, /dev/input/event*, /dev/hidraw*) and sets
// them to world-accessible. VHCI-created devices don't get normal udev
// rules applied, so they default to root-only access.
func fixVHCIDevicePermissions(port int) {
// Wait for the device to finish enumerating and create device nodes.
// The kernel needs time to enumerate descriptors and bind drivers.
@@ -101,12 +104,13 @@ func fixVHCIDevicePermissions(port int) {
if err := os.Chmod(devPath, 0666); err == nil {
log.Printf("[use] set permissions 0666 on %s", devPath)
found = true
} else {
log.Printf("[use] chmod %s failed: %v", devPath, err)
}
}
// sound devices → /dev/snd/*
if parent == "sound" && strings.HasPrefix(d.Name(), "card") {
// For sound cards, chmod all related device nodes
sndDir := filepath.Join(path, "device")
if _, err := os.Stat(sndDir); err == nil {
filepath.WalkDir("/dev/snd", func(sndPath string, sd os.DirEntry, err error) error {
@@ -123,6 +127,20 @@ func fixVHCIDevicePermissions(port int) {
devPath := "/dev/input/" + d.Name()
if err := os.Chmod(devPath, 0666); err == nil {
log.Printf("[use] set permissions 0666 on %s", devPath)
found = true
} else {
log.Printf("[use] chmod %s failed: %v", devPath, err)
}
}
// hidraw devices → /dev/hidrawN
if parent == "hidraw" && strings.HasPrefix(d.Name(), "hidraw") {
devPath := "/dev/" + d.Name()
if err := os.Chmod(devPath, 0666); err == nil {
log.Printf("[use] set permissions 0666 on %s", devPath)
found = true
} else {
log.Printf("[use] chmod %s failed: %v", devPath, err)
}
}
@@ -133,4 +151,6 @@ func fixVHCIDevicePermissions(port int) {
return
}
}
log.Printf("[use] fixVHCIDevicePermissions: no device nodes found after 7.5s (port %d)", port)
}