WEBVTT

00:00.000 --> 00:04.180
It's either as a boot kit or in some cases as a firmware implant as we will see later.

00:04.620 --> 00:09.940
What's good also is that code here is hidden from the OS and the hypervisor.

00:10.100 --> 00:16.040
So antivirus, EDRs, or anti-cheat engines won't see these things, right?

00:16.660 --> 00:21.120
Now in terms of privilege level this is just a simplification but we can think about it like this.

00:21.120 --> 00:25.940
We have our applications, like for instance our browser, running at the very top of ring three.

00:25.940 --> 00:33.280
Then we have our OS, ring zero, and if we have a hypervisor it's down the OS of course and only then we have SMM.

00:33.740 --> 00:35.600
Now how does this work?

00:35.600 --> 00:39.640
We can divide the uh the thing in two phases.

00:39.640 --> 00:51.780
We have boot time where the firmware BIOS UFI code will after initializing the the hardware will load the SMM code into an special area of memory called SM RAM.

00:52.160 --> 01:00.180
And then it will hand off the execution to the OS loader then the OS loads and as you can see SMM is just a run time concept.

01:00.180 --> 01:02.760
It will provide services for the for the platform.

01:02.880 --> 01:07.760
For instance power management, security, and the OS can invoke some services from it as well.

01:08.600 --> 01:09.820
So how does that happen?

01:09.820 --> 01:12.760
Well there's this concept of system management interrupt.

01:12.760 --> 01:24.660
When an SMI occurs the processor gets interrupted and then this the the current register set of the processor is saved into the SM RAM into a safety area.

01:25.120 --> 01:34.280
And then whatever needs to happen happens some um good feature for the system and it then comes back to the OS.

01:34.280 --> 01:42.080
In this case we are doing a synchronous SMI like a software SMI the OS is um invoking a service from SMM.

01:42.940 --> 01:46.440
Now we've been working on this area for a bit.

01:46.620 --> 01:49.780
Uh we published some some blogs.

01:49.780 --> 01:51.680
We've done some some presentations before.

01:51.680 --> 01:53.120
How are you on Hexagon?

01:53.120 --> 02:02.220
We have a couple of CVEs in 2023 and we also released some tools for um checking for misconfigurations and known issues.

02:02.400 --> 02:11.220
Um all of these things that we've done before are mostly related to either misconfigurations from vendors or software vulnerabilities in components.

02:11.220 --> 02:17.100
Now we're going to present today is an architectural flaw in the AMD processor itself.

02:17.100 --> 02:18.440
So that's very different.

02:18.440 --> 02:23.260
And so for that we're going to just see again what is what makes the security of SMM.

02:23.500 --> 02:32.840
So we can think on the CPU when it's an SMM mode we have the memory controller in the middle and we can just access this area with where the SMM code and data lives.

02:32.840 --> 02:35.280
We can execute instructions from this area.

02:35.280 --> 02:37.500
We can write to this area and read.

02:37.620 --> 02:49.400
However when the CPU is in normal mode meaning non-SMM, the memory controller just rejects um if if you read from this uh from this memory you're just going to return receive Fs.

02:49.400 --> 02:52.280
Writes are discarded and of course execution is disallowed.

02:52.280 --> 02:54.860
How does this hap- how is this happening?

02:55.780 --> 03:01.340
Well we have um what's called a TSEC region or top of memory segment region.

03:01.380 --> 03:10.480
Essentially the firmware after loads uh after it loads SMM at boot time, it will hopefully configure these two registers.

03:10.800 --> 03:18.140
And the idea is to overlap um have this region to overlap with all the contents of SM RAM to protect it.

03:18.400 --> 03:23.100
We have uh two registers we have the TSEC base and the TSEC mask which is the length.

03:23.100 --> 03:27.060
The TSEC mask as you can see have also uh additional fields.

03:27.560 --> 03:30.100
And yeah essentially this is the way.

03:30.100 --> 03:40.240
The memory controller will see that uh the CPU is executing in normal mode and will just reject to read the content or write the content of the SM RAM.

03:40.520 --> 03:42.120
Has to be enabled.

03:42.120 --> 03:44.480
That's why the T-valid is there.

03:44.980 --> 03:58.160
Now the layout of SM RAM uh basically is up to the vendor to define but most systems out there are going to follow what the EDK2 has which is TianoCore.

03:58.160 --> 03:59.540
This is reference code.

03:59.980 --> 04:06.060
And uh essentially it's going to consist at the very bottom you can see here um SMM core area.

04:06.060 --> 04:10.360
This is just supporting code for the rest of of what's going to be in there.

04:10.360 --> 04:19.300
And then for each core we're going to have an SMM base and at a specific offset 8000 from the SMM base we're going to have the entry point.

04:19.300 --> 04:25.220
Which is where the processor, the core is going to start executing from when the SMI happens.

04:25.620 --> 04:28.220
And then we have a safe state at offset FE00.

04:28.220 --> 04:29.780
This is TianoCore right?

04:30.260 --> 04:33.060
It can be laid out differently by the vendor.

04:33.280 --> 04:40.800
And then we have the SMI handlers at the very top which are going to be the functions that are are going to be useful for for us for the system.

04:40.800 --> 04:42.780
Handling power, security or whatever.

04:44.120 --> 04:47.040
Um so yeah just a summary of the SM RAM registers.

04:47.040 --> 04:50.360
We have the three that we just mentioned and we also have an SMM block.

04:50.360 --> 04:51.400
That's very important.

04:51.400 --> 05:00.540
Hopefully the firmware code is going to set this bit so that the whatever runs at run time the OS cannot tamper with these registers.

05:00.540 --> 05:13.960
We don't want for example at run time having the OS disabling the TSEC location because this will just um update or change the code at the SM RAM location and execute with these additional privileges right?

05:14.160 --> 05:16.980
Now this needs to be configured for each core.

05:17.540 --> 05:25.620
With that we can see a first difference between how Intel and AMD manage the access to MSRs.

05:25.780 --> 05:33.420
On Intel systems these MSRs that are related to SMM are only accessible while the CPU is in SMM.

05:33.800 --> 05:39.420
In fact obtaining the SMM base for example on Intel could be considered a leak.

