start	end	text
0	4900	It's either as a boot kit or in some cases as a firmware implant as we will see later. What's
4900	11540	good also is that code here is hidden from the OS and the hypervisor. So antivirus,
11540	18040	EDRs, or anti-cheat engines won't see these things, right? Now in terms of privilege level
18040	22580	this is just a simplification but we can think about it like this. We have our applications,
22580	27140	like for instance our browser, running at the very top of ring three. Then we have our OS,
27140	32340	ring zero, and if we have a hypervisor it's down the OS of course and only then we have
32340	40340	SMM. Now how does this work? We can divide the uh the thing in two phases. We have boot time
40340	47620	where the firmware BIOS UFI code will after initializing the the hardware will load the SMM
47620	54140	code into an special area of memory called SM RAM. And then it will hand off the execution
54140	60340	to the OS loader then the OS loads and as you can see SMM is just a run time concept. It will
60340	65420	provide services for the for the platform. For instance power management, security, and the
65420	70400	OS can invoke some services from it as well. So how does that happen? Well there's this
70400	77160	concept of system management interrupt. When an SMI occurs the processor gets interrupted and
77160	84040	then this the the current register set of the processor is saved into the SM RAM into a
84040	92940	safety area. And then whatever needs to happen happens some um good feature for the system and
92940	97880	it then comes back to the OS. In this case we are doing a synchronous SMI like a software SMI
97880	107140	the OS is um invoking a service from SMM. Now we've been working on this area for a bit. Uh
107160	112200	we published some some blogs. We've done some some presentations before. How are you on
112200	119700	Hexagon? We have a couple of CVEs in 2023 and we also released some tools for um checking for
119700	126000	misconfigurations and known issues. Um all of these things that we've done before are mostly
126000	131220	related to either misconfigurations from vendors or software vulnerabilities in components.
131220	137200	Now we're going to present today is an architectural flaw in the AMD processor itself. So
137200	141980	that's very different. And so for that we're going to just see again what is what makes the
141980	147500	security of SMM. So we can think on the CPU when it's an SMM mode we have the memory
147500	152280	controller in the middle and we can just access this area with where the SMM code and data
152280	157960	lives. We can execute instructions from this area. We can write to this area and read. However
157960	163660	when the CPU is in normal mode meaning non-SMM, the memory controller just rejects um if if
163660	169700	you read from this uh from this memory you're just going to return receive Fs. Writes are
169700	174860	discarded and of course execution is disallowed. How does this hap- how is this happening?
175780	181960	Well we have um what's called a TSEC region or top of memory segment region. Essentially the
181960	189340	firmware after loads uh after it loads SMM at boot time, it will hopefully configure these
189340	196020	two registers. And the idea is to overlap um have this region to overlap with all the
196020	201140	contents of SM RAM to protect it. We have uh two registers we have the TSEC base and the
201140	206120	TSEC mask which is the length. The TSEC mask as you can see have also uh additional
206120	212660	fields. And yeah essentially this is the way. The memory controller will see that uh the CPU
212660	219200	is executing in normal mode and will just reject to read the content or write the content of
219200	227040	the SM RAM. Has to be enabled. That's why the T-valid is there. Now the layout of SM RAM
227960	234420	uh basically is up to the vendor to define but most systems out there are going to follow
234940	241760	what the EDK2 has which is TianoCore. This is reference code. And uh essentially it's
241760	246400	going to consist at the very bottom you can see here um SMM core area. This is just
246400	251980	supporting code for the rest of of what's going to be in there. And then for each core we're
251980	258280	going to have an SMM base and at a specific offset 8000 from the SMM base we're going to
258280	263380	have the entry point. Which is where the processor, the core is going to start executing
263380	269140	from when the SMI happens. And then we have a safe state at offset FE00. This is TianoCore
269140	274640	right? It can be laid out differently by the vendor. And then we have the SMI handlers at
274640	280060	the very top which are going to be the functions that are are going to be useful for for us
280060	286100	for the system. Handling power, security or whatever. Um so yeah just a summary of the SM
286100	290360	RAM registers. We have the three that we just mentioned and we also have an SMM block.
290360	296640	That's very important. Hopefully the firmware code is going to set this bit so that the
296640	301280	whatever runs at run time the OS cannot tamper with these registers. We don't want for
301280	307460	example at run time having the OS disabling the TSEC location because this will just um
308020	312740	update or change the code at the SM RAM location and execute with these additional
312740	319800	privileges right? Now this needs to be configured for each core. With that we can see a
320360	327000	first difference between how Intel and AMD manage the access to MSRs. On Intel systems
327000	334440	these MSRs that are related to SMM are only accessible while the CPU is in SMM. In fact
334440	341260	obtaining the SMM base for example on Intel could be considered a leak. On AMD all these
341260	347780	MSRs are accessible from ring zero, no problem. Again if we have the SMM block bit set
347780	352540	then the configuration cannot be changed. Not even SMM can change the configuration
352540	356060	until the next power cycle in which I mean the firmware will take over again and
356060	363160	configure this in the same way. But we can now spot the bug in the documentation. This is
363160	370820	the same TSEC mask register and the fields just a picture from the documentation. We can see
370820	376960	how the SMM block is covering all of the fields except for two over there. These two fields
376960	382260	are going to be what we're going to be talking about in this session. And we have T-CLOSE
382260	389260	and A-CLOSE. We're just going to focus on T-CLOSE. A-CLOSE stands for the same feature but
389260	393560	for a previous region called ASEC which overlaps on the video memory. It's not used anymore
393560	400580	so it doesn't matter. But what happens is when this bit is set, the data accesses that the
400580	405080	core that the core performs when it's running in SMM are going to be directed to MMIO
405080	412740	instead of to SMRAM. And that's cool because as we said before, we can set this bit from
412740	419760	ring zero because it's not blocked by the SMM block, right? It actually in the A-CLOSE
419760	425480	description it also says hey, don't forget to unset this when you're returning from SMM
425480	433500	because otherwise your safety are going to be erroneously read from MMIO. That's bad. The
433500	438140	documentation says as well hey, if you have a valid T-CLOSE region and you're in SMM and
438140	443140	the T-CLOSE is set, then instruction fetches are still going to be directed to DRAM but data
443140	449400	accesses are going to go to MMIO instead. If you're not in SMM then both accesses, both type
449400	457200	of accesses are going to go to MMIO. So we can say X86 behaves in a Harvard, like a Harvard
457200	462060	architecture. It goes to Harvard, right? If we have our core zero for example running in
462060	467760	normal mode, both data and instruction fetches just go to MMIO. If we have our core zero now
467760	473500	in SMM with the T-CLOSE off, this is what happens. No problem. We read and execute from SM
473500	478840	RAM. However when we set T-CLOSE on, now data fetches go like this. And this is a problem
478840	486860	because this portion can be controlled by an attacker. So triggering the condition is super
486860	493640	easy. We just need to set this bit, this T-CLOSE bit, and call into an SMI and the system
493640	499700	will immediately freeze, hang, or you're going to spot the problem right there. This feature
499700	507420	exists because, well AMD wanted to have the ability to reuse the physical address space and
507420	514020	have SMM code access an IO device that were using the same SM RAM physical memory
514020	520460	essentially. Um, we haven't seen any vendor using this feature. Um, but yeah, that's why.
520460	526260	And it was, on what we could track is in 2006 there was this document that first mentioned
526260	534600	the feature. So it means it's been around at least for 18 years. Now, for people familiarized
534600	540740	with um, biosecurity they're probably going to remember this vulnerability presented by
540740	547020	Christopher Domas in 2015 called the memory sinkhole attack. And what happened was that he
547020	553520	was able to remap the APIC which is a specific device um, available and overlap it with the
553520	558920	T-SEC area and it caused the same effect. Uh, data fetches will go to MMIO instead of SM RAM.
559140	564480	Now the difference here of course is that that was only limited to the APIC and it only
564480	569600	affected the 4K region where the APIC was overlapped with. The SYNCLOSE behavior
569600	576480	changed uh, how the entire T-SEC works. Um, any device in theory could be overlapped, right?
576480	586880	Because we just direct any access to the MMIO space. So, we can bring some attack ideas in. Our
586880	591780	easy thing will be, the easiest thing will be to just grab any PCI device and hopefully
591780	597340	we'll have a good register layout on its bar so that we can take control of the execution at
597340	601480	the very beginning of the entry point. As there are multiple integrated devices that we
601480	606680	could use, we could just try remapping one of those and based on what we read, the register
606680	614180	should become visible at the T-SEC location from the OS. However this failed. We can see here
614180	623960	how uh, we have an ethernet controller uh, with its original uh, bar 2 uh, D0714000. We have
623960	627900	some registers right here, they're visible registers. And we're going to try to overlap, when
627900	634360	we try to overlap it with the SMM entry uh, BFED0000, we can see that we're still reading F's.
634360	642060	So, the remapping failed. Registers are not available. Um, we can see that the registers were
642060	653940	moved from their original location. Uh, something happened. When we restore, we can see the
654520	660160	the the priority of the memory probably failed, right? So what that that led us to try to
660160	664860	understand okay, how that does, how how is that working? I have this register called top of
664860	674180	memory or TOM. Um, this thing defines a limit between the usable DRAM before 4 gigabytes on the
674180	681880	physical address space and MMIO space on top. Now, on Intel, this register has a lock bit. Once
681880	686300	it's configured, you cannot tamper with it anymore at run time. But on AMD, it doesn't have
686300	691840	such a lock so we can just, you know, modify this and maybe that's good for us. The idea is
691840	697340	simple, we have this is uh, imagine this is the layout, right? And we'll move the MMIO space
697340	701980	of the TOM that defines the MMIO space to match with the TSEC base. So we have something
701980	708580	like that. Maybe then, trying the same trick that we uh, did before could work.
708580	714040	Unfortunately, we could move the TSEC, no problem, but it didn't change the behavior that we saw
714040	722380	before. In practice, it didn't work. So that led us to dig, dig, dig uh, deeper into uh, into
722380	727140	augmentation and we found there are some actual priorities when the core access um, some
727140	731120	portion of the physical address space. Essentially determines what, where it's going. And we
731120	736440	can see that the TSEC and ASIC mechanisms are listed 4, which means 1, 2 and 3, whatever is
736440	741840	listed there has less, less priority than this. And at the, at number 1, we can see the
741840	745780	TOM is, is listed there. So we have, that's why it never worked, right? It would have never
745780	755460	worked. What's at 5, where we have the MMIO configuration space and the APIC? Uh, that
755460	761520	makes sense. We, the APIC was used before in the Intel attack. The MMIO config space we
761520	768960	cannot use really. Um, and then at 6 we have this Norbridge address space uh, routing but uh,
768960	773200	that probably stands for older architectures. This is not seen in modern, modern stuff. So
773200	780220	we cannot use it. For the APIC, we cannot really use it and we're going to explain why. But
780220	787280	for that, I'm going to give an analysis of, of um, how the SMM entry point code works. When
787280	793720	the SMM, when the SMI occurs, the SMM core uh, that, that the core um, executing at SMM
793720	799660	starts executing in real mode. In 16 bit mode, flat. No protection whatsoever. What it has to
799660	804160	do is quickly go to protected mode 32 bit and then goes to long mode and then passes the
804160	808940	execution to the handlers. This is a very simplified view. Now, that first step going to,
808940	812900	from real mode to protected mode is, is key, right? That's the first thing that needs to
812900	821040	happen. For this, um, on x86, we need, essentially are enabled segmentation. Uh,
821040	827440	segmentation provides um, the ability for the, for the core to see the memory in a segmented
827440	831280	way. That's, that's how it's called. Essentially, we can have different segments for
831280	836480	memory and assigns uh, different permissions or like um, the ability to execute code or, or
836480	840400	just read data and stuff like that. We have this key data structure called global
840400	846500	descriptor table of GD or GDT. And we have a register on the processor that is called
846500	852200	GDTR that's going to point to the base of our GDT structure and it's going to have a limit in
852200	856340	bytes. And so the GDT is just really an array of descriptors. And we can have different
856340	859780	types of descriptors. We can have, we can have code descriptors, data descriptors. Each
859780	863580	one is going to have a base. The first one is never used. That's why it's called, it's
863580	868660	called null descriptor. But then, when we have a jump, you can see we'll have um, a jump.
868660	872940	It's not only having an offset like a target location but it's also going to have like a
872940	876820	segment selector right here. That segment selector picks the descriptor we're going to use
876820	882160	for the, for, for our, our code segment. And then the top, the, the offset is added to the
882160	888500	base that is indicated by the GDT. Forming the final linear address. With that we can do
888500	897800	uh, an analysis of um, the EDK2 SMM entry point. Essentially um, we can see that at the very
897800	904840	beginning we are moving into the register BX, the entry point plus 4D. This is, this is a
904840	911120	decom, like um, extracted from a, from, from a compiled um, SMM code. So you can see at 4D
911120	916080	right there we have a GDT description ready to, to, to be loaded into the GDTR. The next
916080	919440	instruction that matters for us is the load GDT. This is the instruction that is going to
919440	925340	load the GDTR with the content that BX points to. And finally, we have a jump over here
925340	931860	that's gonna perform the actual um, going into protected mode. And it has the selector of
931860	939360	code as well and the offset. Now, with this, what, what will happen if we over, overlap a
939360	945640	device that we control on the entry point? And we control offset 4D. What will happen is
945640	950280	that the load GDT will be loading something that we control. So we can load our fake GDT
950280	955320	right? So that's what we're trying to do here. We're trying to get control over the
955320	960800	offset 4D with any device that we can find so that the, the fake GDT then provides the
960800	965560	descriptors we need and we can take control and jump down there. That's the whole idea of
965560	972600	the attack. And that's why the APIC is a problem. Two things. First, the system becomes
972600	977940	unstable when the APIC is moved. Super unstable. Second, the APIC racers are not useful
977940	982740	for taking control in the way we need. We can see that at 4D we have this reserved
982740	987920	regions with all zeros. Rights are discarded here. We're not able to control here and if we
987920	993040	load a GDTR with all zeros we're essentially saying to the processor, hey, here's an
993040	999600	empty GDT. So this won't work. And at this point we found another device not documented by
999600	1004500	the, the specification that also has priority over uh, the TSEC region. That's the
1004500	1012140	spike controller and Christophe's going to describe it for us. Alright. So the spike
1012140	1015160	controller is a very nice device for us because it's present in all the systems we've
1015160	1021020	tested and it's basically used to access the spike flash on um, AMD uh, systems. So for
1021020	1024740	example for reading, writing, erasing the spike flash, it always goes for the spike
1024740	1029720	controller. And it has a couple of key features that are really uh, interesting to us. First
1029720	1034560	of all, we can relocate the bar over the SMM entry point. Secondly, the portions which are
1034560	1039320	interesting to us at offset 4D, we can control them. And three, it actually takes precedence
1039320	1045020	over uh, SMRAM when TCLOS is enabled. So with that in mind, what we will do for our attack is
1045020	1051380	simply take the spike bar, relocate it over the SMM entry point of core zero, and then
1051380	1058420	afterwards manipulate the values at offset 4D within that bar. Um, the um, registers that
1058420	1062460	actually correspond to that portion of memory in the bar uh, are the memory range and
1062460	1067560	ROM protection zero register. Those were used in the past to uh, lock down access to the spike
1067560	1073100	flash, but mostly these are not configured, they're not fixed, so we can fully control them.
1073100	1077800	On some systems they are fixed, but actually they are fixed to values which are still useful
1077800	1085260	for us. So, before I dive into the exploits, uh, I also want to uh, show you a little bit our
1085260	1091260	debugging stuff because it's a little bit special. Um, so we were facing actually two
1091260	1096740	challenges uh, when we tried to develop the exploit. First of all, we didn't really have a
1096740	1101840	way to know whether our payload ran because the system just crashes, reboots, and memory is
1101840	1108320	just all wiped. Uh, and secondly, we didn't really have any debugging framework for SMM. Um,
1108320	1112740	and like for example when crashes happen, we want to be able to modify the code however we
1112740	1118220	see fit. So to resolve the first issue, we actually took a PCI squirrel, which is typically
1118220	1124060	used with PCI leach for DMA attacks, but the nice thing about it is, actually is that it has
1124360	1131000	a bar buffer, as we call it, where when we write to it, it actually survives across
1131000	1136540	reboots. So for instance, a payload can write a value to uh, the bar buffer, kind of like a
1136540	1140320	checkpoint so we know it ran, and then when the system reboots, it's still going to be there.
1140320	1145420	Right. And if we want to modify, for example, for the second issue, if we want to modify uh,
1145420	1150400	code in SMM for some extra debugging capabilities, for that we just um, injected a firmware
1150400	1156480	implant, uh, that loads a nice SMM module that allows us to do all of that. So the setup
1156480	1160540	looks like this, we just have the PCI squirrel connected to our target device via an M2
1161020	1167200	uh, adapter, and all of this is powered externally by a power supply. So, it's time to get our
1167200	1172180	hands dirty, so let's take a look at how uh, the exploit looks like. In the first attempt,
1172180	1176920	uh, we remap the spy bar, just like mentioned before, over the SMM entry point of core zero,
1176920	1183160	then we tweak uh, these values at offset 4D. We create a fake GDT in the beginning of the
1183160	1187340	address space, uh, with the, with a nice base address that will allow us when the jump
1187340	1193520	happens to redirect the execution to our own payload. And then when we uh, execute the SMM
1193520	1198120	entry point code with TCLOS enabled, what's going to happen is uh, the old GDT is actually
1198120	1203740	going to load the GDT register uh, with a value that points to our own fake GDT, so that's
1203740	1208480	great. And afterwards, when the jump happens, a descriptor from the fake GDT is going to be
1208480	1217740	taken that we control, um, and it's going to be used as a base uh, for the jump. So, and um,
1217740	1223020	this is going to redirect the execution like this, at least in theory. So, um, an interesting
1223020	1230900	detail is actually how we pick the base address in the GDT descriptor, um, and for that we have
1230900	1236320	to understand how it normally executes and how it executes with TCLOS in this case. So, um,
1236320	1242640	when the for jump happens, um, and the normal execution, what happens is the GDT register is
1242640	1247260	going to point to a GDT within SMRAM where it's nicely protected, um, and the segment
1247260	1252020	selector is going to index into that table, um, and the base is going to be actually fixed to
1252020	1257920	zero. Which means with the base of zero when we add it uh, to the for jump offset, what's
1257920	1262720	going to happen is the linear address is going to be the same. Now in our case, actually we
1262720	1269620	have a bit of an issue. We want to read the execution, um, outside of TSEG. The only
1269620	1274820	problem is that within the first four gigs of memory, after TSEG, there's not really any spot
1274820	1279360	where we can put a payload, right? So, if we increase the base a little bit, sure the
1279360	1283900	instruction pointer is going to go a bit more up, up, up, up, and the address space, we don't
1283900	1289120	really have DRAM over there that we control. So we wondered, okay, what happens if we
1289120	1296460	actually increase the base such that when we, uh, the base of the GDT descriptor, such that
1296460	1304280	when we add it to the for jump offset, it actually overflows. Um, yeah, it just overflows.
1304280	1308520	So we thought, okay, this isn't going to be possible, but actually it was. Uh, this is nice
1308520	1313480	because, uh, if we choose the base sufficiently big and we add the offset, we can actually make
1313480	1316640	it wrap around and make it jump to our own payload in the beginning of the physical address
1316640	1321060	space. The beginning of the physical address space, we have DRAM there, great, we control all
1321060	1327040	of that. So, uh, that was one of the key takeaways actually that we had from the research as
1327040	1334020	well. So this worked, our payload actually ran, and we saw this because it would write a
1334020	1337740	value, this nice checkpoint to our bar buffer, but the system would crash and we wondered,
1337740	1341900	okay, why is this happening? Um, the reason was the SMM safe state. So like Enrique
1341900	1346840	mentioned, when a CPU goes to SMM mode, it actually saves the current register state into
1346840	1352040	the, uh, SMM safe state. When it returns, it just restores it. What happens is when TCLOS
1352040	1357960	is enabled, actually the writes, when the core enters SMM, are going to be discarded, which
1357960	1362800	means when we return with TCLOS disabled, actually it's just going to use stale values that
1362800	1368260	were still there, that were stored before. And to resolve this, the trick is actually pretty
1368260	1374300	straightforward. We trigger the SMM twice. One time, um, without TCLOS and the second time
1374300	1381340	with TCLOS. So we first put the core zero into a known controlled state, and then trigger an
1381340	1386400	SMI without TCLOS. This is going to prime the SMM safe state, and afterwards when we trigger
1386400	1391740	the bug, with TCLOS enabled, the code is going to go for the same execution path, and it's
1391740	1398560	just going to reuse the values that we stored before. So that worked, but unfortunately it
1398560	1403200	crashed again. But this time around we did see actually that the, uh, the core zero was
1403200	1407180	returning from SMM, so that was great. We had full control of core zero, OS code was
1407180	1412660	running, we saw our checkpoints, great. But no matter what we tried, this damn thing was
1412660	1417300	still crashing. Um, so we spent an eternity debugging this thing until we stumbled into
1417300	1424820	this. When we enable TCLOS, what happens is, we enable it on core zero only, but actually it
1424820	1430540	gets enabled on both cores. Core zero and core one. Um, and we found that the culprit for
1430540	1434840	this is symmetric multi-threading, so this is AMD's implementation of Intel hyper-threading.
1435020	1439740	Um, and what it does is it divides a physical core into two logical cores. And some of the
1439740	1444160	resources on these logical cores are shared and some of them are not. So for instance the
1444160	1451560	SMM base MSR is separate, so every logical core has a different base MSR. But the TSEC mask is
1451560	1457780	actually shared, which is what we just saw, right? And we wondered, is this the actual issue?
1457780	1463100	Because we assume when an SMI gets triggered, that only one core goes into SMM at the time.
1464040	1468400	And we put this to the test and what we saw is the following. When we have multiple cores
1468400	1474880	running in normal mode, so outside of SMM, um, when we, when one of them triggers an SMI, an
1474880	1479480	interrupt gets asserted on all of the cores and all of the cores are going to go into SMM mode
1479480	1487000	and going to start executing the SMM entry point codes, um, for each and one of them. So,
1487000	1490940	our assumptions were actually wrong, right? We assumed the SMIs are local, but they're
1490940	1495620	actually not. And we thought that this was actually the case because the IDK2 code has a
1495620	1500940	so-called rendezvous routine, which will, every time you enter into SMM, this routine is
1500940	1506500	going to be triggered and that core which entered into SMM will send an explicit interprocessor
1506500	1512100	interrupt to all of the logical cores to explicitly pull them from whatever state they were in
1512100	1516880	into SMM. And, well, what's the point of that if actually all the cores always go into SMM
1516880	1521380	anyway, right? Um, and we dug a little bit deeper into the documentation and we found that
1521380	1526300	the IO hub seems to be responsible for this to, uh, basically assert this interrupt on all of
1526300	1534160	the cores. So, we're out of luck. So, to summarize, we had all cores always going into SMM
1535500	1539120	and T-Cores being enabled on two cores at the same time and not just one as we initially
1539120	1545380	thought. And this will actually make just core 1 go haywire, right? We have control of core 0
1545380	1550360	but core 1 is, uh, just going to go nuts and crash the whole system. So, to tackle the
1550360	1557140	problem, we had to get control of core 1 some way. Uh, and we dug deep into our bag of tricks
1557140	1563140	to really, uh, see if maybe there's a nice elegant solution to this to just take core 1 out
1563140	1570480	of the running. Um, so we tried to, um, we tried to find another device to overlap with the
1570480	1575480	entry point of core 1. There was none. Uh, we tried to disable SMT in the BIOS. That also
1575480	1581940	didn't work. We tried to, uh, use the, uh, so-called init IPI and also the SKL instruction to
1581940	1588200	put core 1 into a state that would actually make it ignore SMIs. That also didn't work. And
1588200	1592480	finally, we also tried to send a so-called SMI IPI which, at least according to the
1592480	1598100	documentation, would allow us to trigger an SMI on individual cores. And it also didn't work.
1598100	1602880	So, despite the documentation indicating one thing, in practice, we didn't manage to, uh, get
1602880	1607380	it to work. So, we're running out of options and we had to take a step back and analyze the
1607380	1611960	problem. And we realized, okay, the LGDT has the actual problem because it's going to be
1611960	1619360	load- loading the GDT register with all Fs, right? So, is this, is there maybe some way we can
1619360	1625780	actually still take advantage of this? Um, so, when the supplementary point normally executes
1625780	1629980	what happens with the GDT register is, it's going to be loaded with a nice value for the base.
1629980	1635860	It's going to be pointing to the GDT within, uh, SMRAM, right? And afterwards, the segment
1635860	1642220	selector is going to be taken, added to it, uh, and the base within that, uh, descriptor is
1642220	1648400	going to be used to calculate the final linear address. Now, in our case, what's going to
1648400	1653180	happen when TICOS is enabled, uh, the GDT register is going to be loaded with all Fs, both the
1653180	1659920	limits and the base. And what's going to happen then is, when the for jump, the segment
1659920	1664280	selector is going to be added to it. And once again, we have our good old friend's integer
1664280	1669900	overflow. It's actually going to result in the physical address 7. And this is actually
1669900	1674260	awesome because address 7 in the physical address space, once again, that's DRAM. We control
1674260	1679480	DRAM. So, we can take advantage of that. We can put our GDT at the beginning of DRAM and we
1679480	1685880	can just overflow this thing like this. And afterwards, uh, from the GDT we control, we set a
1685880	1692020	nice base so that afterwards, uh, the code jumps wherever we want it to. So, to summarize, we
1692020	1696620	have two types of wraparounds. One is between the GDT descriptor base and the for jump offset.
1696620	1702760	And the second one between the GDT register base and the for jump segment selector. And the
1702760	1708580	nice thing about this is, we can actually reuse the same fake GDT for both core zero and
1708580	1715740	core one. And the added bonus is, we don't even need the spy bar anymore. The only thing
1715740	1720180	that we really have to take care of is the SMM safe state. Once again, for core one. For core
1720180	1725300	zero, we just do the same thing as before. But core one is going to be running in some
1725300	1729600	unknown state. It could be running in ring three, ring zero, just in an unknown context. We
1729600	1733980	have to bring it to the same controlled state as core zero. And we do so by using a kernel
1733980	1739220	synchronization API. Which on Windows is the deferred procedure call. Or on Linux,
1739220	1745360	symmetric multiprocessing. And basically once that's done, we have both cores in a known
1745360	1752400	state. And we can use the same trick we did for core zero. So, all good things are three. So,
1752400	1757960	let's try again. The exploit this time is greatly simplified. And the only thing we have to
1757960	1763600	do is, we create the fake GDT in the beginning of the address space. We choose the base
1763600	1769060	address within the descriptor accordingly. And that's it. And then when we trigger, when we
1769060	1774540	enable T-Close and run the uh, SMM entry point code again, the old GDT this time around is
1774540	1779560	going to point to the very end of the address space of the first four gigs. But then when the
1779560	1784020	far jump happens, it's going to wrap around. It's going to fetch the GDT descriptor entry from
1784020	1789260	the beginning of the address space from our fake GDT. And then afterwards it's going to
1789260	1795580	redirect execution for both core zero and core one to our own payload. And it finally
1795580	1800180	worked. We managed to control both cores, core zero and core one. Uh, our payload would
1800180	1805660	execute with SMM privileges and uh, it would return gracefully from SMM to the operating
1805660	1809560	system and nothing would crash. And that was great. There were only a couple of things that
1809560	1816460	we wanted to improve uh, in our exploit. And that was um, to reload the GDT because the base
1816460	1822880	actually is um, a bit off. So we just reloaded the GDT so that the base address is equal zero
1822880	1828060	again so that we don't have strange misalignment issues. We set up long modes, so page
1828060	1834000	tables, stack pointer, etc. so we can execute like uh, any SQL that we want. Uh, and then we
1834000	1838600	also install an SMI hander so that we only have to exploit the bug once and then basically we
1838600	1845640	have kind of semi persistence until the system resets. Right? So, for the demo, just to
1845640	1851700	show you I'm not selling just some snake oil. Uh, we have a system over here which is a
1851700	1860000	Huawei Matebook D16 from uh, 2023. And you can see when the system boots, it actually shows
1860000	1866500	the Huawei logo. That logo is embedded in the firmware code. For that, um, so for our
1866500	1871860	exploit we're actually going to modify that uh, that logo. So, um, we're going to run our
1871860	1876360	exploit with uh, kernel privileges. So you'll see over here that we have to elevate
1876360	1882260	privileges and it's going to be triggered via a malicious driver. And then our exploit is
1882260	1886500	going to do uh, three things. At first it's going to use the synclose issue to elevate
1886500	1892220	privileges to SMM. Then it's going to disable the spy flash protections. And then
1892220	1897660	afterwards it's going to write to the spy flash the portion where the um, boot splash logo
1897660	1902640	is actually residing. This takes a little while, about 15 minutes, so we just fast forward
1902640	1909200	that portion. And you can see okay, it shows done patching, all good. And at this point we
1909200	1922480	just reset the system and pray that it works. So let's see. Yeah, this one takes a little
1922480	1939880	while. And... there we go. We're successful. So, I'm actually going to show you how to
1939900	1942580	do this. So I mean this was just one example of what we can do with this kind of access into
1942580	1947340	the system. But let's take a more systematic approach to see whether this works on all
1947340	1952760	systems, just on some. What does this actually depend on? So the next attack paths depend on
1952760	1958600	how the platform is actually configured. Um, so every vendor configures certain features
1958600	1964460	that AMD provides to them. And specifically there are two of them which are key to this. One
1964460	1969820	is room armor, which can be used to restrict access to the portions of the spy flash. And
1969820	1974580	the second one is platform secure boot, which is AMD's equivalent of boot guard, which will
1974580	1980760	verify the initial stages of the firmware code. Um, so if everything is enabled, the very
1980760	1985180	least thing that we can do is we can write to a portion of the spy flash where you have your
1985180	1989280	variables live. So for instance, in these variables you're going to have things like the
1989280	1995720	secure boot keys which are used. So we can break secure boot. That's nice. Um, but if nothing
1995720	1999280	is enabled, actually we have firmware implants. I'm going to explain in a moment what the
1999280	2003480	difference actually is. So in the first configuration where everything is properly
2003480	2008700	configured, we see, okay, we escalate from the operating system to SMM. And from there we can
2008700	2014480	write the, let's say, firmware data portion of the spy flash where the configurations are. So
2014480	2018900	we can manipulate the secure boot keys so that afterwards we can actually load our own
2018900	2024460	malicious boot loader before the OS loader runs. On the second configuration where the PSB
2024460	2029920	is not enabled, we have basically the same scenario. Um, Roam Armor will still restrict
2029920	2038740	write access to, um, to the data portion. And we can, we can still just, um, uh, inject our own
2038740	2044100	boot kits. And the third configuration we can write to even firmware code, but that's going to
2044100	2049840	be still verified by platform secure boot. So, okay, and these three, we have the same
2049840	2053220	scenario. We can just inject a boot kit, which is still nice because it runs before the OS
2053220	2058520	loader. Any protections provided by the operating system would still be, um, rendered null.
2059880	2064440	But, in the last scenario where none of these features are enabled, what we can do is we can
2064440	2069440	inject our, uh, malware into the spy flash, into the firmware code portion of it. And when
2069440	2075900	that happens, uh, is what we're going to get is we can, um, run our own malware at the very
2075900	2080880	earliest stage of the boot process. And there's a key difference here between a firmware
2080880	2087900	implant and, uh, a boot kit, is that this attack actually is resistant to, uh, to OS
2087900	2093240	reinstallations. So even if you wipe your drive, it's still going to be around. Um, and even if
2093240	2096840	you try to push a firmware update from the operating system, it's still going to be around
2096840	2102540	because the, uh, the malware can just say, well, the update was successful. Um, and the only
2102540	2107940	way to really get rid of it at that point is to take apart your system, take a spy programmer
2108360	2116400	to read out the spy flash, inspect it, and if it's infected, um, just, uh, rewrite it. But
2117340	2122980	typically it's not really in the repertoire of a typical IT guy, right? So to illustrate how
2122980	2127200	prevalent actually these misconfigurations are, we did some research last year on that and
2127200	2130700	we saw that the majority of the systems have none of the security features actually
2130700	2135620	enabled. Which means all the systems which have none of the features enabled are
2135620	2140900	vulnerable to firmware implants. Which is pretty bad. And to put a cherry on top, we also
2140900	2145460	found that once you're infected with that kind of, uh, firmware implant, you can even disable
2145460	2150300	platform secure boot forever by burning a specific fuse so that your system remains
2150300	2157840	vulnerable to firmware, uh, implant reinfections forever. Sweet. So, let's wrap up the
2157840	2167440	presentation. Thanks Christophe. So, yeah, in terms of affected systems, um, I think
2167460	2173960	we covered most of them, right? Pretty much all of them. Uh, yeah. Um, our tests were on
2173960	2180380	Ryzen, mostly. Several laptops. Uh, but turns out the Threat Reaper series is also
2180380	2188900	affected. Epic series is also affected. Meaning servers. Um, and yeah, uh, due to the
2188900	2197300	longevity of this, this, this thing, we can estimate the total number of affected chips are in
2197300	2205320	around the hundreds of millions. Um, there's an advisory from AMD published now, um, where
2205320	2211560	more information on the system, the affected systems and cover, uh, there's a microcode
2211560	2219820	update now. Information is there, so you can check. Mitigations. Yeah, AMD, as I just
2219820	2225580	said, provided, um, with microcode updates. However, it might not cover all of the
2225580	2233200	affected systems. Of course, um, in terms of what an OEM can do, they can just modify the
2233200	2240020	SMM entry point code to detect if the T-Close bit is set. And if it is, then just abort the
2240020	2245620	execution and this, this will just render the exploitation unfeasible. Uh, this can even
2245620	2254080	be done at the EDK 2 level for AMD systems, right? And we really haven't covered here core
2254080	2259880	boot, but core boot is affected in the same way. We just, I mean, um, core boot at the very
2259880	2264640	beginning of the entry point performs a low GDT. They have to go to protected mode as well,
2264640	2270860	so it's, it's the same thing. Um, and actually core boot, they are checking for this, uh, for
2270860	2277180	other issues as well at the entry point, so they could, they could very well do this. Um,
2277180	2282760	and users, well, they can, you know, a hypervisor could trap the access on the TSEC mask
2282760	2290460	MSR, so that's another, uh, way to stop this. Timeline wise, well, we reported this back in
2290460	2298480	October of 2023. A CVE of 2023, uh, 31315 was assigned in November. And then we discussed
2298480	2303500	mitigations and impact with AMD over the course of the next months. Um, and yeah, finally
2304100	2310340	yesterday, um, the advisory was published and we are here at DEF CON today. This was the
2310340	2318100	official AMD response. Essentially, we work with them in a process of, uh, responsible
2318100	2325440	disclosure. And yeah, they've been great to work with. Conclusions and takeaways. Well, the
2325440	2332360	vulnerability has been around for nearly two decades. Um, the complexity of the architecture
2332360	2337660	clearly plays in favor of attackers and we see this, uh, with the flexibility of, of, of the
2337660	2344780	GDT. Um, the two types of wraparounds, the, the, the byte level, uh, um, address, um,
2344780	2351820	like granularity that there is with it, no problem. Um, and also with the, how the MSRs can
2351820	2357440	be accessed without any restriction. Uh, that, that's, that's all good for attackers, right?
2357440	2366320	Um, these things combined are what made this exploit approach possible. It might be on other
2366320	2372180	exploit methods too. Um, but yeah, all of this of, of course requires an in depth
2372180	2377080	understanding of the architecture. And in the end we managed to exploit this without
2377080	2382620	requiring physical presence. So that's very good. And yeah, exploit code will be released
2382620	2387900	soon. So stay tuned for that. Questions?
2395690	2414350	Is there a microphone? Hello. Um, it wasn't entirely clear to me, is the spy flash chip
2414350	2421170	you're referring to on the, uh, CPU die or is it external? External. Okay. Yeah. Um,
2439570	2449350	so I'm sorry if I understood your question correctly was about bypassing uh, anti-cheat
2449350	2454710	systems uh, using this method? Nope. Installing something to bypass uh, the anti-cheat
2454710	2463810	systems and uh, uh. Once you achieve arbitrary code execution in SMM, uh, yeah, pretty much
2463810	2471110	uh, like modern anti-cheat systems running uh, either kernel or even maybe a hypervisor
2471110	2476670	level could, could, could run. And this, this runs even below that. Does that make sense?
2476670	2484270	Yeah, but uh, since uh, MAD has disclosed the processors that are vulnerable to this attack,
2484270	2489230	it is the, it is not disclosed in PlayStation 5 which has MAD. So that's what I was asking
2489230	2501330	if maybe it's also, yeah. Ah, okay. But, but yeah, I'm sorry, I, I don't know, uh, I, I don't
2501330	2507910	understand your question correctly. The, the PlayStation 5 hypervisor blocks the MSR.
2507910	2514330	If it's for that, yes. The, the, yes. We, we check that. And it is being trapped by the
2514330	2521230	hypervisor layer on the PlayStation. Yes, sorry. Hey, thank you. Um, quick question. Um, why
2521230	2529630	didn't disabling SMT prevent the system from becoming unstable? Uh, yes. So the SMT, when we
2529630	2535850	try to disable it, um, essentially what happens is the other logical core will just not run,
2535850	2540770	but it'll still be there and it will be, all the entry points will be already configured by
2540770	2544970	the firmware, if that makes sense. So when the SMI happens, it was a level underneath, I
2544970	2550550	mean, it won't, you won't see the processor available at the OS level, but all, all the layout
2550550	2556510	and, and, and, and, at the, at, yeah, at the deeper level, the, the logical core is still
2556510	2560490	there, if that makes sense. Yes, it does. So we have to deal with that regardless. Yes, we
2560490	2568610	tried. Thank you. Hello. Do you know what, uh, changes AMD microcode update made? Um, I'm
2568610	2573950	sorry, could you, could you speak up louder? I'll say. Do you know what changes AMD microcode
2573950	2579890	update made to mitigate this issue? Oh, interesting question. Uh, yes. Uh, no, I mean,
2579890	2590270	officially we don't. Uh, um, what, uh, what, what, what, what, what, what, what, what, what, what,
2590490	2604770	what, what. Uh, we don't. That's a little bit short of it. Uh, yes. I think we're good. Okay.
2604770	2609470	Well, if no more questions, thank you so much for joining us today.
