From owner-freebsd-usb@freebsd.org Wed Mar 30 09:30: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 2F511AE0F08 for ; Wed, 30 Mar 2016 09:30:37 +0000 (UTC) (envelope-from interloper255@gmail.com) Received: from mail-wm0-x231.google.com (mail-wm0-x231.google.com [IPv6:2a00:1450:400c:c09::231]) (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 BDB2B1EE1 for ; Wed, 30 Mar 2016 09:30:36 +0000 (UTC) (envelope-from interloper255@gmail.com) Received: by mail-wm0-x231.google.com with SMTP id 191so81643062wmq.0 for ; Wed, 30 Mar 2016 02:30:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=mtUVWT7owIHvusQXZBbjhpsTEqy5f4jhMqqX+koGVnA=; b=0Au4g8jXXNib/shhbCVL7LuQqhm7dlV551iCzaAXfJ1UJUgF9MISTeDzH4yDM4Hf/V ez1oXI6WCtY1+PAOGdmqm5dRMFe2gZgm1ted7P5YT0c2ho9FPNKkoqFRT10VT7lxFTxW yvhOut0RduAEmnkuCarn5fiZ7b1yq7T4So+OXYEyQ7rFjy7XP3r1aUuyvAYeiIFW3Lbh kQCpL4diuEfsKr6PDukXj7cU9AcbBV1npE3EuYDJ7+hUglAGmYveq5XLS7j3K025JgOq o8MJoYyN6vtlucpF47ZZBb8xl0IIw3Qk4OMSa8h87mItMzQeZBBMnjdZPxQWcoMrJdrf ILKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=mtUVWT7owIHvusQXZBbjhpsTEqy5f4jhMqqX+koGVnA=; b=Gl3EUJkY9UMf5W7kEb24vOAs0PS+rV11shd7AmJlU8unKE6glzBFa4mxuYQK+h0fXW V/A7vFZqwOxfDtiXKBt723RzulitQn0uf1qS4DsuCLiBjIpIRnFjwgb5FgT4ySNO7zCU YK64y/q2T/CahHpDx1TprxyUYqdhTsh1NSlNMk/ka0eMhXnLzIwoprjbBbq8zxRGKup1 TsfkUUA5HjnS0mCIZtSlsyPyER/319qIl+9C0psCYHKo77oSxf/pGOTdKEmX5tbxW1Yd QaITPYydbfVjPos9qLCjhtvZLeP+zUacil01l7/lArXvrvergRfeJdfO2iiUGN511NfR sCMQ== X-Gm-Message-State: AD7BkJKuI8xqbo5YW8/OXYrXV7qDK7eCsevzI7mqGkGhzaIFUu0W65VoTSIJRS6Qi8/0gK0PN0U7zhl381V+nQ== MIME-Version: 1.0 X-Received: by 10.194.2.202 with SMTP id 10mr8808687wjw.94.1459330235227; Wed, 30 Mar 2016 02:30:35 -0700 (PDT) Received: by 10.194.25.226 with HTTP; Wed, 30 Mar 2016 02:30:35 -0700 (PDT) In-Reply-To: <56FB7C64.5090801@selasky.org> References: <56FB7C64.5090801@selasky.org> Date: Wed, 30 Mar 2016 10:30:35 +0100 Message-ID: Subject: Re: libusb permission error (?) when attempting to detach device which is not attached From: Conor To: Hans Petter Selasky Cc: 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: Wed, 30 Mar 2016 09:30:37 -0000 Thank you for your response. This clears up a few things. Hi, > > Currently only root/superuser can alter the enumeration state of USB, like > attaching/detaching kernel drivers. That's why there is a PRIV_DRIVER check > in the IOCTL of USB_IFACE_DRIVER_DETACH. > Duly noted. The privilege check failure is valid, then. To me, it doesn't seem to align with the devfs rules I mentioned, but I don't know the full scope of PRIV_DRIVER, so I may be way off. Regarding 'currently', is this likely to change in 11.0? > >> 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? >> > > Unlike Linux, interface drivers can co-exist in userspace and the kernel > for the same USB device, given they are not in use at the same time. > Currently this and other user-space drivers should call > libusb_kernel_driver_active(), but don't bail out if > libusb_kernel_driver_active() does not succeed. > > Got it. This was my solution to the issue, however, it would still require superuser privileges to detach the device if an active driver is present, right? The remaining approach, as far as I can see, is to run openocd with elevated privileges, as opposed to avoid attempting to detach the device by checking for an active driver. Not optimal, but unavoidable, I think. -- Conor.