05:39.780 --> 05:45.240
On AMD all these MSRs are accessible from ring zero, no problem.

05:45.280 --> 05:50.700
Again if we have the SMM block bit set then the configuration cannot be changed.

05:50.800 --> 05:58.180
Not even SMM can change the configuration until the next power cycle in which I mean the firmware will take over again and configure this in the same way.

05:59.000 --> 06:02.400
But we can now spot the bug in the documentation.

06:02.620 --> 06:10.080
This is the same TSEC mask register and the fields just a picture from the documentation.

06:10.180 --> 06:15.640
We can see how the SMM block is covering all of the fields except for two over there.

06:16.080 --> 06:20.960
These two fields are going to be what we're going to be talking about in this session.

06:20.960 --> 06:23.560
And we have T-CLOSE and A-CLOSE.

06:23.900 --> 06:25.700
We're just going to focus on T-CLOSE.

06:25.700 --> 06:32.860
A-CLOSE stands for the same feature but for a previous region called ASEC which overlaps on the video memory.

06:32.860 --> 06:34.800
It's not used anymore so it doesn't matter.

06:34.840 --> 06:47.540
But what happens is when this bit is set, the data accesses that the core that the core performs when it's running in SMM are going to be directed to MMIO instead of to SMRAM.

06:47.600 --> 06:57.460
And that's cool because as we said before, we can set this bit from ring zero because it's not blocked by the SMM block, right?

06:57.660 --> 07:10.360
It actually in the A-CLOSE description it also says hey, don't forget to unset this when you're returning from SMM because otherwise your safety are going to be erroneously read from MMIO.

07:10.360 --> 07:11.420
That's bad.

07:13.280 --> 07:25.840
The documentation says as well hey, if you have a valid T-CLOSE region and you're in SMM and the T-CLOSE is set, then instruction fetches are still going to be directed to DRAM but data accesses are going to go to MMIO instead.

07:26.000 --> 07:31.260
If you're not in SMM then both accesses, both type of accesses are going to go to MMIO.

07:31.780 --> 07:37.720
So we can say X86 behaves in a Harvard, like a Harvard architecture.

07:37.720 --> 07:38.880
It goes to Harvard, right?

07:38.880 --> 07:45.860
If we have our core zero for example running in normal mode, both data and instruction fetches just go to MMIO.

07:46.220 --> 07:50.860
If we have our core zero now in SMM with the T-CLOSE off, this is what happens.

07:50.860 --> 07:51.520
No problem.

07:51.520 --> 07:54.260
We read and execute from SM RAM.

07:54.260 --> 07:58.120
However when we set T-CLOSE on, now data fetches go like this.

07:58.120 --> 08:04.480
And this is a problem because this portion can be controlled by an attacker.

08:05.360 --> 08:07.280
So triggering the condition is super easy.

08:07.280 --> 08:18.160
We just need to set this bit, this T-CLOSE bit, and call into an SMI and the system will immediately freeze, hang, or you're going to spot the problem right there.

08:18.900 --> 08:34.900
This feature exists because, well AMD wanted to have the ability to reuse the physical address space and have SMM code access an IO device that were using the same SM RAM physical memory essentially.

08:35.460 --> 08:38.240
Um, we haven't seen any vendor using this feature.

08:38.380 --> 08:40.460
Um, but yeah, that's why.

08:40.460 --> 08:47.280
And it was, on what we could track is in 2006 there was this document that first mentioned the feature.

08:47.360 --> 08:50.520
So it means it's been around at least for 18 years.

08:51.840 --> 09:04.360
Now, for people familiarized with um, biosecurity they're probably going to remember this vulnerability presented by Christopher Domas in 2015 called the memory sinkhole attack.

09:04.360 --> 09:16.040
And what happened was that he was able to remap the APIC which is a specific device um, available and overlap it with the T-SEC area and it caused the same effect.

09:16.060 --> 09:18.920
Uh, data fetches will go to MMIO instead of SM RAM.

09:19.140 --> 09:28.160
Now the difference here of course is that that was only limited to the APIC and it only affected the 4K region where the APIC was overlapped with.

09:28.440 --> 09:33.180
The SYNCLOSE behavior changed uh, how the entire T-SEC works.

09:33.280 --> 09:36.480
Um, any device in theory could be overlapped, right?

09:36.480 --> 09:41.060
Because we just direct any access to the MMIO space.

09:42.340 --> 09:46.160
So, we can bring some attack ideas in.

09:46.320 --> 09:59.260
Our easy thing will be, the easiest thing will be to just grab any PCI device and hopefully we'll have a good register layout on its bar so that we can take control of the execution at the very beginning of the entry point.

09:59.420 --> 10:10.380
As there are multiple integrated devices that we could use, we could just try remapping one of those and based on what we read, the register should become visible at the T-SEC location from the OS.

10:11.840 --> 10:13.360
However this failed.

10:13.360 --> 10:23.440
We can see here how uh, we have an ethernet controller uh, with its original uh, bar 2 uh, D0714000.

10:23.440 --> 10:26.460
We have some registers right here, they're visible registers.

10:26.460 --> 10:34.360
And we're going to try to overlap, when we try to overlap it with the SMM entry uh, BFED0000, we can see that we're still reading F's.

10:34.360 --> 10:36.500
So, the remapping failed.

10:36.800 --> 10:38.420
Registers are not available.

10:38.860 --> 10:44.060
Um, we can see that the registers were moved from their original location.

10:44.060 --> 10:46.700
Uh, something happened.

10:47.600 --> 10:58.140
When we restore, we can see the the the priority of the memory probably failed, right?

10:58.260 --> 11:03.360
So what that that led us to try to understand okay, how that does, how how is that working?

11:03.360 --> 11:06.280
I have this register called top of memory or TOM.

11:06.840 --> 11:17.440
Um, this thing defines a limit between the usable DRAM before 4 gigabytes on the physical address space and MMIO space on top.

11:17.720 --> 11:21.660
Now, on Intel, this register has a lock bit.

11:21.660 --> 11:24.980
Once it's configured, you cannot tamper with it anymore at run time.

11:24.980 --> 11:31.260
But on AMD, it doesn't have such a lock so we can just, you know, modify this and maybe that's good for us.

