[PATCH v3 20/31] driver core: Expose device trust authorization interfaces
From: Leon Romanovsky
Date: Wed Nov 18 2026 - 14:34:59 EST
From: Leon Romanovsky <leonro@xxxxxxxxxx>
An initrd must be able to authorize a blocked device after attestation and
distinguish that permission from a successful driver binding. Existing bus
authorization interfaces also need a way to grant access without bypassing
the common policy.
Expose policy and active trust through sysfs, with shared authorization
rules for bus callers. Authorizing a blocked device fixes the choice for
its lifetime, so a failed probe cannot reopen the decision. Require boot
opt-in for the new writable interface to preserve legacy attachment
assumptions.
Signed-off-by: Leon Romanovsky <leonro@xxxxxxxxxx>
---
Documentation/ABI/testing/sysfs-devices-trust | 32 +++++++
MAINTAINERS | 1 +
drivers/base/base.h | 2 +
drivers/base/core.c | 15 ++-
drivers/base/trust.c | 129 ++++++++++++++++++++++++++
include/linux/device.h | 5 +
include/linux/device/trust.h | 3 +
7 files changed, 186 insertions(+), 1 deletion(-)
diff --git a/Documentation/ABI/testing/sysfs-devices-trust b/Documentation/ABI/testing/sysfs-devices-trust
new file mode 100644
index 0000000000000..154c5577c65e0
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-devices-trust
@@ -0,0 +1,32 @@
+What: /sys/devices/.../trust
+Date: September 2026
+Contact: driver-core@xxxxxxxxxxxxxxx
+Description:
+ (RO) The active trust level for the device. The values are
+ "blocked", "adversary", and "unrestricted". Driver core resolves
+ the level before driver setup and retains it through DMA
+ cleanup. It is "blocked" outside a binding transaction.
+
+What: /sys/devices/.../trust_policy
+Date: September 2026
+Contact: driver-core@xxxxxxxxxxxxxxx
+Description:
+ (RW) The requested trust policy for the device. The initial
+ value may be selected by the bus before the device is
+ registered; otherwise it is "default". The policy is resolved
+ to an active trust level before the device is probed.
+
+ Changes through this attribute require an explicit device
+ trust boot option. Any such option selects an implicit
+ blocked default; use device_trust.default=default to
+ enable them while preserving bus policy. Without one,
+ only writing the current policy succeeds. Existing bus
+ authorization interfaces remain available. Explicit unrestricted
+ policy disables runtime policy changes.
+
+ The values are "default", "blocked", "adversary", and
+ "unrestricted". "default" lets the bus select the operating level.
+ "blocked" prevents driver binding. "adversary" requests
+ classification as potentially malicious. "unrestricted" requests
+ normal operation. Adversary protections depend on bus, DMA,
+ and driver support; classification alone adds none.
diff --git a/MAINTAINERS b/MAINTAINERS
index b726344362b41..a145aaaca2ef3 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8150,6 +8150,7 @@ L: driver-core@xxxxxxxxxxxxxxx
S: Supported
T: git git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git
F: Documentation/ABI/testing/sysfs-bus-drivers-probe
+F: Documentation/ABI/testing/sysfs-devices-trust
F: Documentation/core-api/kobject.rst
F: Documentation/driver-api/driver-model/
F: drivers/base/
diff --git a/drivers/base/base.h b/drivers/base/base.h
index 56f1a9c73964b..1e7ee9856fe6f 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -195,6 +195,8 @@ void device_release_driver_internal(struct device *dev, const struct device_driv
int device_private_init(struct device *dev);
+extern const struct attribute_group device_trust_attr_group;
+
/* Unrestricted-only manual attachment uses the caller's subsystem serialization. */
void device_trust_init_state(struct device *dev);
int device_trust_prepare_unrestricted(struct device *dev,
diff --git a/drivers/base/core.c b/drivers/base/core.c
index c0006b3aa38f7..e72424618d622 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -2999,10 +2999,14 @@ static int device_add_attrs(struct device *dev)
if (error)
goto err_remove_type_groups;
+ error = device_add_group(dev, &device_trust_attr_group);
+ if (error)
+ goto err_remove_dev_groups;
+
if (device_supports_offline(dev) && !dev_offline_disabled(dev)) {
error = device_create_file(dev, &dev_attr_online);
if (error)
- goto err_remove_dev_groups;
+ goto err_remove_dev_trust_group;
}
if (fw_devlink_flags && !fw_devlink_is_permissive() && dev->fwnode) {
@@ -3032,6 +3036,8 @@ static int device_add_attrs(struct device *dev)
device_remove_file(dev, &dev_attr_waiting_for_supplier);
err_remove_dev_online:
device_remove_file(dev, &dev_attr_online);
+ err_remove_dev_trust_group:
+ device_remove_group(dev, &device_trust_attr_group);
err_remove_dev_groups:
device_remove_groups(dev, dev->groups);
err_remove_type_groups:
@@ -3057,6 +3063,7 @@ static void device_remove_attrs(struct device *dev)
device_remove_file(dev, &dev_attr_removable);
device_remove_file(dev, &dev_attr_waiting_for_supplier);
device_remove_file(dev, &dev_attr_online);
+ device_remove_group(dev, &device_trust_attr_group);
device_remove_groups(dev, dev->groups);
if (type)
@@ -4809,6 +4816,12 @@ static int device_attrs_change_owner(struct device *dev, kuid_t kuid,
if (error)
return error;
+ /* Change the trust attributes of @dev to @kuid/@kgid. */
+ error = sysfs_group_change_owner(kobj, &device_trust_attr_group, kuid,
+ kgid);
+ if (error)
+ return error;
+
if (device_supports_offline(dev) && !dev_offline_disabled(dev)) {
/* Change online device attributes of @dev to @kuid/@kgid. */
error = sysfs_file_change_owner(kobj, dev_attr_online.attr.name,
diff --git a/drivers/base/trust.c b/drivers/base/trust.c
index 35893786a163d..215ea6151ecfc 100644
--- a/drivers/base/trust.c
+++ b/drivers/base/trust.c
@@ -5,6 +5,7 @@
#include <linux/export.h>
#include <linux/init.h>
#include <linux/string.h>
+#include <linux/sysfs.h>
#include "base.h"
@@ -155,6 +156,134 @@ static const char * const device_trust_policy_names[] = {
[DEVICE_TRUST_POLICY_UNRESTRICTED] = "unrestricted",
};
+static const char * const device_trust_level_names[] = {
+ [DEVICE_TRUST_BLOCKED] = "blocked",
+ [DEVICE_TRUST_ADVERSARY] = "adversary",
+ [DEVICE_TRUST_UNRESTRICTED] = "unrestricted",
+};
+
+static ssize_t trust_show(struct device *dev,
+ const struct device_attribute *attr, char *buf)
+{
+ return sysfs_emit(buf, "%s\n",
+ device_trust_level_names[device_get_trust_level(dev)]);
+}
+static DEVICE_ATTR_RO(trust);
+
+static ssize_t trust_policy_show(struct device *dev,
+ const struct device_attribute *attr, char *buf)
+{
+ return sysfs_emit(buf, "%s\n",
+ device_trust_policy_names[READ_ONCE(dev->trust_policy)]);
+}
+
+static bool device_trust_policy_frozen(void)
+{
+ return device_trust_configured &&
+ device_trust_default_policy == DEVICE_TRUST_POLICY_UNRESTRICTED;
+}
+
+/**
+ * device_trust_set_policy_locked - Request policy with the device locked
+ * @dev: registered device
+ * @policy: requested policy
+ *
+ * Apply the admission rules while the caller holds the device lock.
+ *
+ * Return: 0 on success, -EBUSY if the policy can no longer change, or
+ * -ENODEV if the device is being removed outside explicit unrestricted mode.
+ */
+int device_trust_set_policy_locked(struct device *dev,
+ enum device_trust_policy policy)
+{
+ device_lock_assert(dev);
+ if (device_trust_policy_frozen())
+ return policy == dev->trust_policy ? 0 : -EBUSY;
+ if (dev->p->dead)
+ return -ENODEV;
+ if (policy == dev->trust_policy)
+ goto set_policy;
+
+ if (dev->driver)
+ return -EBUSY;
+
+ switch (dev->p->trust_state) {
+ case DEVICE_TRUST_SELECTABLE:
+ if (policy == DEVICE_TRUST_POLICY_BLOCKED)
+ dev->p->trust_state = DEVICE_TRUST_WAITING;
+ break;
+ case DEVICE_TRUST_WAITING:
+ if (policy != DEVICE_TRUST_POLICY_ADVERSARY &&
+ policy != DEVICE_TRUST_POLICY_UNRESTRICTED)
+ return -EBUSY;
+ dev->p->trust_state = DEVICE_TRUST_AUTHORIZED;
+ break;
+ default:
+ return -EBUSY;
+ }
+set_policy:
+ WRITE_ONCE(dev->trust_policy, policy);
+ return 0;
+}
+EXPORT_SYMBOL_GPL(device_trust_set_policy_locked);
+
+/**
+ * device_trust_set_policy - Request a trust policy for a device
+ * @dev: registered device
+ * @policy: requested policy
+ *
+ * Apply admission rules, including on legacy boots where trust_policy writes
+ * are unavailable. Buses with their own authorization interfaces may use this
+ * API. Callers of device_driver_attach_unrestricted() must preserve its invariants.
+ *
+ * Takes the device lock except in explicit unrestricted mode, where a same-policy
+ * request is a no-op and does not override a pending driver boot rule.
+ *
+ * Return: 0 on success, -EBUSY if the policy can no longer change, or
+ * -ENODEV if the device is being removed outside explicit unrestricted mode.
+ */
+int device_trust_set_policy(struct device *dev, enum device_trust_policy policy)
+{
+ int ret;
+
+ if (device_trust_policy_frozen())
+ return policy == READ_ONCE(dev->trust_policy) ? 0 : -EBUSY;
+
+ device_lock(dev);
+ ret = device_trust_set_policy_locked(dev, policy);
+ device_unlock(dev);
+ return ret;
+}
+EXPORT_SYMBOL_GPL(device_trust_set_policy);
+
+static ssize_t trust_policy_store(struct device *dev,
+ const struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ int policy, ret;
+
+ policy = sysfs_match_string(device_trust_policy_names, buf);
+ if (policy < 0)
+ return policy;
+
+ if (!device_trust_configured)
+ return policy == READ_ONCE(dev->trust_policy) ? count : -EBUSY;
+
+ ret = device_trust_set_policy(dev, policy);
+
+ return ret ? ret : count;
+}
+static DEVICE_ATTR_RW(trust_policy);
+
+static struct attribute *device_trust_attrs[] = {
+ &dev_attr_trust.attr,
+ &dev_attr_trust_policy.attr,
+ NULL,
+};
+
+const struct attribute_group device_trust_attr_group = {
+ .attrs = device_trust_attrs,
+};
static int __init device_trust_default_setup(char *str)
{
int policy = match_string(device_trust_policy_names,
diff --git a/include/linux/device.h b/include/linux/device.h
index 702eb66b81bf3..2914b7191d342 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -933,6 +933,11 @@ static inline bool device_iommu_mapped(struct device *dev)
return (dev->iommu_group != NULL);
}
+static inline bool device_policy_is_blocked(const struct device *dev)
+{
+ return READ_ONCE(dev->trust_policy) == DEVICE_TRUST_POLICY_BLOCKED;
+}
+
/* Get the wakeup routines, which depend on struct device */
#include <linux/pm_wakeup.h>
diff --git a/include/linux/device/trust.h b/include/linux/device/trust.h
index 32071f12ed257..b940dddf10e46 100644
--- a/include/linux/device/trust.h
+++ b/include/linux/device/trust.h
@@ -43,6 +43,9 @@ enum device_trust_policy {
void device_trust_init(struct device *dev);
int device_trust_prepare(struct device *dev, const struct device_driver *drv);
void device_trust_clear(struct device *dev);
+int device_trust_set_policy_locked(struct device *dev,
+ enum device_trust_policy policy);
+int device_trust_set_policy(struct device *dev, enum device_trust_policy policy);
enum device_trust_level device_get_trust_level(const struct device *dev);
bool device_is_adversarial(const struct device *dev);
--
2.56.1