From nobody Wed Dec 10 04:57:53 2025 X-Original-To: usb@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4dR3PY5C6Vz6Jvd5 for ; Wed, 10 Dec 2025 04:57:53 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dR3PY3xZqz3mJG for ; Wed, 10 Dec 2025 04:57:53 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1765342673; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eD9tqRPGLN1MuvBxcqUwb5qWg1RdzexBtN0oWecxoFE=; b=wHBkzS/Xi2Qu7Yg2WfIKWJRhGV+zVncPRK/8BqHTALttU+q/1o3p+3CJASVG+eTkLFcwZW r6FWVMv/+xAqgDh/JqM8iyEDaTkHZ36CAEivG66qje2FdMVU45OXvZtF331b7gVjmzgugV WWSFyuOvHcFYoSelJ34XjLN9UD0ajmQD9JlE2qOC/AzMCKOlXOrWYBgh2tY2YxQD1MZx+V VrbfsfYeK9lJMILWy+32XYSJsJ5VpkVCHPznloIcgQjshbYBd2Kd4WGYwdgd5oVMKqdLDs cACzFttJHOsBvNuWuC/b8lchmKC7J9l4vZogtgyxhWFppAj4Nlg/+ORV+aOXkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1765342673; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eD9tqRPGLN1MuvBxcqUwb5qWg1RdzexBtN0oWecxoFE=; b=k8txfnaGlKUnMkZy7E3f7KQIathWinCKnKUvyunWzFWEJNifC2WPswSs6m9MHd7JHNEJgO EJf4D5OCxNTg2eRZO64LsMnyxn/JecmgbRF6ku0RgYMC2Yv4896CXLjI8cWsrzHgCh4fs/ FW64u8ejRCSQEcgryJNENKRviPg6z0v4j+aSvUrxv79CxxErXERYldn9R8sU6sIfKup8ep YfC7zVaIwey1MxyMTK0gEAnEWRPIRaqsOVrJv0uTGaV5drl8LYTT6O84VMnrhH1UPWG35A NJ5dNhWnv473yZVQWzsqQa4NsD0mQWJ57HBeifnoWhT/wL4o38sR4oBjXLa3Ew== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1765342673; a=rsa-sha256; cv=none; b=NPNEZMNG6tX0NpvU7tEprfhnn5GZjw3218FwtzuYf8lrV5Mj41FcxQ8qReDPrKyYQ5LrQ/ S/tY/BXfJs1W/vcgr6nhcb7vV9dZLlS13EUZVqQYpBk54DspOkz44fz2v1ZPAyBottrAo0 sbYZB5QtaGzrIPoWCgD8jHeLvzLp7c7mnMTOBSM2EC/IYRtHD+bxpLzkJG0Vqi5r6XQCjs +TO0zls+4N5zygnRGFo5zgj/rJQZ4vyI3iNUNMNl6YFUkc7NX533NS7YIrYzTo3xCzmAEt nU0syOFYxA8pAePCIJQJVrJk2w9VgwO9MHs9itgJNCBLtPZ6SCO6l7KBx752xw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4dR3PY2hS9zTlc for ; Wed, 10 Dec 2025 04:57:53 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 5BA4vr3N069703 for ; Wed, 10 Dec 2025 04:57:53 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 5BA4vrNx069701 for usb@FreeBSD.org; Wed, 10 Dec 2025 04:57:53 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: usb@FreeBSD.org Subject: [Bug 291506] libusb_open advisory lock (libusb compatiblity) Date: Wed, 10 Dec 2025 04:57:53 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: usb X-Bugzilla-Version: 15.0-RELEASE X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Some People X-Bugzilla-Who: unitrunker@unitrunker.net X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: usb@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-usb List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: freebsd-usb@freebsd.org Sender: owner-freebsd-usb@FreeBSD.org MIME-Version: 1.0 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D291506 --- Comment #2 from unitrunker --- =3D=3D DRAFT (feedback welcome) =3D=3D Requirements libusb_open assume: libusb_device parameter comes from libusb_get_device_list() succeeds on opening a valid, attached device not locked by any processes (including self). fails on opening a device locked by any process (including self). libusb_open_with_vid_pid for "N" valid, matching devices attached to host. succeeds on opening all N devices with matching vid/pid and not locked by a= ny process (including self). fails when all valid, matching devices are taken by any process (including self). About "including self" - be sure to cover in-process testing where the same libusb_context is shared and also where a new=20 libusb_context is created prior to each device open attempt. Tools Two USB devices with same VID/PID (preferrably with different serial number= s). usbgrab: a small test tool to take ownership of the first device with match= ing vid and pid on the host. Uses libusb_open_with_vid_pid. Synopis: usbgrab [-p] [-a] vid - four digit hexadecimal vendor id pid - four digit hexadecimal product id. -p pause, displays "Press enter..." and waits for input. Keeps the device "owned" for an indefinite amount of time. -a all - grabs all matching devices and displays how many were found. If -a= is absent, the program grabs the first matching device. -p and -a may be combined. Test Plan A. Single device 1. Attach one device with known VID/PID. 2. run "usbgrab -p &" utility to take ownership of the device.= =20 3. Verify the tool displays "Found: 1 Press enter ..." 4. run "usbgrab " in the foreground. 5. Verify an error is displayed. 6. run "fg" to place the earlier usbgrab process into the foreground. 7. press enter to exit the process. Verify no usbgrab background processes remain. B. Two devices, sequential 1. Attach two devices with same known VID/PID. 2. run "usbgrab -p &" utility to take ownership of the device. 3. Verify the tool displays "Found: 1 Press enter ..." 4. run "usbgrab " in the foreground. 5. Verify NO error is displayed. 6. run "fg" to place the earlier usbgrab process into the foreground. 7. press enter to exit the process. Verify no usbgrab background processes remain. C. Two devices, all or none 1. Attach two devices with same known VID/PID. 2. run "usbgrab -p -a &" utility to take ownership of all match= ing devices. 3. Verify the tool displays "Found: 2 Press enter ..." 4. run "usbgrab " in the foreground. 5. Verify an error is displayed. 6. run "fg" to place the earlier usbgrab process into the foreground. 7. press enter to exit the process. Verify no usbgrab background processes remain. D. Two devices, alternating 1. Attach two devices with same known VID/PID. 2. run "usbgrab -p &" utility to take ownership of the device a= nd pause in the background. 3. Verify the tool displays "Found: 1 Press enter ..." 4. Make note of the background process pid. 5. run "usbgrab -p &" in the background to take ownership of the second device. 6. Verify "Found 1 Press enter ..." is displayed. 7. run "usbgrab " in the foreground. 8. Verify an error is displayed. 9. run "fg " to place the earlier usbgrab process into the foreground. 10. press enter to exit the process. 11. run "usbgrab " 12. Verify "Found 1" is displayed 13. run "fg" to place earlier usbgrab process into foreground. 14. press enter to exit the process. Verify no usbgrab background processes remain. Notes I tested this by running buildworld on a git clone of https://github.com/freebsd/freebsd-src.git Instead of installing the results, I renamed three files in /usr/lib (libus= b.a, libusb.so, libusb.so.3) and copied the three newly built files into place.= =20 There's probably a better way but this works. Those scope of this change is= so small - I can quickly deploy and roll-back the change to compare before vs. after behavior. Concerns For a USB device shared between kernel and userland, what impact might an advisory lock have on the libusb_detach_kernel_driver and libusb_attach_kernel_driver functions? The devices I use to test do not have kernel drivers. --=20 You are receiving this mail because: You are the assignee for the bug.=