11:31.320 --> 11:34.940
The idea is simple, we have this is uh, imagine this is the layout, right?

11:34.940 --> 11:41.200
And we'll move the MMIO space of the TOM that defines the MMIO space to match with the TSEC base.

11:41.260 --> 11:42.880
So we have something like that.

11:43.240 --> 11:48.580
Maybe then, trying the same trick that we uh, did before could work.

11:48.580 --> 11:54.820
Unfortunately, we could move the TSEC, no problem, but it didn't change the behavior that we saw before.

11:54.820 --> 11:56.440
In practice, it didn't work.

11:56.880 --> 12:08.580
So that led us to dig, dig, dig uh, deeper into uh, into augmentation and we found there are some actual priorities when the core access um, some portion of the physical address space.

12:08.580 --> 12:10.840
Essentially determines what, where it's going.

12:10.840 --> 12:19.440
And we can see that the TSEC and ASIC mechanisms are listed 4, which means 1, 2 and 3, whatever is listed there has less, less priority than this.

12:19.440 --> 12:23.320
And at the, at number 1, we can see the TOM is, is listed there.

12:23.320 --> 12:25.320
So we have, that's why it never worked, right?

12:25.320 --> 12:26.520
It would have never worked.

12:27.920 --> 12:32.760
What's at 5, where we have the MMIO configuration space and the APIC?

12:33.780 --> 12:36.360
Uh, that makes sense.

12:36.660 --> 12:40.240
We, the APIC was used before in the Intel attack.

12:40.360 --> 12:42.840
The MMIO config space we cannot use really.

12:43.000 --> 12:50.900
Um, and then at 6 we have this Norbridge address space uh, routing but uh, that probably stands for older architectures.

12:50.900 --> 12:53.100
This is not seen in modern, modern stuff.

12:53.100 --> 12:54.980
So we cannot use it.

12:55.320 --> 13:00.080
For the APIC, we cannot really use it and we're going to explain why.

13:00.080 --> 13:06.940
But for that, I'm going to give an analysis of, of um, how the SMM entry point code works.

13:07.020 --> 13:15.300
When the SMM, when the SMI occurs, the SMM core uh, that, that the core um, executing at SMM starts executing in real mode.

13:15.300 --> 13:16.720
In 16 bit mode, flat.

13:16.720 --> 13:18.160
No protection whatsoever.

13:18.660 --> 13:25.240
What it has to do is quickly go to protected mode 32 bit and then goes to long mode and then passes the execution to the handlers.

13:25.240 --> 13:26.780
This is a very simplified view.

13:27.020 --> 13:31.920
Now, that first step going to, from real mode to protected mode is, is key, right?

13:31.920 --> 13:33.640
That's the first thing that needs to happen.

13:34.100 --> 13:40.040
For this, um, on x86, we need, essentially are enabled segmentation.

13:40.580 --> 13:47.620
Uh, segmentation provides um, the ability for the, for the core to see the memory in a segmented way.

13:47.620 --> 13:48.980
That's, that's how it's called.

13:48.980 --> 13:58.280
Essentially, we can have different segments for memory and assigns uh, different permissions or like um, the ability to execute code or, or just read data and stuff like that.

13:58.300 --> 14:02.500
We have this key data structure called global descriptor table of GD or GDT.

14:03.180 --> 14:12.840
And we have a register on the processor that is called GDTR that's going to point to the base of our GDT structure and it's going to have a limit in bytes.

14:13.080 --> 14:15.760
And so the GDT is just really an array of descriptors.

14:15.760 --> 14:17.160
And we can have different types of descriptors.

14:17.160 --> 14:19.640
We can have, we can have code descriptors, data descriptors.

14:19.640 --> 14:21.180
Each one is going to have a base.

14:21.360 --> 14:22.700
The first one is never used.

14:22.700 --> 14:24.500
That's why it's called, it's called null descriptor.

14:24.500 --> 14:28.660
But then, when we have a jump, you can see we'll have um, a jump.

14:28.660 --> 14:34.400
It's not only having an offset like a target location but it's also going to have like a segment selector right here.

14:34.440 --> 14:38.700
That segment selector picks the descriptor we're going to use for the, for, for our, our code segment.

14:38.700 --> 14:44.660
And then the top, the, the offset is added to the base that is indicated by the GDT.

14:44.940 --> 14:46.860
Forming the final linear address.

14:47.300 --> 14:53.340
With that we can do uh , an analysis of um, the EDK2 SMM entry point.

14:53.340 --> 15:03.440
Essentially um, we can see that at the very beginning we are moving into the register BX, the entry point plus 4D.

15:03.480 --> 15:09.760
This is, this is a decom , like um, extracted from a, from, from a compiled um, SMM code.

15:09.760 --> 15:15.060
So you can see at 4D right there we have a GDT description ready to, to, to be loaded into the GDTR.

15:15.060 --> 15:17.980
The next instruction that matters for us is the load GDT.

15:17.980 --> 15:22.560
This is the instruction that is going to load the GDTR with the content that BX points to.

15:22.940 --> 15:30.040
And finally, we have a jump over here that's gonna perform the actual um, going into protected mode.

15:30.400 --> 15:34.280
And it has the selector of code as well and the offset.

15:34.500 --> 15:42.060
Now, with this, what, what will happen if we over, overlap a device that we control on the entry point?

15:42.060 --> 15:44.420
And we control offset 4D.

15:44.500 --> 15:48.440
What will happen is that the load GDT will be loading something that we control.

15:48.440 --> 15:50.760
So we can load our fake GDT right ?

15:50.900 --> 15:52.380
So that's what we're trying to do here.

15:52.380 --> 16:04.680
We're trying to get control over the offset 4D with any device that we can find so that the, the fake GDT then provides the descriptors we need and we can take control and jump down there.

16:04.680 --> 16:06.460
That's the whole idea of the attack.

16:07.640 --> 16:10.660
And that's why the APIC is a problem.

16:10.900 --> 16:11.600
Two things.

16:11.600 --> 16:14.420
First, the system becomes unstable when the APIC is moved.

16:14.420 --> 16:15.400
Super unstable.

16:15.440 --> 16:20.100
Second, the APIC racers are not useful for taking control in the way we need.

16:20.140 --> 16:24.480
We can see that at 4D we have this reserved regions with all zeros.

