From owner-freebsd-usb@freebsd.org Fri Jul 3 08:10:48 2020 Return-Path: Delivered-To: freebsd-usb@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 4F88836DCE0 for ; Fri, 3 Jul 2020 08:10:48 +0000 (UTC) (envelope-from hps@selasky.org) Received: from mail.turbocat.net (turbocat.net [88.99.82.50]) (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 mx1.freebsd.org (Postfix) with ESMTPS id 49ynhl3dSBz3gmR for ; Fri, 3 Jul 2020 08:10:47 +0000 (UTC) (envelope-from hps@selasky.org) Received: from hps2020.home.selasky.org (unknown [178.17.145.105]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.turbocat.net (Postfix) with ESMTPSA id 8AF88260184; Fri, 3 Jul 2020 10:10:45 +0200 (CEST) Subject: Re: USB reset fails when using a LimeSDR Mini on FreeBSD To: Jan Behrens Cc: "freebsd-usb@FreeBSD.org" References: <20200625121052.e9f7e7cbeb68fad264ec80a9@magnetkern.de> <20200627144419.f14371695d9b62ea99106c4a@magnetkern.de> <20200627173604.7f7b7777140e66dbad812fc7@magnetkern.de> <20200627180420.4b8012fb@ernst.home> <20200702103523.adb0566bcc7b6e354905a8a5@magnetkern.de> <97c8fd11-9200-dff7-4c68-b0b80cc44871@selasky.org> <20200702104743.223e98c325806025704703f2@magnetkern.de> <20200702111538.e7edf0ae8d10ec7ede9acebb@magnetkern.de> <9e14575a-5c8b-28c8-6593-22019a21e7e7@selasky.org> <20200702120655.73d1111e2de81c626be78139@magnetkern.de> <8ac365f3-3d33-4730-622e-e66f29dd5938@selasky.org> <20200702123747.1bdf36b9d2ebe283f7bb855e@magnetkern.de> <20200703095108.7ce5497f53ed4c4a3d7289e3@magnetkern.de> From: Hans Petter Selasky Message-ID: <4fdcdc92-6a0d-5645-0a10-e95d69001d3a@selasky.org> Date: Fri, 3 Jul 2020 10:10:23 +0200 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200703095108.7ce5497f53ed4c4a3d7289e3@magnetkern.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 49ynhl3dSBz3gmR X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of hps@selasky.org designates 88.99.82.50 as permitted sender) smtp.mailfrom=hps@selasky.org X-Spamd-Result: default: False [-2.57 / 15.00]; TO_DN_EQ_ADDR_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+a:mail.turbocat.net]; NEURAL_HAM_LONG(-0.99)[-0.991]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[selasky.org]; ARC_NA(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; NEURAL_HAM_SHORT(-0.33)[-0.327]; RCPT_COUNT_TWO(0.00)[2]; NEURAL_HAM_MEDIUM(-0.95)[-0.954]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:24940, ipnet:88.99.0.0/16, country:DE]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Jul 2020 08:10:48 -0000 Hi Jan, On 2020-07-03 09:51, Jan Behrens wrote: >> >> Yes, and we have one or two firmware loading utilities in base still >> using them. > > Except that /dev/usb/X.Y.0 (which is linked by /dev/ugenX.Y) controls > access rights to the device through libusb, right? Yes, that is correct. >> >> Yes, but opening /dev/ugenX.Y doesn't mean that kernel device drivers >> are detached from this device. > > Can/does a kernel device driver restrict what a user can do with the > device when the kernel driver is active? Or does access to the device > always enable a user to mess up things badly? The kernel device driver can not restrict what the user-space driver can do. Yes, user-space can mess up the device totally. >> >> User-space drivers are requested to create a uniq PID file, to avoid >> clashes with multiple drivers on the same interface and may use >> libusb_claim_interface() to tell the kernel to detach any drivers on >> that specific interface. > > If the kernel refuses to give up control, is the user-space program > denied access? If yes, I can generally understand why you don't want a > USB reset to be initiated by a user-space program (at least as long > there are kernel drivers attached). The FreeBSD USB stack has no concept of exclusive access to USB endpoints. Simply if both kernel and user-space attach to the same device, user-space will receive half of the USB packets and the kernel the other half. >> If you for example load the LimeSDR two times for the same ugenX.Y >> device, then the interface communication might stop working, even though >> no error is reported. > > Thus the lock of user-space drivers is only advisory and not enforced? Right, it is not enforced. > How about if a kernel driver uses the device? Can/does the kernel block > out a user-space driver that would mess with the kernel's operation on > the device? No, it is all transparent. Kernel drivers cannot block user-space, but user-space can detach kernel-space. That's all. > > I see three possible approaches currently: > > 1. Allowing a USB reset if the user has access to /dev/ugenX.Y (might > allow users to mess with kernel's operation on a device, unless the > problem exists anyway, see my questions above). > > 2. Allowing a USB reset if the user has access to /dev/ugenX.Y and > there are other prerequirements fulfilled (e.g. a sysctl setting to > enable it globally, which might not be fine-graded enough, or the > requirement that there is currently no kernel driver attached, or a > combination thereof). > > 3. Providing a way to grant "reset permissions" on a per-device basis > (might be overkill, and not really needed). > Maybe you're right we should allow this for non-root aswell. I need to think about it! --HPS