From owner-freebsd-usb@freebsd.org Tue Mar 29 20:05:37 2016 Return-Path: Delivered-To: freebsd-usb@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 4BA09AE2A9E for ; Tue, 29 Mar 2016 20:05:37 +0000 (UTC) (envelope-from interloper255@gmail.com) Received: from mail-wm0-x234.google.com (mail-wm0-x234.google.com [IPv6:2a00:1450:400c:c09::234]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D9C931F09 for ; Tue, 29 Mar 2016 20:05:36 +0000 (UTC) (envelope-from interloper255@gmail.com) Received: by mail-wm0-x234.google.com with SMTP id p65so155235554wmp.1 for ; Tue, 29 Mar 2016 13:05:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to; bh=rd++7sphthKKPw4/IEOjxWvRDw6/co7o+CoYm1WxACI=; b=EeJbhlmcBX0VQlhejRwfcZ+fAhJrW77Y523Kp75VpgjHTqFsrUsVFqz/p5ofAcnwms ZKtbzeySzPDsnwHRv8cwxALPi2R6rP9q9V7Q6kjPa/2kNsbZXnz0LvMMUUCeR+/+ud7D fmj5DXMjf4YfH8Xuql5Xw+CUjUCvut0W4JW4AIy3GYTfcWKfxDOtROGp+jciNE+ihhy2 2/3UMHDnkNECLHGwIiAnwvu7CTgsycEPxVhGpqBFzf6yPwouQHWLvFhtdnWpPp9SrCym 4TS9M7X7XYvB/uW1vtucjz+3ZBz6WpERPZgc64WzA3dpA3dW/QIWAACO8sBwTWuGqasc 0bHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to; bh=rd++7sphthKKPw4/IEOjxWvRDw6/co7o+CoYm1WxACI=; b=MEN5ZfD+5Xdc0cPHhcmKDb79icVsEVHviqdovGb2hS9QoBZoFIH9qXQamSYdQKrWaQ HH5US9HrPMgZbcJtVaWbCKZ5PyGMIlwKZV3FLyYWoNw5RGELt3acL5/jXrLsz65hGfEi JvrJ9u+hkEaTOdwAO0ryuYbtrk/db7m8paygzovKzqC85fC0bKtCdfca6SBQbWOPH4cm D+EGhGU2COhcrIP3QYCdDX1lZpEhe3g8Hs77abphi/12VxCVpA5hMYOWFleaXrZMXUHg zWuyV4d8/qp3FIk/OGCNPect00dI/L+sp+G3T2pQLJ8P+X4vsP5KemEG7GO8ToAp2IUO OnFw== X-Gm-Message-State: AD7BkJLIo7DU61ex1cX0ExrM7kjPkyL1KwYydu5eSsWi0iqhMHX8Nq7hgfyLqXiVQHQpjNP8xmaNvufkBQI67Q== MIME-Version: 1.0 X-Received: by 10.28.132.17 with SMTP id g17mr19266775wmd.63.1459281935266; Tue, 29 Mar 2016 13:05:35 -0700 (PDT) Received: by 10.194.25.226 with HTTP; Tue, 29 Mar 2016 13:05:35 -0700 (PDT) Date: Tue, 29 Mar 2016 21:05:35 +0100 Message-ID: Subject: libusb permission error (?) when attempting to detach device which is not attached From: Conor To: freebsd-usb@freebsd.org Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.21 X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Mar 2016 20:05:37 -0000 Greetings, I'm unsure if this is the correct place for this discussion; if it is more suitably discussed elsewhere, please let me know. Currently, I'm looking into an issue with a port (devel/openocd), whereby attempting to detach a USB device fails due to, from what I can tell, a permissions error. First, some background; The port's pkg-message suggests adding the following lines to /etc/devfs.rules: ===== [localrules=10] add path 'ugen*' mode 0660 group operator add path 'usb/*' mode 0660 group operator add path 'usb' mode 0770 group operator ====== ...such that members of the operator group may access attached hardware. I've done so, and my user is a member of the operator group. The device in question is an Olimex JTAG debugger, and I'm running 10.2-RELEASE. When starting OpenOCD as my user, it bombs out stating that libusb_detach_kernel_driver() has failed with LIBUSB_ERROR_OTHER. When starting as root, there is no error, and I can socat/telnet to the OpenOCD server and flash/debug a target. Initially, it seemed that it was, indeed, a permissions issue: 1) Some initial investigation of the FreeBSD libusb implementation, and kernel source, pointed at the failure being in privilege checking in the ioctl handler for USB_IFACE_DRIVER_DETACH whereby a check for PRIV_DRIVER fails (sys/dev/usb/usb_generic.c:2210) when running as my user. Naturally, the check for su returns success when running as root. 1a) Given the permissions alluded to in /etc/devfs.rules above, should this privilege check fail, given that the device node is one of ugenX.Y? 2) I've patched the OpenOCD source to first check for an active driver with libusb_kernel_driver_active(), and only on success, attempting to detach the device. Whilst this rectifies the issue -- there is no active driver, ergo, no detach attempt is made and I can use the server as described with su, above -- is it reasonable/necessary to do this? I appreciate any insights or input you might have.