16:24.480 --> 16:25.800
Rights are discarded here.

16:25.800 --> 16:34.340
We're not able to control here and if we load a GDTR with all zeros we're essentially saying to the processor, hey, here's an empty GDT.

16:34.520 --> 16:36.340
So this won't work.

16:36.400 --> 16:44.240
And at this point we found another device not documented by the, the specification that also has priority over uh, the TSEC region.

16:44.240 --> 16:47.520
That's the spike controller and Christophe's going to describe it for us.

16:50.240 --> 16:51.280
Alright.

16:51.640 --> 17:00.460
So the spike controller is a very nice device for us because it's present in all the systems we've tested and it's basically used to access the spike flash on um, AMD uh, systems.

17:00.760 --> 17:05.520
So for example for reading, writing, erasing the spike flash, it always goes for the spike controller.

17:05.660 --> 17:09.380
And it has a couple of key features that are really uh, interesting to us.

17:09.440 --> 17:13.120
First of all, we can relocate the bar over the SMM entry point.

17:13.220 --> 17:17.460
Secondly, the portions which are interesting to us at offset 4D, we can control them.

17:17.600 --> 17:22.540
And three, it actually takes precedence over uh, SMRAM when TCLOS is enabled.

17:22.920 --> 17:34.440
So with that in mind, what we will do for our attack is simply take the spike bar, relocate it over the SMM entry point of core zero, and then afterwards manipulate the values at offset 4D within that bar.

17:34.720 --> 17:44.280
Um, the um, registers that actually correspond to that portion of memory in the bar uh, are the memory range and ROM protection zero register.

17:44.340 --> 17:53.100
Those were used in the past to uh, lock down access to the spike flash, but mostly these are not configured, they're not fixed, so we can fully control them.

17:53.100 --> 17:58.700
On some systems they are fixed, but actually they are fixed to values which are still useful for us.

17:59.660 --> 18:07.460
So, before I dive into the exploits, uh, I also want to uh, show you a little bit our debugging stuff because it's a little bit special.

18:07.680 --> 18:14.180
Um, so we were facing actually two challenges uh, when we tried to develop the exploit.

18:14.240 --> 18:22.920
First of all, we didn't really have a way to know whether our payload ran because the system just crashes, reboots, and memory is just all wiped.

18:23.280 --> 18:27.120
Uh, and secondly, we didn't really have any debugging framework for SMM.

18:27.400 --> 18:33.560
Um, and like for example when crashes happen, we want to be able to modify the code however we see fit.

18:33.680 --> 18:51.860
So to resolve the first issue, we actually took a PCI squirrel, which is typically used with PCI leach for DMA attacks, but the nice thing about it is, actually is that it has a bar buffer, as we call it, where when we write to it, it actually survives across reboots.

18:51.860 --> 19:00.180
So for instance, a payload can write a value to uh, the bar buffer, kind of like a checkpoint so we know it ran, and then when the system reboots, it's still going to be there.

19:00.180 --> 19:00.760
Right .

19:00.840 --> 19:14.920
And if we want to modify, for example, for the second issue, if we want to modify uh, code in SMM for some extra debugging capabilities, for that we just um, injected a firmware implant, uh, that loads a nice SMM module that allows us to do all of that.

19:15.800 --> 19:25.480
So the setup looks like this, we just have the PCI squirrel connected to our target device via an M2 uh, adapter, and all of this is powered externally by a power supply.

19:26.020 --> 19:30.960
So, it's time to get our hands dirty, so let's take a look at how uh, the exploit looks like.

19:31.160 --> 19:40.080
In the first attempt, uh, we remap the spy bar, just like mentioned before, over the SMM entry point of core zero, then we tweak uh, these values at offset 4D.

19:40.640 --> 19:49.960
We create a fake GDT in the beginning of the address space, uh, with the, with a nice base address that will allow us when the jump happens to redirect the execution to our own payload.

19:50.740 --> 20:04.440
And then when we uh, execute the SMM entry point code with TCLOS enabled, what's going to happen is uh, the old GDT is actually going to load the GDT register uh, with a value that points to our own fake GDT, so that's great.

20:04.620 --> 20:14.880
And afterwards, when the jump happens, a descriptor from the fake GDT is going to be taken that we control, um, and it's going to be used as a base uh, for the jump.

20:15.980 --> 20:20.500
So, and um, this is going to redirect the execution like this, at least in theory.

20:20.780 --> 20:34.580
So, um, an interesting detail is actually how we pick the base address in the GDT descriptor, um, and for that we have to understand how it normally executes and how it executes with TCLOS in this case.

20:34.580 --> 20:52.700
So, um, when the for jump happens, um, and the normal execution, what happens is the GDT register is going to point to a GDT within SMRAM where it's nicely protected, um, and the segment selector is going to index into that table, um, and the base is going to be actually fixed to zero.

20:52.700 --> 21:00.720
Which means with the base of zero when we add it uh, to the for jump offset, what's going to happen is the linear address is going to be the same.

21:00.800 --> 21:04.300
Now in our case, actually we have a bit of an issue.

21:04.300 --> 21:09.220
We want to read the execution, um, outside of TSEG.

21:09.260 --> 21:16.780
The only problem is that within the first four gigs of memory, after TSEG, there's not really any spot where we can put a payload, right?

21:16.800 --> 21:26.100
So, if we increase the base a little bit, sure the instruction pointer is going to go a bit more up, up, up, up, and the address space, we don't really have DRAM over there that we control.

21:26.200 --> 21:39.940
So we wondered, okay, what happens if we actually increase the base such that when we, uh, the base of the GDT descriptor, such that when we add it to the for jump offset, it actually overflows.

21:40.800 --> 21:44.280
Um, yeah, it just overflows.

21:44.280 --> 21:47.620
So we thought, okay, this isn't going to be possible, but actually it was.

21:47.740 --> 21:57.340
Uh, this is nice because, uh, if we choose the base sufficiently big and we add the offset, we can actually make it wrap around and make it jump to our own payload in the beginning of the physical address space.

21:57.340 --> 22:01.760
The beginning of the physical address space, we have DRAM there, great, we control all of that.

22:02.120 --> 22:07.540
So, uh, that was one of the key takeaways actually that we had from the research as well.

