-
Notifications
You must be signed in to change notification settings - Fork 416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AMD SPI lock check #4094
Comments
On a related note, AMD also documents (somewhat poorly) the memory mappings of SPI ROM. There are in fact a couple registers that hold the low and high addresses where the ROM is mapped. |
Yeah no relying on accessing things you can't from userspace when locked down.
FYI, for at least one product the PPR is also published for family 19h recently. It's slightly different, so yes the behavior would need to be model dependent. |
Thanks I missed that and only had the useless « preliminary » version. For the record, the corresponding section (looks like they changed the naming convention but the procedure is the same):
So I guess the best approach here is to (a) keep an eye on changes to Intel driver to see if a common or similar approach can be found for both, and (b) reach out to AMD maintainer to think about exposing this information. |
Is that io space? @zaolin seemed to think that you could read some of that even with things locked down -- although no idea if that's goig to work longer term. I also think the work by @dgutson is probably the way we want to go; i.e. have a sysfs class that drivers can just "implement" -- I believe the consensus was that the concept was sound but there was some bikesheding on the name itself. The idea was to ask @kees for some help actually getting this over the finishing line. Some context for Kees -- https://lwn.net/Articles/824829/ I'm also really crossing my fingers for a |
While I'd welcome the @kerneis-anssi If the SPI_BASE_ADDRESS is a PCI BAR you can access the memory region through /dev/mem, given the kernel is not in the most strict lockdown mode. Alternatively you could use VFIO to map that BAR into userspace with the additional upside of being able to receive interrupts. This way you could implement the whole SPI driver in userspace. The flashrom project does that for hardware sequencing on the Intel SPI controller albeit via /dev/mem. The implementation for VFIO should be more or less the same. |
@kerneis-anssi is there anything I can help unblock here? I've got AMD hardware now and can help move this along myself if that would be helpful. |
I'm not sure what @flanfly calls "the most strict lockdown mode". Basically there are three flavors of lockdown:
Opening /dev/mem (let alone reading any part of it) is disabled in both integrity and confidentiality mode: see https://elixir.bootlin.com/linux/v5.4.23/source/security/lockdown/lockdown.c#L19 (DEV_MEM is before INTEGRITY_MAX in the list). I need is to be able to read memory area 0xFEC10000—0xFEC10020, which corresponds to SPI_BASE and appears as |
@flanfly Even though I don't need to implement the SPI driver at all (because I don't care about dumping the rom at this stage), I'm very interested when you mention "you could use VFIO to map that BAR into userspace". Do you have any example code where this is done, or pointers to API documentation? |
Probably the best way to deal with this kind of this is with a legit kernel driver and expose a sysfs node for the setting you're interested in. i.e. I recommend getting the original patch series mentioned in the description dusted off, fixed up, and resent: |
And while you're at it, this one too: |
We'll look into it with a colleague of mine. Also got a tip that ROM protection may change on future AMD boards, so it makes even more sense to try and have a single sysfs feature for the various implementations instead of having the complexity in fwupd. Edit: it's not new, and it's not documented at all :-( but here you go, the only details available about ROM Armor: https://twitter.com/vpikhur/status/1458519177115832328 |
for reading out info via chipsec, @kerneis-anssi's script in a gist: |
When fwupd checks for SPI write protection status, is that something that can be toggled via kernel configuration? e.g., would CONFIG_SPI = n or CONFIG_SPI_SPIDEV = n enable SPI write protection? I have an AMD laptop reporting SPI replay protection as enabled but SPI write protection as disabled, and am trying to determine if there is a bug anywhere. The kernel has lockdown enabled (integrity) and the BIOS doesn't have any SPI toggles. Pardon my asking here, there was little discussion of this specific topic anywhere else that I could find. |
It's very unlikely to be a bug in fwupd or the kernel. They reflect the state exported by the platform. |
I have investigated how to implement a check that the BIOS sets the correct flags on AMD platforms to prevent SPI overwrite.
AMD PPR for family 17h has the following text:
RomProtect in point 1 lives in PCI configuration space, so should be accessible via sysfs. However, the rest of the registers are mapped in main memory: SPIx04 means SPI_BASE_ADDRESS + 0x04, where SPI_BASE_ADDRESS is outside of PCI config space (in practice it's 0xFEC10000, but it's also stored as a PCI config if we don't want to hard code it). Therefore, I don't see a way to access it on a locked down or strict_dev_mem kernel. Debian — and I guess other distributions — has a patch to enable lock down automatically when secure boot is enabled.
In principle, this is something similar to Intel's BIOS Lock Enable and friends, and we'd like the kernel to export it. Given that the latest attempt I could find to do that for Intel was abandoned a year ago, I'm not sure how much hope there is on that front. cc @dgutson
There is one driver right now in the kernel that accesses this memory space: the amd-spi driver. I'm not clear how SPI drivers are plumbed in the kernel, but looking at the code and the AMD spec, I can guess that SPI_BASE_ADDRESS ends up being assigned to
amd_spi.io_remap_addr
in that code. The code does not access or checks the lock flags though, and I'm don't think it belongs to a SPI driver to do that. We could try and reach out to the AMD maintainer of that driver.Any thought?
The text was updated successfully, but these errors were encountered: