Linux bluetooth development
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Danilo Krummrich <dakr@kernel.org>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Andrew Lunn <andrew@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Russell King <linux@armlinux.org.uk>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Johannes Berg <johannes@sipsolutions.net>,
	Jonathan Corbet <corbet@lwn.net>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	Bjorn Helgaas <bhelgaas@google.com>,
	"Joerg Roedel (AMD)" <joro@8bytes.org>,
	Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
	Vasant Hegde <vasant.hegde@amd.com>,
	Will Deacon <will@kernel.org>,
	Robin Murphy <robin.murphy@arm.com>,
	David Woodhouse <dwmw2@infradead.org>,
	Lu Baolu <baolu.lu@linux.intel.com>,
	Johan Hovold <johan@kernel.org>,
	Eric Dumazet <edumazet@kernel.org>,
	Marcel Holtmann <marcel@holtmann.org>,
	Luiz Augusto von Dentz <luiz.dentz@gmail.com>,
	Nipun Gupta <nipun.gupta@amd.com>,
	Nikhil Agarwal <nikhil.agarwal@amd.com>,
	Pieter Jansen van Vuuren <pieter.jansen-van-vuuren@amd.com>,
	Chris Lu <chris.lu@mediatek.com>, Mans Rullgard <mans@mansr.com>,
	Alan Stern <stern@rowland.harvard.edu>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Cornelia Huck <cornelia.huck@de.ibm.com>,
	Andrew Morton <akpm@osdl.org>, Jeff Garzik <jeff@garzik.org>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	Bart Van Assche <bvanassche@acm.org>,
	Alexander Duyck <alexander.h.duyck@linux.intel.com>,
	Dan Williams <djbw@kernel.org>, Lukas Wunner <lukas@wunner.de>
Cc: 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, linux-coco@lists.linux.dev,
	Alexey Kardashevskiy <aik@amd.com>,
	Luiz Augusto von Dentz <luiz.von.dentz@intel.com>,
	Greg Kroah-Hartman <gregkh@suse.de>,
	linux-sound@vger.kernel.org, Jason Gunthorpe <jgg@ziepe.ca>
Subject: [PATCH v5 27/33] driver core: Document trust admission and initrd authorization
Date: Thu,  3 Dec 2026 14:03:49 +0200	[thread overview]
Message-ID: <20261203-device-trust-core-v5-27-485cc6eddd46@nvidia.com> (raw)
In-Reply-To: <20261203-device-trust-core-v5-0-485cc6eddd46@nvidia.com>

From: Leon Romanovsky <leonro@nvidia.com>

Allowing a driver to bind does not establish device identity or prevent DMA
initiated by the hardware. An initrd that treats those as equivalent could
authorize a device before attestation or containment is ready.

Document the authorization workflow and the division of responsibility
between userspace, driver core and bus infrastructure. Explain which
decisions survive probe failure and unbind, and when queued probes may
start, so policy agents can prepare the device before granting access.
Include the kernel-doc of the device trust API.

Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 .../driver-api/driver-model/device-trust.rst       | 247 +++++++++++++++++++++
 Documentation/driver-api/driver-model/index.rst    |   1 +
 2 files changed, 248 insertions(+)