22:08.460 --> 22:19.040
So this worked, our payload actually ran, and we saw this because it would write a value , this nice checkpoint to our bar buffer, but the system would crash and we wondered, okay , why is this happening?

22:19.360 --> 22:21.440
Um, the reason was the SMM safe state.

22:21.440 --> 22:28.240
So like Enrique mentioned, when a CPU goes to SMM mode, it actually saves the current register state into the, uh, SMM safe state.

22:28.240 --> 22:29.960
When it returns, it just restores it.

22:29.960 --> 22:45.580
What happens is when TCLOS is enabled, actually the writes, when the core enters SMM, are going to be discarded, which means when we return with TCLOS disabled, actually it's just going to use stale values that were still there, that were stored before.

22:45.820 --> 22:49.100
And to resolve this, the trick is actually pretty straightforward.

22:49.100 --> 22:50.820
We trigger the SMM twice.

22:50.820 --> 22:55.100
One time, um, without TCLOS and the second time with TCLOS.

22:55.100 --> 23:02.480
So we first put the core zero into a known controlled state, and then trigger an SMI without TCLOS.

23:02.480 --> 23:14.200
This is going to prime the SMM safe state, and afterwards when we trigger the bug, with TCLOS enabled, the code is going to go for the same execution path, and it's just going to reuse the values that we stored before.

23:14.720 --> 23:19.320
So that worked, but unfortunately it crashed again.

23:19.320 --> 23:24.980
But this time around we did see actually that the, uh, the core zero was returning from SMM, so that was great.

23:24.980 --> 23:29.580
We had full control of core zero, OS code was running, we saw our checkpoints, great.

23:29.720 --> 23:33.620
But no matter what we tried, this damn thing was still crashing.

23:33.620 --> 23:38.020
Um, so we spent an eternity debugging this thing until we stumbled into this.

23:38.180 --> 23:46.140
When we enable TCLOS, what happens is, we enable it on core zero only, but actually it gets enabled on both cores.

23:46.140 --> 23:48.040
Core zero and core one.

23:48.760 --> 23:54.840
Um, and we found that the culprit for this is symmetric multi-threading, so this is AMD's implementation of Intel hyper-threading.

23:55.020 --> 23:59.060
Um, and what it does is it divides a physical core into two logical cores.

23:59.060 --> 24:03.300
And some of the resources on these logical cores are shared and some of them are not.

24:03.300 --> 24:08.700
So for instance the SMM base MSR is separate, so every logical core has a different base MSR.

24:09.120 --> 24:14.380
But the TSEC mask is actually shared, which is what we just saw, right?

24:14.780 --> 24:17.780
And we wondered, is this the actual issue?

24:17.780 --> 24:23.100
Because we assume when an SMI gets triggered, that only one core goes into SMM at the time.

24:24.040 --> 24:26.940
And we put this to the test and what we saw is the following.

24:26.940 --> 24:42.860
When we have multiple cores running in normal mode, so outside of SMM, um, when we, when one of them triggers an SMI, an interrupt gets asserted on all of the cores and all of the cores are going to go into SMM mode and going to start executing the SMM entry point codes,

24:42.860 --> 24:45.680
um, for each and one of them.

24:45.680 --> 24:49.140
So, our assumptions were actually wrong, right?

24:49.140 --> 24:51.880
We assumed the SMIs are local, but they're actually not.

24:51.960 --> 25:13.820
And we thought that this was actually the case because the IDK2 code has a so-called rendezvous routine, which will, every time you enter into SMM, this routine is going to be triggered and that core which entered into SMM will send an explicit interprocessor interrupt to all of the logical cores to explicitly pull them from whatever state they were in into SMM.

25:13.820 --> 25:17.820
And, well, what's the point of that if actually all the cores always go into SMM anyway, right?

25:18.280 --> 25:26.840
Um, and we dug a little bit deeper into the documentation and we found that the IO hub seems to be responsible for this to, uh, basically assert this interrupt on all of the cores.

25:26.880 --> 25:28.780
So, we're out of luck.

25:29.740 --> 25:39.800
So, to summarize, we had all cores always going into SMM and T-Cores being enabled on two cores at the same time and not just one as we initially thought.

25:40.180 --> 25:44.280
And this will actually make just core 1 go haywire, right?

25:44.280 --> 25:48.880
We have control of core 0 but core 1 is, uh, just going to go nuts and crash the whole system.

25:49.580 --> 25:54.040
So, to tackle the problem, we had to get control of core 1 some way.

25:54.360 --> 26:03.980
Uh, and we dug deep into our bag of tricks to really, uh, see if maybe there's a nice elegant solution to this to just take core 1 out of the running.

26:04.400 --> 26:11.980
Um, so we tried to, um, we tried to find another device to overlap with the entry point of core 1.

26:12.160 --> 26:13.220
There was none.

26:13.380 --> 26:15.180
Uh, we tried to disable SMT in the BIOS.

26:15.180 --> 26:16.440
That also didn't work.

26:16.440 --> 26:26.380
We tried to, uh, use the, uh, so-called init IPI and also the SKL instruction to put core 1 into a state that would actually make it ignore SMIs.

26:26.540 --> 26:27.860
That also didn't work.

26:28.020 --> 26:36.740
And finally, we also tried to send a so-called SMI IPI which, at least according to the documentation, would allow us to trigger an SMI on individual cores.

26:36.860 --> 26:38.100
And it also didn't work.

26:38.100 --> 26:43.660
So, despite the documentation indicating one thing, in practice, we didn't manage to, uh, get it to work.

26:44.320 --> 26:48.080
So, we're running out of options and we had to take a step back and analyze the problem.

26:48.300 --> 26:56.280
And we realized, okay, the LGDT has the actual problem because it's going to be load- loading the GDT register with all Fs, right?

26:56.460 --> 27:01.140
So, is this, is there maybe some way we can actually still take advantage of this?

27:01.620 --> 27:09.980
Um, so, when the supplementary point normally executes what happens with the GDT register is, it's going to be loaded with a nice value for the base.

27:09.980 --> 27:14.580
It's going to be pointing to the GDT within, uh, SMRAM, right?

