From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793909064; b=LqbX0IpJHcQdFvyyNXZAdEhPoEefV1PAxZCrI++BJXBeyGdA+eHPkpvxwQu6cbVZ0OzT nvSG9eGEuSpYJBlVoSdZWC3o17NiQc1jclBh6Pd1jQAmeWWqXeBtEys1mLVq8VKm3/HNW YVBO19wTUvjF3DOZ585oDk++uuP+xTsO+c0RBKDiog/wHuvXEmfHm7yGhFZdp7Zfo7q7v hB7l+VCP3w0mT6fth1RwKhvH4Wk4irsnVO0YbPI/cwfN3DA0PCJRZIhEa8UbCa3wCLzLA lUCIx6zED80tHdlD4ogJPdBZM2jOEC9YXQljKai6c1GnvlJuhiNfSYOK00EpoosmBfg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793909064; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; bh=Aw5degZrQHo3V3rpws5+g22RRHe/seP3Fa1C54u6MN0=; b=xFEfcSLCDnmG2Q9fc7EECGylyfFwM5Sn3qVPuA6zJIfdG19a/1/Wx+s/QjM8kCuFWwHi obYSsDscxUomxIC7wluZ6YETSVIEsbvNol5Cj7xiAUDJg8IJOrS14NxGXkOEJZukeAfrz z6N6Xw8ZlXh9qKe6At0FRd13T8gkebHutHBGaQfsvZnJjH12w7oUXc0ZYdIVqmhcuyY7B GUWBIezLJX0ZDudXqKbX95Sk2tygN6BWcMtdXQDRBQl01jmegkQ4sixJaWmXfDDrc6kJ5 CK8211ZS3sbiHEygey1FR8UuPPaLFurY+yZ70KnKjfVJlYbMkDvnov2n07L/+BEtKCw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=rowland.harvard.edu; spf=fail smtp.mailfrom=g.harvard.edu; dkim=pass header.d=rowland.harvard.edu header.i=@rowland.harvard.edu header.a=rsa-sha256 header.s=google header.b="l7XvB/r0"; arc=none smtp.remote-ip=209.85.160.182 Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 26A7D606A32F for ; Thu, 5 Nov 2026 20:04:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 26A7D606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rowland.harvard.edu Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=g.harvard.edu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=rowland.harvard.edu header.i=@rowland.harvard.edu header.a=rsa-sha256 header.s=google header.b=l7XvB/r0 Received: by mail-qt1-f182.google.com with SMTP id d75a77b69052e-53634b8328eso19644111cf.0 for ; Thu, 05 Nov 2026 12:04:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rowland.harvard.edu; s=google; t=1793909062; x=1794513862; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=Aw5degZrQHo3V3rpws5+g22RRHe/seP3Fa1C54u6MN0=; b=l7XvB/r0EAsfmkvKwLXi9U+FCv4znlZ1uWBgyBwXXZBCaUNdokUJy53RUHWJ+2kEWT BpwprXNHONWGHOvIsaDTpZHtcB6XsAeWhewDJaNhuiB2euiyoU1AbjQlFtg5R3UAb8Zl j9ild+5nUdzM5UZbj7mYag8Dctagcxk6YhEm1Nh61f0Vznb26vlUpjb7sFwe3CVlNOPl SyOS6Mi1UVvjAAp7m7mMB3CBgWNbht54CQ+BOwi4rfm1nRGeYFie5joT1aagUt7j+5ki VjKs1rKf0ER8mcU7zk1mritepu2DeojMvspSrsP6rAbky9P1uX094nTddzM3XtqlzsCQ csmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793909062; x=1794513862; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Aw5degZrQHo3V3rpws5+g22RRHe/seP3Fa1C54u6MN0=; b=d6qTSXpKBALfSnNo+XwmdLqoHqV0/WRnGuwuYMNzs88FT+O0cwOWTvLrk7+/q3eOuA qYFlTTOq9s3yXuhT6iwKg4zkEUEodiFuUV9cFIjNWoWfkaamOKldscr55dZFmlVuq2tF N0NcNvIFSf+0eWXG4CTH6AqniNhwV4kfKf1uI5Ljy1zQHC6e7x0MhVbniToZh5DUtVb+ B8bWcVvOyID4wCIilcSROy/Az7bvcT0n/JguPCC5GW6hLkejLDCDECTSrId6Cbo5fvXP DFTGPbFxuT0U4JkGiB6Uf2xkSo8BsyXH31yEnmte+/G/ITBdXkwQePKpGAmUOiOszDoC s9JA== X-Forwarded-Encrypted: i=1; AKwUvBxfndM4yj0MBQ+S8kX0sjpaGjdVhpKSyFplfXcRp0BdGMm/v8pnOTZbZwta7mpbxw4KGORsQZwCJZ0j5L4=@vger.kernel.org X-Gm-Message-State: APuU4Z9FTJSJcz4soCRO5dxnmZayH1o21s18Lv/zqFUJhaLZnJzSTibx dUgXUXe7sHCo8OnW21iBOuERiItQF+lxk9HP0Axr9773SBsvjSAt6Uqbi5QlAAHXxA== X-Gm-Gg: AYBFou01upj6ZYrp8ptz9bxa5TRD3If2kGvmPRjjAT+E6P3UZQESofjErpfaPapX/z+ rzmQGm9rfR8p8jQ6fBQAOR3KchM0j1WVektCaDXVZA3N1GmRXBAMW6IUcoLD54/SAjd0THUz2mZ G5OzeIDOH0KT4Rn/Zg3O2EQeUXzWwVALRm4Q90GwGwE2OZcYTqFgG2270EVRNQz07JkbTfC0HFn ChBLX4WzhYgIKGSHvYxUlVty7QKqFdyb2xppJ+8df3tB9fJGQloiEbGw/RKdCkWvncMAXfuDG5G 8UnkyFTPpqQQ8Zii7yJFBj0Wi55YYJVjsS3c4x+wmkzCfeoLMl2djUl9oq/Tt8/km+ecVPxV39C glzlwiw/tD/BOAMbH8ybDWS6kolab9WugR7eQGY8a+UvCuzP0f/WOmCXm7lilp/gZ/kZZjoBECj 1DeKO1UbthvnaL7zceM6qT1MmhQJl7UzxpjPJDwCzma/JdGEhS+1oVk9jo6/wsRl/Nm1qDHBFx9 x3EyRBpbbaTBBrwaQjjLK+BJmrnM4GUYhV9T+aMYizV6UYaTWnzXr5kPOtpEBNenabMPs4LYrCg wYJihmJedmQwLjwLVAjirnwLYoUd X-Received: by 2002:a05:622a:418d:b0:536:60e1:c87d with SMTP id d75a77b69052e-54e14266a2dmr6509601cf.35.1793909061778; Thu, 05 Nov 2026 12:04:21 -0800 (PST) Received: from rowland.harvard.edu ([2601:19b:d01:d210::66b0]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-54e270167afsm1403061cf.25.2026.11.05.12.04.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 12:04:21 -0800 (PST) Date: Thu, 5 Nov 2026 15:04:18 -0500 From: Alan Stern To: Leon Romanovsky Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Dmitry Torokhov , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Johannes Berg , Jonathan Corbet , Shuah Khan , Randy Dunlap , Bjorn Helgaas , "Joerg Roedel (AMD)" , Suravee Suthikulpanit , Vasant Hegde , Will Deacon , Robin Murphy , David Woodhouse , Lu Baolu , Johan Hovold , Eric Dumazet , Marcel Holtmann , Luiz Augusto von Dentz , Nipun Gupta , Nikhil Agarwal , Pieter Jansen van Vuuren , linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, linux-input@vger.kernel.org, netdev@vger.kernel.org, linux-wireless@vger.kernel.org, linux-usb@vger.kernel.org, linux-bluetooth@vger.kernel.org, linux-acpi@vger.kernel.org, linux-doc@vger.kernel.org, linux-pci@vger.kernel.org, iommu@lists.linux.dev, Jason Gunthorpe Subject: Re: [PATCH 05/17] USB: Lock registered interfaces during manual driver binding Message-ID: References: <20261105-device-trust-core-v1-0-1e536825b4eb@nvidia.com> <20261105-device-trust-core-v1-5-1e536825b4eb@nvidia.com> <20261105184442.GF8298@unreal> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261105184442.GF8298@unreal> On Thu, Nov 05, 2026 at 08:44:42PM +0200, Leon Romanovsky wrote: > On Thu, Nov 05, 2026 at 12:24:33PM -0500, Alan Stern wrote: > > On Thu, Nov 05, 2026 at 01:42:18PM +0200, Leon Romanovsky wrote: > > > From: Leon Romanovsky > > > > > > Interface claims hold the USB device lock, but device_bind_driver() > > > requires the target interface lock. Without it, trust-policy writes can > > > race admission. > > > > This says nothing about usb_driver_release_refused_claim() and the code > > related to it. It is an incomplete description of the patch. > > > > Note that nothing prevents drivers from using an interface they claim > > before that interface is registered. For your scheme to work properly, > > you should make sure the claim is authorized when > > usb_driver_claim_interface() is called, not when the interface is > > registered. > > This patch is unrelated to authorization; I meant "authorization" in its generic sense. When you don't trust something, you don't authorize it to do anything. Pretend I had written "the interface being claimed is trusted" in place of "the claim is authorized" above. > it ensures that the lock is > acquired when the driver is bound. That may have been your intention when the patch was created, but if you read the patch you'll see that it includes a whole bunch of material not related to locking during binding. Namely, this part: > > > +/* > > > + * The driver core refused to bind an interface that a sibling claimed before > > > + * it was registered, and dropped the claim. Let the claimant release the > > > + * interface instead of operating it with a bound interface but no driver. > > > + */ > > > +void usb_driver_release_refused_claim(struct usb_interface *iface, > > > + struct device_driver *claimant) > > > +{ > > > + struct device *dev = &iface->dev; > > > + > > > + device_lock(dev); > > > + if (!dev->driver && iface->condition == USB_INTERFACE_BOUND) { > > > + dev->driver = claimant; > > > + usb_unbind_interface(dev); > > > + dev_set_drvdata(dev, NULL); > > > + dev->driver = NULL; > > > + } > > > + device_unlock(dev); > > > +} > > > + > > > /* returns 0 if no match, 1 if match */ > > > int usb_match_device(struct usb_device *dev, const struct usb_device_id *id) > > > { > > > diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c > > > index a738d03c23eac..d35a7710c8ef4 100644 > > > --- a/drivers/usb/core/message.c > > > +++ b/drivers/usb/core/message.c > > > @@ -2264,6 +2264,7 @@ int usb_set_configuration(struct usb_device *dev, int configuration) > > > */ > > > for (i = 0; i < nintf; ++i) { > > > struct usb_interface *intf = cp->interface[i]; > > > + struct device_driver *claimant; > > > > > > if (intf->dev.of_node && > > > !of_device_is_available(intf->dev.of_node)) { > > > @@ -2277,7 +2278,14 @@ int usb_set_configuration(struct usb_device *dev, int configuration) > > > dev_name(&intf->dev), configuration, > > > intf->cur_altsetting->desc.bInterfaceNumber); > > > device_enable_async_suspend(&intf->dev); > > > + claimant = intf->dev.driver; > > > + if (claimant && !try_module_get(claimant->owner)) > > > + claimant = NULL; > > > ret = device_add(&intf->dev); > > > + if (!ret && claimant && !intf->dev.driver) > > > + usb_driver_release_refused_claim(intf, claimant); > > > + if (claimant) > > > + module_put(claimant->owner); > > > if (ret != 0) { > > > dev_err(&dev->dev, "device_add(%s) --> %d\n", > > > dev_name(&intf->dev), ret); > > > diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h > > > index a9b37aeb515be..293340a48b6c5 100644 > > > --- a/drivers/usb/core/usb.h > > > +++ b/drivers/usb/core/usb.h > > > @@ -49,6 +49,8 @@ extern int usb_set_isoch_delay(struct usb_device *dev); > > > extern int usb_get_bos_descriptor(struct usb_device *dev); > > > extern void usb_release_bos_descriptor(struct usb_device *dev); > > > extern int usb_set_configuration(struct usb_device *dev, int configuration); > > > +void usb_driver_release_refused_claim(struct usb_interface *iface, > > > + struct device_driver *claimant); > > > extern int usb_choose_configuration(struct usb_device *udev); > > > extern int usb_generic_driver_probe(struct usb_device *udev); > > > extern void usb_generic_driver_disconnect(struct usb_device *udev); Was this meant to be two separate patches that somehow got combined into one? Alan Stern