diff --git a/Documentation/driver-api/driver-model/device-trust.rst b/Documentation/driver-api/driver-model/device-trust.rst
new file mode 100644
index 000000000000..de26a2cf049e
--- /dev/null
+++ b/Documentation/driver-api/driver-model/device-trust.rst
@@ -0,0 +1,247 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+============
+Device trust
+============
+
+Device trust controls how the kernel uses a device. It does not verify
+the device's identity or firmware.
+
+Each device has a requested policy and an active trust level. The bus,
+boot options and userspace set the policy. When a driver binds, driver
+core turns the policy into a level, and bus, DMA and driver code act on
+that level.
+
+Policies and levels
+===================
+
+The ``trust_policy`` sysfs attribute holds the requested policy:
+
+- ``bus``: the bus chooses the level.
+- ``blocked``: no driver may bind.
+- ``adversarial``: treat the device as potentially malicious.
+- ``unrestricted``: use the device normally.
+
+The bus may set the initial policy; otherwise it is ``bus``. Boot
+options can replace it; see `Boot options`_.
+
+The read-only ``trust`` attribute shows the active level:
+
+- ``blocked`` (``DEVICE_TRUST_BLOCKED``): no driver is set up or bound.
+- ``adversarial`` (``DEVICE_TRUST_ADVERSARIAL``): the device may be
+  malicious. This is only a label; protection comes from bus, DMA and
+  driver code that checks it.
+- ``unrestricted`` (``DEVICE_TRUST_UNRESTRICTED``): the device has the
+  normal privileges that the bus and DMA policy allow.
+
+On a bus without a ``trust_resolve`` callback, ``bus`` and
+``unrestricted`` give ``unrestricted``, and ``adversarial`` gives
+``adversarial``.
+
+Boot options
+============
+
+Built-in drivers can bind before userspace starts, so boot options set
+the initial policy. ``<policy>`` is one of the four policy names.
+
+``device_trust``
+  Enable device trust with ``blocked`` as the default.
+
+``device_trust.default=<policy>``
+  Set the policy of all devices. ``bus`` keeps the bus policy; other
+  values replace it, including topology and removability defaults.
+
+``device_trust=<bus>:<device>=<policy>[,...]``
+  Set the policy of single devices, named as in
+  ``/sys/bus/<bus>/devices/<device>``. The first colon ends the bus name;
+  later colons belong to the device name.
+
+``device_trust.driver=<bus>:<driver>=<policy>[,...]``
+  Set the policy of devices that a driver binds, named as in
+  ``/sys/bus/<bus>/drivers/<driver>``. Module names and aliases do not
+  match. Quote the option if a driver name contains spaces.
+
+Any ``device_trust`` option, even an unknown one or one without a value,
+makes ``blocked`` the default. ``device_trust.default=`` replaces that
+default wherever it appears; the last valid value wins.
+
+Names must match exactly, without wildcards. They cannot contain commas,
+equals signs, double quotes or control characters, and device names
+cannot contain whitespace. In a list, the last entry for a name wins. If
+an option is repeated, the last valid list replaces the earlier ones. A
+malformed list is ignored entirely, with a warning. Boot rules also apply
+to devices found after boot, and driver rules to modules.
+
+A device entry takes precedence over driver rules, the global default
+and bus policy, wherever it appears. A device entry of ``bus`` lets
+the bus choose the level even when the global default is ``blocked``.
+
+Boot options do not prove a device's identity.
+
+Driver rules
+------------
+
+A driver rule applies at the first bind attempt by a matching driver,
+before the level is chosen. It replaces bus and global policy, including
+a global ``blocked``. It does not apply if the device has a device entry,
+has been authorized or committed, or has had a successful policy write.
+With ``device_trust.default=unrestricted``, writing the current value
+does not count as such a write. A rule applies only once per device,
+even if binding fails.
+
+Several drivers can match one device. Once a driver rule has set the
+policy, a later driver whose rule names a different policy is rejected,
+even if both policies give the same level. If the device was committed
+without a driver rule, a later driver's rule may name another policy but
+must give the committed level. A driver never binds against its own
+rule. Drivers without a rule use the device's current policy.
+
+After a ``blocked`` driver rule applies, the device waits for
+authorization, even if other drivers try to bind. Userspace can
+authorize it unless ``device_trust.default=unrestricted`` is set.
+
+Changing the policy
+===================
+
+Without device trust boot options, the kernel works as before: bus
+defaults and bus authorization interfaces are unchanged, and
+``trust_policy`` accepts only its current value. Any device trust boot
+option enables policy changes; ``device_trust.default=bus`` does so
+without changing bus defaults.
+
+``device_trust.default=unrestricted`` is the exception. It fixes the
+policy of every device, including devices with boot exceptions. Writing
+a different value returns ``-EBUSY``, and writing the current value
+changes nothing. Boot rules still apply.
+
+When policy changes are enabled, a device is in one of these states:
+
+- Selectable: any policy can be written. Writing ``blocked`` makes the
+  device wait.
+- Waiting: the policy is ``blocked``. Only ``adversarial`` or
+  ``unrestricted`` can be written, which authorizes the device. Writing
+  ``bus`` does not unblock it.
+- Authorized: the policy cannot change.
+- Committed: before driver setup, the kernel fixed the policy and the
+  level. Neither can change.
+
+A device starts as waiting if its initial policy is ``blocked``, and as
+selectable otherwise. A different policy cannot be written while a
+driver is bound. Rejected writes return ``-EBUSY``.
+
+A device keeps its state for the lifetime of the device object,
+including across the switch from initrd to the root filesystem.
+Unbinding and rebinding do not reset it. A removed device that is found
+again is a new object and starts from bus and boot policy.
+
+Policy writes cannot revoke authorization or move a running device
+between ``adversarial`` and ``unrestricted``. Stopping a device needs a
+separate procedure that stops its driver, tears down DMA and contains the
+device on its bus.
+
+Driver binding
+==============
+
+A driver cannot bind a ``blocked`` device. A manual bind returns
+``-EPERM`` before any driver or DMA setup, and automatic matching moves
+on to the next driver. The device keeps waiting for authorization.
+
+The active level stays the same from DMA setup, through probe, operation
+and removal, until ``bus_type::dma_cleanup`` finishes. Then it returns to
+``blocked``.
+
+Initrd attestation
+==================
+
+An initrd can check devices before their drivers use them:
+
+1. Boot with ``device_trust.default=blocked`` to hold all devices, or
+   with ``device_trust.default=bus`` and ``blocked`` device entries
+   to hold some. Add exceptions for the devices and suppliers needed to
+   reach the initrd, attest devices and contain DMA meanwhile. Held
+   devices stay blocked even if their bus would choose another level, and
+   built-in drivers cannot bind them.
+
+2. In the initrd, control probing and attest the device through a
+   transport that works without its driver. Keep it ``blocked`` during
+   verification and preparation, and leave it blocked if verification
+   fails or is not possible. Attest again if a reset or preparation step
+   invalidates the evidence. Removing or replacing the device invalidates
+   the result; a reused bus address does not prove identity.
+
+3. Write ``adversarial`` or ``unrestricted`` to ``trust_policy``. This
+   fixes the policy and allows binding. Queued or concurrent probes may
+   start at once, so the evidence must still be valid at this point.
+
+4. Bind the driver through ``drivers_probe`` or another attach path. The
+   kernel commits the level before setup, and retries keep the same
+   policy and level. Retry on ``-EAGAIN``. A scan may skip rejected
+   drivers without returning an error, and a successful
+   ``drivers_probe`` write does not wait for a probe that is already
+   running.
+
+The ``driver`` link appears before probe completes, so it does not show
+that binding succeeded. Watch for the ``bind`` uevent of the current
+device object, starting before step 3, or use a synchronous per-driver
+bind.
+
+A driver whose probe callback exists only during init cannot retry a
+binding held by ``blocked``. Its devices need a boot exception, or the
+driver needs a probe callback that stays available. Boot exceptions with
+``adversarial`` or ``unrestricted`` let devices operate without fresh
+attestation. The kernel provides neither an attestation transport nor a
+verifier.
+
+DMA
+===
+
+``blocked`` stops driver binding, not DMA that the hardware starts on its
+own. The bus and IOMMU must contain such DMA while the device waits.
+
+``adversarial`` does not require an IOMMU and does not isolate DMA by
+itself. Without an IOMMU group, or with IOMMU support compiled out,
+binding uses the platform's normal DMA setup. Drivers that manage DMA
+themselves must provide their own containment. Drivers that do not use
+DMA need no domain.
+
+Device trust does not change DMA handling, IOMMU domain selection or
+ATS based on the active level; existing bus and platform code still
+decides them. Connecting them is separate work. If setup fails after
+commitment, the device keeps the committed level and cannot fall back to
+``unrestricted``.
+
+Bus and driver interfaces
+=========================
+
+A bus can implement the ``trust_resolve`` callback of struct bus_type to
+choose the level from the device, the candidate driver and the policy.
+For ``bus`` it may use topology or firmware data; any other policy
+must give the level of the same name, or the callback fails. The
+callback must not enable the device or grant DMA access; setup callbacks
+do that after it, before probe.
+
+Global and device boot rules apply when the device is added. A bus that
+needs the policy earlier calls device_trust_init(). Bus code that
+operates a device before device_add() admits it with
+device_trust_prepare() and ends the active level with
+device_trust_clear(). Buses with their own authorization interfaces can
+check device_trust_enabled() and request policies with
+device_trust_set_policy().
+
+Drivers may cache the active level while bound, but must not change the
+policy. Check device_is_adversarial() on paths that bypass the DMA API;
+general DMA containment belongs in bus and IOMMU code. A committed level
+does not allow using the device while it is unbound.
+
+Trust does not describe transport protection, encryption, verified
+identity, memory privacy or DMA addressability. Keep those properties
+separate from the policy and level.
+
+device_driver_attach_unrestricted() keeps devices out of device trust
+authorization and **must not be used in new code**; use
+device_driver_attach() instead.
+
+.. kernel-doc:: include/linux/device/trust.h
+
+.. kernel-doc:: drivers/base/trust.c
+   :export:
diff --git a/Documentation/driver-api/driver-model/index.rst b/Documentation/driver-api/driver-model/index.rst
index abeb4b36636b..af547cd13b2c 100644
--- a/Documentation/driver-api/driver-model/index.rst
+++ b/Documentation/driver-api/driver-model/index.rst
@@ -9,6 +9,7 @@ Driver Model
    bus
    design-patterns
    device
+   device-trust
    devres
    driver
    overview

-- 
2.56.1


  parent reply	other threads:[~2026-12-03 12:05 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 12:03 [PATCH v5 00/33] driver core: Authorize device trust before driver binding Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 01/33] wifi: mac80211_hwsim: lock device for manual " Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 02/33] Bluetooth: btusb: Fix MediaTek ISO claim locking Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 03/33] USB: Lock interfaces during manual driver binding Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 04/33] USB: serial: Register USB drivers with their owning module Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 05/33] USB: Reject claims of DT-disabled interfaces Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 06/33] USB: Reject usbfs connect requests for unregistered interfaces Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 07/33] USB: Release interface claims according to binding state Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 08/33] USB: Reject claims after interface registration failure Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 09/33] ALSA: usb-audio: Release interface claims when probe fails Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 10/33] USB: Pin modules for unregistered interface claims Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 11/33] USB: Add helpers to release unpublished " Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 12/33] USB: Unwind interface claims after registration or binding failure Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 13/33] PNP: Attach card devices through the driver core Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 14/33] cdx: Propagate DMA configuration errors Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 15/33] driver core: Report deferred probes through sysfs drivers_probe Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 16/33] driver core: Add a compatibility API for manual driver attachment Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 17/33] Input: gameport - use the compatibility driver attachment API Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 18/33] Input: serio " Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 19/33] net: phy: Use " Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 20/33] USB: Drain usbfs when a device is unregistered Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 21/33] driver core: Introduce a generic device trust level Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 22/33] driver core: Expose device trust authorization interfaces Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 23/33] driver core: Accept device trust policy on the kernel command line Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 24/33] driver core: Accept device trust policy by driver name Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 25/33] driver core: Expose committed device trust level Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 26/33] driver core: Cover trust authorization and binding with KUnit Leon Romanovsky
