Bug 269729 - sysutils/nut USB permissions issue
Summary: sysutils/nut USB permissions issue
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Cy Schubert
URL:
Keywords:
: 275659 (view as bug list)
Depends on:
Blocks:
 
Reported: 2023-02-21 07:28 UTC by Denny Page
Modified: 2023-12-11 05:57 UTC (History)
3 users (show)

See Also:
bugzilla: maintainer-feedback? (cy)


Attachments
APC Smart-UPS1000 patch (1.96 KB, patch)
2023-02-21 21:13 UTC, Cy Schubert
no flags Details | Diff
Add uhid ignore quirk for APC UPS1000 (3.00 KB, patch)
2023-02-22 02:43 UTC, Cy Schubert
no flags Details | Diff
Correct patch (3.01 KB, patch)
2023-02-22 03:11 UTC, Cy Schubert
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Denny Page 2023-02-21 07:28:31 UTC
I maintain the NUT package for pfSense and have run into an issue with USB permissions for some UPS models. 

NB: My testing is against nut-2.8.0_13, but I haven't seen anything suggesting that the issue is resolved in later port revisions.

The permission problem arrises from the fact that the kernel attaches a driver to the device during initialization, and this subsequently prevents the device from being opened by usbhid-ups. The error reported is "Can't claim USB device"

The following demonstrates the specifics:

-----
[23.01-RELEASE][root@fw]/root: usbconfig -d ugen0.2 show_ifdrv
ugen0.2: <American Power Conversion Smart-UPS1000 FW:UPS 16.0 / ID1047> at usbus0, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON (10mA)
ugen0.2.0: uhid0: <American Power Conversion Smart-UPS1000 FW:UPS 16.0 / ID1047, class 0/0, rev 2.00/0.01, addr 4>

[23.01-RELEASE][root@fw]/root: /usr/local/libexec/nut/usbhid-ups -a ups
Network UPS Tools - Generic HID driver 0.47 (2.8.0)
USB communication driver (libusb 1.0) 0.43
interrupt pipe disabled (add 'pollonly' flag to 'ups.conf' to get rid of this message)
Can't claim USB device [051d:0003]@0/0: Other error

[23.01-RELEASE][root@fw]/root: usbconfig -d ugen0.2 detach_kernel_driver

[23.01-RELEASE][root@fw]/root: usbconfig -d ugen0.2 show_ifdrv
ugen0.2: <American Power Conversion Smart-UPS1000 FW:UPS 16.0 / ID1047> at usbus0, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON (10mA)

[23.01-RELEASE][root@fw]/root: /usr/local/libexec/nut/usbhid-ups -a ups
Network UPS Tools - Generic HID driver 0.47 (2.8.0)
USB communication driver (libusb 1.0) 0.43
interrupt pipe disabled (add 'pollonly' flag to 'ups.conf' to get rid of this message)
Using subdriver: APC HID 0.98

[23.01-RELEASE][root@fw]/root: 
-----

As you would expect, if the "-u root" option is added to usbhid-ups then it will succeed even if the kernel driver is currently attached.

I note that this permission issue is also present in the truss outputs in bug #267144
Comment 1 Denny Page 2023-02-21 20:48:47 UTC
Looks like it is indeed a missing quirk definition in the kernel. As noted previously, newer APC UPSs use product id 0x0003 rather than 0x0002. I'll get a PR up.
Comment 2 Cy Schubert freebsd_committer freebsd_triage 2023-02-21 21:13:00 UTC
Created attachment 240309 [details]
APC Smart-UPS1000 patch

