thunderbolt: Automatically authorize PCIe tunnels when IOMMU is active
Subsystems (2)
RFC 1/1 thunderbolt: Automatically authorize PCIe tunnels when IOMMU is active
Historically TBT3 in Linux used "Thunderbolt security levels" as a primary means of "security" against DMA attacks. This mean that users would need to ack any device plugged in via userspace. In ~2018 machines started to use the IOMMU for protection, but instead of dropping security levels a convoluted flow was introduced:
* User hotplugs device
* Driver discovers supported tunnels
* Driver emits a uevent to userspace that a PCIe tunnel is present
* Userspace reads 'iommu_dma_protection' attribute (which currently indicates an Intel IOMMU is present and was enabled pre-boot not that it's active "now")
* Based on that value userspace then authorizes automatically or prompts the user like how security level based support worked.
This is further confused because a pre-OS CM may authorize PCIe tunnels and the Linux USB4 CM will re-use tunnels if the paths discovered are the same. This means if you plug in a dock pre-boot it works in Linux immediately, but if you plug it in after boot you need to authorize it with userspace.
All the hand waving malarkey should be unnecessary when the IOMMU translation layer is active.
* First detect that the firmware has allowed PCIe tunnels to be created.
* Then check if an IOMMU domain is assigned to the NHI.
- If it is, set TBT security level to "NONE".
- If it is not, leave things as before.
* Lastly when a port is scanned via tb_scan_port, check the security level.
* If it was set as "NONE", create the PCIe tunnel and update the 'authorized' attribute to reflect this.
---
Remaining items to be done/investigated/discussed:
* Documentation updates for this
* Is this a good enough method to check IOMMU is active?
* Should the IOMMU check be on PCIe root port for tunneling instead of the router? If so, need to discover it via the device link (possibly at time of device link creation).
* Maybe create a TBT new security level definition "iommu" that functionally behaves same to "none" to make things clearer to userspace how the device was authorized.
* Drop iommu_dma_protection attribute?
drivers/thunderbolt/tb.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/thunderbolt/tb.c +15 -1
@@ -6,6 +6,7 @@* Copyright (C) 2019, Intel Corporation */ +#include <linux/iommu.h> #include <linux/slab.h> #include <linux/errno.h> #include <linux/delay.h>
@@ -18,6 +19,8 @@#define TB_TIMEOUT 100/* ms */ +static int tb_tunnel_pci (struct tb *tb,struct tb_switch *sw); +/** * struct tb_cm - Simple Thunderbolt connection manager * @tunnel_list: List of active tunnels
@@ -690,6 +693,16 @@ static void tb_scan_port(struct tb_port *port)if (tcm->hotplug_active &&tb_tunnel_usb3 (sw->tb, sw))tb_sw_warn (sw,"USB3 tunnel creation failed\n" ); +/* +* Create PCIe tunnels if security has been turned off +* (such as by IOMMU translation enabled) +*/ +if (port->sw->tb->security_level ==TB_SECURITY_NONE ) { +if (tb_tunnel_pci (port->sw->tb, sw)) +tb_sw_warn (sw,"PCIe tunnel creation failed\n" ); +else + sw->authorized =1 ; + }tb_add_dp_resources (sw);tb_scan_switch (sw); }
@@ -1702,7 +1715,8 @@ struct tb *tb_probe(struct tb_nhi *nhi)return NULL ;if (tb_acpi_may_tunnel_pcie ()) - tb->security_level =TB_SECURITY_USER ; + tb->security_level =iommu_get_domain_for_dev (&nhi->pdev->dev) ? +TB_SECURITY_NONE :TB_SECURITY_USER ;else tb->security_level =TB_SECURITY_NOPCIE ;
Signature · 1 line
2.34.1
Hi Mario,
Quoted 5 lines · Mario Limonciello
Historically TBT3 in Linux used "Thunderbolt security levels" as a primary means of "security" against DMA attacks. This mean that users would need to ack any device plugged in via userspace. In ~2018 machines started to use the IOMMU for protection, but instead of dropping security levels a convoluted flow was introduced:
Quoted 8 lines
* User hotplugs device
* Driver discovers supported tunnels
* Driver emits a uevent to userspace that a PCIe tunnel is present
* Userspace reads 'iommu_dma_protection' attribute (which currently indicates an Intel IOMMU is present and was enabled pre-boot not that it's active "now")
* Based on that value userspace then authorizes automatically or prompts the user like how security level based support worked.
There are legitimate reasons to disable PCIe tunneling even if the IOMMU bits are in place. The ACPI _OSC allows the boot firmware to do so and our "security levels" allows the userspace policy to do the same. I would not like to change that unless absolutely necessary.
[AMD Official Use Only]
Quoted 29 lines
-----Original Message-----
From: Mika Westerberg <[email protected]>
Sent: Wednesday, March 16, 2022 01:30
To: Limonciello, Mario <[email protected]>
Cc: Andreas Noever <[email protected]>; Michael Jamet <[email protected]>; Yehezkel Bernat <[email protected]>; open list:THUNDERBOLT DRIVER <[email protected]>; open list <[email protected]>
Subject: Re: [RFC] thunderbolt: Automatically authorize PCIe tunnels when IOMMU is activeHi Mario,
Quoted 2 lines · Mario Limonciello
Historically TBT3 in Linux used "Thunderbolt security levels" as a primary means of "security" against DMA attacks. This mean that users would need
to
Quoted 11 lines
ack any device plugged in via userspace. In ~2018 machines started to use the IOMMU for protection, but instead of dropping security levels a convoluted flow was introduced:
* User hotplugs device
* Driver discovers supported tunnels
* Driver emits a uevent to userspace that a PCIe tunnel is present
* Userspace reads 'iommu_dma_protection' attribute (which currently indicates an Intel IOMMU is present and was enabled pre-boot not that it's active "now")
* Based on that value userspace then authorizes automatically or prompts the user like how security level based support worked.
Quoted 4 lines
There are legitimate reasons to disable PCIe tunneling even if the IOMMU bits are in place. The ACPI
_OSCallows the boot firmware to do so and our "security levels" allows the userspace policy to do the same. I would not like to change that unless absolutely necessary.
Actually I intentionally left that in the RFC patch, to only do this based off of tb_acpi_may_tunnel_pcie, so I think that should still work as you described if boot firmware turned off PCIe tunneling.
Quoted 33 lines · Mario
[AMD Official Use Only]
Quoted 29 lines
-----Original Message-----
From: Mika Westerberg <[email protected]>
Sent: Wednesday, March 16, 2022 01:30
To: Limonciello, Mario <[email protected]>
Cc: Andreas Noever <[email protected]>; Michael Jamet <[email protected]>; Yehezkel Bernat <[email protected]>; open list:THUNDERBOLT DRIVER <[email protected]>; open list <[email protected]>
Subject: Re: [RFC] thunderbolt: Automatically authorize PCIe tunnels when IOMMU is activeHi Mario,
Quoted 2 lines · Mario Limonciello
Historically TBT3 in Linux used "Thunderbolt security levels" as a primary means of "security" against DMA attacks. This mean that users would need
to
Quoted 11 lines
ack any device plugged in via userspace. In ~2018 machines started to use the IOMMU for protection, but instead of dropping security levels a convoluted flow was introduced:
* User hotplugs device
* Driver discovers supported tunnels
* Driver emits a uevent to userspace that a PCIe tunnel is present
* Userspace reads 'iommu_dma_protection' attribute (which currently indicates an Intel IOMMU is present and was enabled pre-boot not that it's active "now")
* Based on that value userspace then authorizes automatically or prompts the user like how security level based support worked.
Quoted 8 lines
Quoted 4 lines
There are legitimate reasons to disable PCIe tunneling even if the IOMMU bits are in place. The ACPI
_OSCallows the boot firmware to do so and our "security levels" allows the userspace policy to do the same. I would not like to change that unless absolutely necessary.Actually I intentionally left that in the RFC patch, to only do this based off of
tb_acpi_may_tunnel_pcie, so I think that should still work as you described if boot firmware turned off PCIe tunneling.
Right but if the user still wants to disable it, like say you are travelling and you want to be sure that no PCIe devices get attached while your laptop is charging from a public "charging station" (whatever is the right term).
[Public]
Quoted 32 lines
Quoted 7 lines
Quoted 7 lines
IOMMU is active
Hi Mario,
Quoted 2 lines · Mario Limonciello
Historically TBT3 in Linux used "Thunderbolt security levels" as a primary means of "security" against DMA attacks. This mean that users would
need
Quoted 2 lines
Quoted 2 lines
to
Quoted 1 line
ack any device plugged in via userspace. In ~2018 machines started to
use
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
the IOMMU for protection, but instead of dropping security levels a convoluted flow was introduced:
* User hotplugs device
* Driver discovers supported tunnels
* Driver emits a uevent to userspace that a PCIe tunnel is present
* Userspace reads 'iommu_dma_protection' attribute (which currently indicates an Intel IOMMU is present and was enabled pre-boot notthat
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
it's active "now")
* Based on that value userspace then authorizes automatically orprompts
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
the user like how security level based support worked.
There are legitimate reasons to disable PCIe tunneling even if the
IOMMU
Quoted 6 lines
Quoted 3 lines
bits are in place. The ACPI
_OSCallows the boot firmware to do so and our "security levels" allows the userspace policy to do the same. I would not like to change that unless absolutely necessary.Actually I intentionally left that in the RFC patch, to only do this based off of
tb_acpi_may_tunnel_pcie, so I think that should still work as you
Quoted 7 lines
described
Quoted 1 line
if boot firmware turned off PCIe tunneling.
Right but if the user still wants to disable it, like say you are travelling and you want to be sure that no PCIe devices get attached while your laptop is charging from a public "charging station" (whatever is the right term).
So wouldn't you flip the default in BIOS setup to disable PCIe tunnels then for this use case?
Otherwise with how it is today you end up with the PCIe tunnel created in the boot FW and then coming into the OS if it's the same path the tunnel stays in place with no opportunity for userspace to authorize it, no?
Quoted 37 lines · Mario
[Public]
Quoted 35 lines
Quoted 7 lines
Quoted 7 lines
IOMMU is active
Hi Mario,
Quoted 2 lines · Mario Limonciello
Historically TBT3 in Linux used "Thunderbolt security levels" as a primary means of "security" against DMA attacks. This mean that users would
need
Quoted 2 lines
Quoted 2 lines
to
Quoted 1 line
ack any device plugged in via userspace. In ~2018 machines started to
use
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
the IOMMU for protection, but instead of dropping security levels a convoluted flow was introduced:
* User hotplugs device
* Driver discovers supported tunnels
* Driver emits a uevent to userspace that a PCIe tunnel is present
* Userspace reads 'iommu_dma_protection' attribute (which currently indicates an Intel IOMMU is present and was enabled pre-boot notthat
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
it's active "now")
* Based on that value userspace then authorizes automatically orprompts
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
the user like how security level based support worked.
There are legitimate reasons to disable PCIe tunneling even if the
IOMMU
Quoted 6 lines
Quoted 3 lines
bits are in place. The ACPI
_OSCallows the boot firmware to do so and our "security levels" allows the userspace policy to do the same. I would not like to change that unless absolutely necessary.Actually I intentionally left that in the RFC patch, to only do this based off of
tb_acpi_may_tunnel_pcie, so I think that should still work as youdescribed
Quoted 1 line
if boot firmware turned off PCIe tunneling.
Quoted 7 lines
Quoted 4 lines
Right but if the user still wants to disable it, like say you are travelling and you want to be sure that no PCIe devices get attached while your laptop is charging from a public "charging station" (whatever is the right term).
So wouldn't you flip the default in BIOS setup to disable PCIe tunnels then for this use case?
What if you are on Chromebook? Or something where this is not user configurable?
Quoted 3 lines
Otherwise with how it is today you end up with the PCIe tunnel created in the boot FW and then coming into the OS if it's the same path the tunnel stays in place with no opportunity for userspace to authorize it, no?
The boot FW does not need to support CM capabilites nor does it need to provide the ACPI _OSC.
[Public]
Quoted 18 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Actually I intentionally left that in the RFC patch, to only do this based
off
Quoted 10 lines
Quoted 8 lines
Quoted 1 line
of
tb_acpi_may_tunnel_pcie, so I think that should still work as youdescribed
Quoted 1 line
if boot firmware turned off PCIe tunneling.
Right but if the user still wants to disable it, like say you are travelling and you want to be sure that no PCIe devices get attached while your laptop is charging from a public "charging station" (whatever is the right term).
So wouldn't you flip the default in BIOS setup to disable PCIe tunnels then
for
Quoted 1 line
this use case?
What if you are on Chromebook? Or something where this is not user configurable?
Quoted 7 lines
Quoted 1 line
Otherwise with how it is today you end up with the PCIe tunnel created in
the
Quoted 2 lines
boot FW and then coming into the OS if it's the same path the tunnel stays in place with no opportunity for userspace to authorize it, no?
The boot FW does not need to support CM capabilites nor does it need to provide the ACPI
_OSC.
Ah right - my thoughts were entirely UEFI firmware centric. Chromebooks don't have BIOS setup, nor do they all have the USB4 _OSC.
Then yes I agree we do need to "keep" this authorization decision in userspace.