27:14.580 --> 27:25.120
And afterwards, the segment selector is going to be taken, added to it, uh, and the base within that, uh, descriptor is going to be used to calculate the final linear address.

27:25.980 --> 27:34.820
Now, in our case, what's going to happen when TICOS is enabled, uh, the GDT register is going to be loaded with all Fs, both the limits and the base.

27:35.480 --> 27:41.680
And what's going to happen then is, when the for jump, the segment selector is going to be added to it.

27:41.760 --> 27:45.160
And once again, we have our good old friend's integer overflow.

27:45.480 --> 27:49.020
It's actually going to result in the physical address 7.

27:49.240 --> 27:53.780
And this is actually awesome because address 7 in the physical address space, once again, that's DRAM.

27:53.780 --> 27:54.920
We control DRAM.

27:54.920 --> 27:56.400
So, we can take advantage of that.

27:56.400 --> 28:01.940
We can put our GDT at the beginning of DRAM and we can just overflow this thing like this.

28:02.200 --> 28:09.980
And afterwards, uh, from the GDT we control, we set a nice base so that afterwards, uh, the code jumps wherever we want it to.

28:10.500 --> 28:13.420
So, to summarize, we have two types of wraparounds.

28:13.420 --> 28:16.320
One is between the GDT descriptor base and the for jump offset.

28:16.340 --> 28:21.900
And the second one between the GDT register base and the for jump segment selector.

28:22.060 --> 28:29.440
And the nice thing about this is, we can actually reuse the same fake GDT for both core zero and core one.

28:29.800 --> 28:33.340
And the added bonus is, we don't even need the spy bar anymore.

28:35.040 --> 28:38.180
The only thing that we really have to take care of is the SMM safe state.

28:38.180 --> 28:39.820
Once again, for core one.

28:39.880 --> 28:42.780
For core zero, we just do the same thing as before.

28:42.960 --> 28:46.220
But core one is going to be running in some unknown state.

28:46.220 --> 28:49.480
It could be running in ring three, ring zero, just in an unknown context.

28:49.480 --> 28:52.440
We have to bring it to the same controlled state as core zero.

28:52.620 --> 28:55.440
And we do so by using a kernel synchronization API.

28:55.780 --> 28:58.340
Which on Windows is the deferred procedure call.

28:58.360 --> 29:00.700
Or on Linux, symmetric multiprocessing.

29:01.660 --> 29:06.540
And basically once that's done, we have both cores in a known state.

29:06.540 --> 29:09.820
And we can use the same trick we did for core zero.

29:10.280 --> 29:12.020
So, all good things are three.

29:12.020 --> 29:13.520
So, let's try again.

29:13.700 --> 29:16.200
The exploit this time is greatly simplified.

29:16.540 --> 29:21.620
And the only thing we have to do is, we create the fake GDT in the beginning of the address space.

29:21.640 --> 29:25.280
We choose the base address within the descriptor accordingly.

29:26.060 --> 29:27.240
And that's it.

29:27.520 --> 29:38.520
And then when we trigger, when we enable T-Close and run the uh, SMM entry point code again, the old GDT this time around is going to point to the very end of the address space of the first four gigs.

29:38.620 --> 29:41.620
But then when the far jump happens, it's going to wrap around.

29:41.620 --> 29:47.280
It's going to fetch the GDT descriptor entry from the beginning of the address space from our fake GDT.

29:48.160 --> 29:53.660
And then afterwards it's going to redirect execution for both core zero and core one to our own payload.

29:54.840 --> 29:56.120
And it finally worked.

29:56.120 --> 29:59.120
We managed to control both cores, core zero and core one.

29:59.140 --> 30:07.460
Uh, our payload would execute with SMM privileges and uh, it would return gracefully from SMM to the operating system and nothing would crash.

30:07.460 --> 30:08.500
And that was great.

30:08.500 --> 30:12.040
There were only a couple of things that we wanted to improve uh, in our exploit.

30:12.040 --> 30:19.560
And that was um, to reload the GDT because the base actually is um, a bit off.

30:19.700 --> 30:26.000
So we just reloaded the GDT so that the base address is equal zero again so that we don't have strange misalignment issues.

30:26.060 --> 30:29.720
We set up long modes, so page tables, stack pointer, etc.

30:29.720 --> 30:32.660
so we can execute like uh, any SQL that we want.

30:32.740 --> 30:41.840
Uh, and then we also install an SMI hander so that we only have to exploit the bug once and then basically we have kind of semi persistence until the system resets.

30:41.840 --> 30:42.520
Right?

30:43.500 --> 30:47.780
So, for the demo, just to show you I'm not selling just some snake oil.

30:47.920 --> 30:56.600
Uh, we have a system over here which is a Huawei Matebook D16 from uh, 2023.

30:57.420 --> 31:00.960
And you can see when the system boots, it actually shows the Huawei logo.

31:00.960 --> 31:03.600
That logo is embedded in the firmware code.

31:03.800 --> 31:09.000
For that, um, so for our exploit we're actually going to modify that uh, that logo.

31:09.080 --> 31:14.160
So, um, we're going to run our exploit with uh, kernel privileges.

31:14.340 --> 31:19.680
So you'll see over here that we have to elevate privileges and it's going to be triggered via a malicious driver.

31:20.060 --> 31:23.880
And then our exploit is going to do uh, three things.

31:23.880 --> 31:28.120
At first it's going to use the synclose issue to elevate privileges to SMM.

31:28.420 --> 31:31.480
Then it's going to disable the spy flash protections.

31:31.560 --> 31:39.480
And then afterwards it's going to write to the spy flash the portion where the um, boot splash logo is actually residing.

31:39.480 --> 31:43.700
This takes a little while, about 15 minutes, so we just fast forward that portion.

31:43.760 --> 31:47.200
And you can see okay, it shows done patching, all good.

31:47.860 --> 31:51.540
And at this point we just reset the system and pray that it works.

31:52.900 --> 31:54.340
So let's see.

32:01.460 --> 32:03.320
Yeah, this one takes a little while.

32:06.420 --> 32:08.960
And... there we go.

32:09.140 --> 32:10.240
We're successful.

32:18.440 --> 32:19.900
So, I'm actually going to show you how to do this .

32:19.900 --> 32:23.160
So I mean this was just one example of what we can do with this kind of access into the system.

32:23.160 --> 32:28.680
But let's take a more systematic approach to see whether this works on all systems, just on some.

32:28.680 --> 32:30.140
What does this actually depend on?

32:30.200 --> 32:34.640
So the next attack paths depend on how the platform is actually configured.

32:35.440 --> 32:40.720
Um, so every vendor configures certain features that AMD provides to them.

32:40.840 --> 32:44.160
And specifically there are two of them which are key to this.

32:44.240 --> 32:48.800
One is room armor, which can be used to restrict access to the portions of the spy flash.

32:49.600 --> 32:57.400
And the second one is platform secure boot, which is AMD's equivalent of boot guard, which will verify the initial stages of the firmware code.

32:58.160 --> 33:06.000
Um, so if everything is enabled, the very least thing that we can do is we can write to a portion of the spy flash where you have your variables live.

33:06.000 --> 33:11.600
So for instance, in these variables you're going to have things like the secure boot keys which are used.

33:11.600 --> 33:13.160
So we can break secure boot.

33:13.240 --> 33:14.220
That's nice.

33:14.420 --> 33:17.720
Um, but if nothing is enabled, actually we have firmware implants.

33:17.720 --> 33:20.780
I'm going to explain in a moment what the difference actually is.

33:20.780 --> 33:27.800
So in the first configuration where everything is properly configured, we see, okay, we escalate from the operating system to SMM.

33:27.840 --> 33:34.260
And from there we can write the, let's say, firmware data portion of the spy flash where the configurations are.

33:34.260 --> 33:42.020
So we can manipulate the secure boot keys so that afterwards we can actually load our own malicious boot loader before the OS loader runs.

33:42.840 --> 33:47.160
On the second configuration where the PSB is not enabled, we have basically the same scenario.

33:47.780 --> 33:54.200
Um, Roam Armor will still restrict write access to, um, to the data portion.

33:54.660 --> 33:59.600
And we can, we can still just, um, uh, inject our own boot kits.

33:59.840 --> 34:06.220
And the third configuration we can write to even firmware code, but that's going to be still verified by platform secure boot.

34:06.860 --> 34:10.240
So, okay, and these three, we have the same scenario.

34:10.240 --> 34:13.900
We can just inject a boot kit, which is still nice because it runs before the OS loader.

34:13.900 --> 34:18.520
Any protections provided by the operating system would still be, um, rendered null.

34:19.880 --> 34:29.100
But, in the last scenario where none of these features are enabled, what we can do is we can inject our, uh, malware into the spy flash, into the firmware code portion of it.

34:29.100 --> 34:38.460
And when that happens, uh, is what we're going to get is we can, um, run our own malware at the very earliest stage of the boot process.

34:38.800 --> 34:49.080
And there's a key difference here between a firmware implant and, uh, a boot kit, is that this attack actually is resistant to, uh, to OS reinstallations.

34:49.080 --> 34:51.620
So even if you wipe your drive, it's still going to be around.

34:51.980 --> 35:00.660
Um, and even if you try to push a firmware update from the operating system, it's still going to be around because the, uh, the malware can just say, well, the update was successful.

35:01.400 --> 35:16.060
Um, and the only way to really get rid of it at that point is to take apart your system, take a spy programmer to read out the spy flash, inspect it, and if it's infected, um, just, uh, rewrite it.

35:16.260 --> 35:20.220
But typically it's not really in the repertoire of a typical IT guy, right?

35:21.460 --> 35:31.540
So to illustrate how prevalent actually these misconfigurations are, we did some research last year on that and we saw that the majority of the systems have none of the security features actually enabled.

35:31.540 --> 35:37.040
Which means all the systems which have none of the features enabled are vulnerable to firmware implants.

35:37.040 --> 35:38.620
Which is pretty bad.

35:39.440 --> 35:53.940
And to put a cherry on top, we also found that once you're infected with that kind of, uh, firmware implant, you can even disable platform secure boot forever by burning a specific fuse so that your system remains vulnerable to firmware, uh, implant reinfections forever.

35:54.480 --> 35:55.320
Sweet.

35:55.920 --> 35:58.880
So, let's wrap up the presentation.

36:01.940 --> 36:03.580
Thanks Christophe.

36:04.560 --> 36:08.320
So, yeah, in terms of affected systems, um, I think we covered most of them, right?

36:08.680 --> 36:10.640
Pretty much all of them.

36:10.880 --> 36:11.780
Uh, yeah.

36:11.780 --> 36:15.620
Um, our tests were on Ryzen, mostly.

36:15.760 --> 36:17.200
Several laptops.

36:17.340 --> 36:20.960
Uh, but turns out the Threat Reaper series is also affected.

36:20.960 --> 36:23.400
Epic series is also affected.

36:23.580 --> 36:25.080
Meaning servers.

36:25.500 --> 36:39.100
Um, and yeah, uh, due to the longevity of this, this, this thing, we can estimate the total number of affected chips are in around the hundreds of millions.

36:39.960 --> 36:52.720
Um, there's an advisory from AMD published now, um, where more information on the system, the affected systems and cover, uh, there's a microcode update now.

36:53.120 --> 36:55.760
Information is there, so you can check.

36:56.580 --> 36:57.700
Mitigations.

36:58.480 --> 37:03.640
Yeah, AMD, as I just said, provided, um, with microcode updates.

37:03.880 --> 37:07.140
However, it might not cover all of the affected systems.

37:07.140 --> 37:17.380
Of course, um, in terms of what an OEM can do, they can just modify the SMM entry point code to detect if the T-Close bit is set.

37:17.720 --> 37:24.460
And if it is, then just abort the execution and this, this will just render the exploitation unfeasible.

37:24.940 --> 37:29.680
Uh, this can even be done at the EDK 2 level for AMD systems, right?

37:29.680 --> 37:37.380
And we really haven't covered here core boot, but core boot is affected in the same way.

37:37.380 --> 37:42.480
We just, I mean, um, core boot at the very beginning of the entry point performs a low GDT.

37:42.480 --> 37:46.840
They have to go to protected mode as well, so it's, it's the same thing.

37:47.420 --> 37:55.160
Um, and actually core boot, they are checking for this, uh, for other issues as well at the entry point, so they could, they could very well do this.

37:56.200 --> 38:07.180
Um, and users, well, they can, you know, a hypervisor could trap the access on the TSEC mask MSR, so that's another, uh, way to stop this.

38:07.840 --> 38:12.880
Timeline wise, well, we reported this back in October of 2023.

38:13.020 --> 38:17.580
A CVE of 2023, uh, 31315 was assigned in November.

38:17.780 --> 38:22.200
And then we discussed mitigations and impact with AMD over the course of the next months.

38:22.240 --> 38:28.220
Um, and yeah, finally yesterday, um, the advisory was published and we are here at DEF CON today.

38:29.320 --> 38:31.780
This was the official AMD response.

38:31.780 --> 38:39.160
Essentially, we work with them in a process of, uh, responsible disclosure.

38:39.500 --> 38:41.740
And yeah, they've been great to work with.

38:43.280 --> 38:44.880
Conclusions and takeaways.

38:45.040 --> 38:48.060
Well, the vulnerability has been around for nearly two decades.

38:48.160 --> 38:58.620
Um, the complexity of the architecture clearly plays in favor of attackers and we see this, uh, with the flexibility of, of, of the GDT.

38:58.620 --> 39:07.800
Um, the two types of wraparounds, the, the, the byte level, uh, um, address, um, like granularity that there is with it, no problem.

39:08.380 --> 39:14.180
Um, and also with the, how the MSRs can be accessed without any restriction.

39:14.660 --> 39:17.440
Uh, that, that's, that's all good for attackers, right?

39:17.440 --> 39:24.960
Um, these things combined are what made this exploit approach possible.

39:25.440 --> 39:27.880
It might be on other exploit methods too.

39:28.280 --> 39:33.900
Um, but yeah, all of this of, of course requires an in depth understanding of the architecture.

39:34.200 --> 39:38.680
And in the end we managed to exploit this without requiring physical presence.

39:38.680 --> 39:39.980
So that's very good.

39:40.060 --> 39:43.340
And yeah, exploit code will be released soon.

39:43.340 --> 39:45.000
So stay tuned for that.

39:46.780 --> 39:47.900
Questions?

39:55.690 --> 39:59.510
Is there a microphone?

40:05.470 --> 40:06.790
Hello.

40:08.950 --> 40:18.810
Um, it wasn't entirely clear to me, is the spy flash chip you're referring to on the, uh, CPU die or is it external?

40:19.170 --> 40:20.270
External.

40:20.310 --> 40:21.030
Okay.

40:21.030 --> 40:21.170
Yeah.

40:21.170 --> 40:21.170
Um,

40:39.570 --> 40:51.130
so I'm sorry if I understood your question correctly was about bypassing uh, anti-cheat systems uh, using this method?

40:51.130 --> 40:51.430
Nope.

40:51.430 --> 40:58.010
Installing something to bypass uh, the anti-cheat systems and uh, uh.

40:58.010 --> 41:12.610
Once you achieve arbitrary code execution in SMM, uh, yeah, pretty much uh, like modern anti-cheat systems running uh, either kernel or even maybe a hypervisor level could, could, could run.

41:12.610 --> 41:15.670
And this, this runs even below that.

41:15.670 --> 41:16.670
Does that make sense?

41:16.670 --> 41:27.830
Yeah, but uh, since uh, MAD has disclosed the processors that are vulnerable to this attack, it is the, it is not disclosed in PlayStation 5 which has MAD.

41:27.830 --> 41:31.710
So that's what I was asking if maybe it's also, yeah.

41:35.030 --> 41:36.190
Ah, okay.

41:37.710 --> 41:43.110
But, but yeah, I'm sorry, I, I don't know, uh, I, I don't understand your question correctly.

41:43.930 --> 41:47.910
The, the PlayStation 5 hypervisor blocks the MSR.

41:47.910 --> 41:49.850
If it's for that, yes.

41:49.850 --> 41:51.050
The, the, yes.

41:51.050 --> 41:52.450
We, we check that.

41:52.770 --> 41:55.910
And it is being trapped by the hypervisor layer on the PlayStation.

41:55.910 --> 41:57.130
Yes, sorry.

41:58.330 --> 41:59.430
Hey, thank you.

41:59.430 --> 42:00.610
Um, quick question.

42:00.610 --> 42:06.150
Um, why didn't disabling SMT prevent the system from becoming unstable?

42:06.890 --> 42:08.310
Uh, yes.

42:08.310 --> 42:22.110
So the SMT, when we try to disable it, um, essentially what happens is the other logical core will just not run, but it'll still be there and it will be, all the entry points will be already configured by the firmware, if that makes sense.

42:22.110 --> 42:37.710
So when the SMI happens, it was a level underneath, I mean, it won't, you won't see the processor available at the OS level, but all, all the layout and, and, and, and, at the, at, yeah, at the deeper level, the, the logical core is still there, if that makes sense.

42:37.710 --> 42:38.190
Yes, it does.

42:38.190 --> 42:40.050
So we have to deal with that regardless.

42:40.050 --> 42:40.970
Yes, we tried.

42:40.970 --> 42:41.790
Thank you.

42:43.910 --> 42:44.770
Hello.

42:44.770 --> 42:48.170
Do you know what, uh, changes AMD microcode update made?

42:48.170 --> 42:50.750
Um, I'm sorry, could you, could you speak up louder?

42:50.750 --> 42:51.330
I'll say.

42:51.330 --> 42:56.330
Do you know what changes AMD microcode update made to mitigate this issue?

42:56.330 --> 42:57.830
Oh, interesting question.

42:57.830 --> 42:58.690
Uh, yes.

42:58.690 --> 43:01.310
Uh, no, I mean, officially we don't.

43:01.890 --> 43:10.530
Uh, um, what, uh, what, what, what, what, what, what, what, what, what, what, what, what.

43:10.530 --> 43:11.750
Uh, we don't.

43:12.870 --> 43:14.750
That's a little bit short of it.

43:15.210 --> 43:16.910
Uh, yes.

43:22.030 --> 43:23.830
I think we're good.

43:24.070 --> 43:24.770
Okay.

43:24.770 --> 43:29.470
Well, if no more questions, thank you so much for joining us today.