Can you try this, please.
Comment 3 Denny Page 2023-02-22 01:52:24 UTC
(In reply to Cy Schubert from comment #2)

Hi Cy, thank you for your reply.

Unfortunately I am not able to directly produce a kernel build for pfSense, so I don't have a mechanism to directly try the patch.

However, if the patch results in the same quirk as this command

  usbconfig add_dev_quirk_vlph 0x051d 0x0003 0x0000 0xffff UQ_HID_IGNORE

then it should work.

I'm expecting to see this as the quirk list for APC:

  [23.01-RELEASE][root@fw]/root: usbconfig dump_device_quirks | grep 0x051d
  VID=0x051d PID=0x0002 REVLO=0x0000 REVHI=0xffff QUIRK=UQ_HID_IGNORE
  VID=0x051d PID=0x0003 REVLO=0x0000 REVHI=0xffff QUIRK=UQ_HID_IGNORE
  [23.01-RELEASE][root@fw]/root: 

Thanks,
Denny
Comment 4 Cy Schubert freebsd_committer freebsd_triage 2023-02-22 02:21:30 UTC
(In reply to Denny Page from comment #3)

The patch wasn't intended to add a quirk. It added a USB device recognition entry.

Do you have any documentation about the device to tell us which quirk bits to set?
Comment 5 Denny Page 2023-02-22 02:31:15 UTC
(In reply to Cy Schubert from comment #4)

> The patch wasn't intended to add a quirk. It added a USB device recognition entry.

Apologies, I didn't understand what to do with it then.


> Do you have any documentation about the device to tell us which quirk bits to set?

Exactly the same as the prior generation devices. The devices are just the newer generation of APC UPSs. Last year or two.

The only quirk necessary (at least in my testing) is that the device should be ignored by the hid class. This is exactly the same as the prior generation of APC UPS devices.

In this example

  [23.01-RELEASE][root@fw]/root: usbconfig dump_device_quirks | grep 0x051d
  VID=0x051d PID=0x0002 REVLO=0x0000 REVHI=0xffff QUIRK=UQ_HID_IGNORE
  VID=0x051d PID=0x0003 REVLO=0x0000 REVHI=0xffff QUIRK=UQ_HID_IGNORE
  [23.01-RELEASE][root@fw]/root: 

The first quirk is for the prior generation UPS devices, and the second quirk is for the new generation of devices.

Does this make sense?
Comment 6 Cy Schubert freebsd_committer freebsd_triage 2023-02-22 02:43:31 UTC
Created attachment 240317 [details]
Add uhid ignore quirk for APC UPS1000

Try this patch,
Comment 7 Denny Page 2023-02-22 03:00:25 UTC
Comment on attachment 240317 [details]
Add uhid ignore quirk for APC UPS1000

I believe the second patch should be adjusted like so:

--
diff --git a/sys/dev/usb/usbdevs b/sys/dev/usb/usbdevs
index 5a369cdb9df4..1b20d1821c7e 100644
--- a/sys/dev/usb/usbdevs
+++ b/sys/dev/usb/usbdevs
@@ -1097,6 +1097,9 @@ product AMOI H02		0x0802	H02 3G modem
 /* American Power Conversion products */
 product APC UPS			0x0002	Uninterruptible Power Supply
 
+/* American Power Conversion products */
+product APC UPS1000		0x0003	Uninterruptible Power Supply
+
 /* Ambit Microsystems products */
 product AMBIT WLAN		0x0302	WLAN
 product AMBIT NTL_250		0x6098	NTL 250 cable modem
--

I.E. 0x0003 instead of 0x0002 for the product.
Comment 8 Cy Schubert freebsd_committer freebsd_triage 2023-02-22 03:11:51 UTC
Created attachment 240318 [details]
Correct patch

(In reply to Denny Page from comment #7)

Oops. Thanks for catching that.
Comment 9 Denny Page 2023-02-22 03:17:30 UTC
(In reply to Cy Schubert from comment #8)

I believe those patches will work. Thanks.
Comment 10 commit-hook freebsd_committer freebsd_triage 2023-02-28 13:47:07 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=8866ea619a1f91616ba7e002a3ad10dfb10148c9

commit 8866ea619a1f91616ba7e002a3ad10dfb10148c9
Author:     Cy Schubert <cy@FreeBSD.org>
AuthorDate: 2023-02-22 02:38:16 +0000
Commit:     Cy Schubert <cy@FreeBSD.org>
CommitDate: 2023-02-28 13:46:00 +0000

    usb: Add HID_IGNORE quirk for APC Smart-UPS1000

    Without the HID_IGNORE quirk enabled it will appear to be a uhid device.

    PR:             269729
    MFC after:      1 week

 sys/dev/usb/quirk/usb_quirk.c | 1 +
 1 file changed, 1 insertion(+)
Comment 11 commit-hook freebsd_committer freebsd_triage 2023-03-08 14:31:48 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=c6ee35809ad3a23d0aa9c9a3f3bab717d46432da

commit c6ee35809ad3a23d0aa9c9a3f3bab717d46432da
Author:     Cy Schubert <cy@FreeBSD.org>
AuthorDate: 2023-02-22 02:38:16 +0000
Commit:     Cy Schubert <cy@FreeBSD.org>
CommitDate: 2023-03-08 14:30:43 +0000

    usb: Add HID_IGNORE quirk for APC Smart-UPS1000

    Without the HID_IGNORE quirk enabled it will appear to be a uhid device.

    PR:             269729

    (cherry picked from commit 8866ea619a1f91616ba7e002a3ad10dfb10148c9)

 sys/dev/usb/quirk/usb_quirk.c | 1 +
 1 file changed, 1 insertion(+)
Comment 12 commit-hook freebsd_committer freebsd_triage 2023-03-08 14:32:49 UTC
A commit in branch stable/12 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=4e16ea3de70ecc355a0c10adb8515a5bba27ae03

commit 4e16ea3de70ecc355a0c10adb8515a5bba27ae03
Author:     Cy Schubert <cy@FreeBSD.org>
AuthorDate: 2023-02-22 02:38:16 +0000
Commit:     Cy Schubert <cy@FreeBSD.org>
CommitDate: 2023-03-08 14:32:17 +0000

    usb: Add HID_IGNORE quirk for APC Smart-UPS1000

    Without the HID_IGNORE quirk enabled it will appear to be a uhid device.

    PR:             269729

    (cherry picked from commit 8866ea619a1f91616ba7e002a3ad10dfb10148c9)

 sys/dev/usb/quirk/usb_quirk.c | 1 +
 1 file changed, 1 insertion(+)
Comment 13 Cy Schubert freebsd_committer freebsd_triage 2023-03-17 18:45:51 UTC
Fixed.
Comment 14 Cy Schubert freebsd_committer freebsd_triage 2023-12-11 05:57:46 UTC
*** Bug 275659 has been marked as a duplicate of this bug. ***