2026-12-03 12:03 ` Leon Romanovsky [this message]
2026-12-03 12:03 ` [PATCH v5 28/33] PCI: Use device trust for platform restrictions Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 29/33] iommu: Use device trust for DMA restrictions Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 30/33] driver core: Allow driver attachment with the device lock held Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 31/33] USB: Retain the result of configuration requests Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 32/33] USB: Authorize interfaces through device trust Leon Romanovsky
2026-12-03 12:03 ` [PATCH v5 33/33] USB: Authorize devices " Leon Romanovsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261203-device-trust-core-v5-27-485cc6eddd46@nvidia.com \
    --to=leon@kernel.org \
    --cc=aik@amd.com \
    --cc=akpm@linux-foundation.org \
    --cc=akpm@osdl.org \
    --cc=alexander.h.duyck@linux.intel.com \
    --cc=andrew@lunn.ch \
    --cc=baolu.lu@linux.intel.com \
    --cc=bhelgaas@google.com \
    --cc=bvanassche@acm.org \
    --cc=chris.lu@mediatek.com \
    --cc=corbet@lwn.net \
    --cc=cornelia.huck@de.ibm.com \
    --cc=dakr@kernel.org \
    --cc=davem@davemloft.net \
    --cc=djbw@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=driver-core@lists.linux.dev \
    --cc=dwmw2@infradead.org \
    --cc=edumazet@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=gregkh@suse.de \
    --cc=hkallweit1@gmail.com \
    --cc=iommu@lists.linux.dev \
    --cc=jeff@garzik.org \
    --cc=jgg@ziepe.ca \
    --cc=johan@kernel.org \
    --cc=johannes@sipsolutions.net \
    --cc=joro@8bytes.org \
    --cc=kuba@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=luiz.dentz@gmail.com \
    --cc=luiz.von.dentz@intel.com \
    --cc=lukas@wunner.de \
    --cc=mans@mansr.com \
    --cc=marcel@holtmann.org \
    --cc=netdev@vger.kernel.org \
    --cc=nikhil.agarwal@amd.com \
    --cc=nipun.gupta@amd.com \
    --cc=pabeni@redhat.com \
    --cc=perex@perex.cz \
    --cc=pieter.jansen-van-vuuren@amd.com \
    --cc=rafael.j.wysocki@intel.com \
    --cc=rafael@kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=robin.murphy@arm.com \
    --cc=skhan@linuxfoundation.org \
    --cc=stern@rowland.harvard.edu \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=tiwai@suse.com \
    --cc=vasant.hegde@amd.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox