systemd 263-rc2 Can Automatically Authorize Thunderbolt and USB4 Devices Early in Boot
The article's text, from Joho no Todai's page.
If unlocking encrypted storage requires a password, the keyboard needs to work early in boot. When the keyboard is plugged into a Thunderbolt dock and depends on an authorized PCI Express (PCIe) connection, the timing of that authorization matters.
On December 4, the team behind Linux's system and service manager released systemd 263-rc2 for testing ahead of the stable release. The release candidate follows 263-rc1, which added components written in Rust, among other changes.
A change merged into the development branch on November 29 adds a rule to automatically authorize Thunderbolt and USB4 devices in udev, which handles events such as device connections.
On supported systems, the new rule enables automatic authorization in the initrd. The initrd is the environment that runs before the main operating system starts. It handles tasks that need to happen before regular services are available.
The developers said the change is meant to make keyboards and storage plugged into a dock usable before boltd starts. The daemon ordinarily manages connected devices.
Why external devices need authorization
Thunderbolt and USB4 can carry PCIe traffic to devices on the other end of a cable. Some PCIe devices use direct memory access (DMA), which lets them access memory without going through the CPU.
Without appropriate DMA restrictions, an external device could read memory without authorization. The Linux kernel documentation describes how devices must be authorized before a PCIe tunnel is established at the user or secure security level.
An input-output memory management unit (IOMMU) manages how peripherals access memory. On systems where an IOMMU provides Thunderbolt DMA protection, it can restrict which areas of memory a device can access to those allocated by its driver.
When the IOMMU blocks unauthorized DMA, manually authorizing every device is less important for memory protection. The kernel exposes whether DMA protection is active, giving systemd the information it needs to decide whether to authorize a device automatically.
systemd 263-rc2: Thunderbolt and USB4 Auto-Authorization Criteria
| When an unauthorized device is added to the Thunderbolt subsystem | ||
|---|---|---|
| Security level | IOMMU DMA protection active | IOMMU DMA protection inactive |
| user | Automatically authorized | Rule does not apply |
| secure | Rule does not apply | Rule does not apply |
DMA protection and the security level determine eligibility
The 80-thunderbolt.rules file in 263-rc2 automatically authorizes a device when all of the following conditions are met.
- udev receives a device add event.
- The device belongs to the Thunderbolt subsystem.
- The domain managing the connection reports
iommu_dma_protectionas1, indicating that IOMMU DMA protection is active. - The domain's security level is set to
user. - The device's
authorizedvalue is0, indicating that it is unauthorized.
The rule checks whether IOMMU protection is active. A system can have an IOMMU and still leave a domain without DMA protection. The rule gives that domain no automatic authorization.
The rule leaves devices at the secure security level to the existing authorization process. At the secure level, supported devices can use a stored key to prove their identity.
An IOMMU limits the memory a device can access. Deciding whether to allow that device to connect and verifying its identity serve a separate purpose.
What changes when authorization happens before boltd starts
On February 23, a systemd user asked the development team to have udev authorize Thunderbolt devices on systems protected by an IOMMU.
systemd 263-rc2: Thunderbolt and USB4 Authorization and Enrollment
| user security level with IOMMU DMA protection active When an unauthorized device is added to the Thunderbolt subsystem | ||
|---|---|---|
| Comparison | udev (new rule) | boltd |
| Early boot authorization | Can authorize before boltd starts | Requires boltd to start |
| New device enrollment | Rule only authorizes | Authorizes and enrolls |
The bolt documentation says that bolt automatically authorizes and enrolls new devices when IOMMU protection is active. Some systems also have a firmware feature that can authorize devices before boot.
The user wanted to reduce the need to include and run boltd in the initrd just to use devices there.
When the user tested a similar udev rule in the initrd, bolt stopped enrolling devices on that system. The user also reported that removing an enrolled device from bolt's records did nothing to prevent it from reconnecting.
On December 3, a report in the development discussion said the Thunderbolt settings panel in GNOME no longer worked correctly. A user asked the developers to consider reverting the rule. The author and the developer who merged it said a fix was needed in bolt.
If udev authorizes devices before boltd can handle them, bolt's enrollment records can diverge from the list of devices that actually work. Where device authorization and enrollment are managed also affects how much control users have over connections.
Making boot easier while keeping control over connections
To benefit early in boot, the Linux distribution's initrd must include the new udev rule and have the required drivers available when the rule runs.
Administrators who want to change how devices are authorized can disable the default rule by making /etc/udev/rules.d/80-thunderbolt.rules a symbolic link to /dev/null, as described in udev's rule loading documentation. To apply the change early in boot, include it in the initrd as well.
Disabling the rule affects udev's new automatic authorization behavior alone. Once boltd starts, automatic authorization follows bolt's settings and the state of IOMMU protection. If you use a docked keyboard to unlock storage, have another way to enter the password before disabling the rule.
Typing a password to unlock encrypted storage is routine, yet it depends on when a peripheral is authorized. The change makes use of hardware memory protection to reduce dependencies early in boot.
A keyboard attached to a dock should work when you need it. Your ability to decide which devices can connect matters too.
