start	end	text
60	10040	Okay, sorry for that. Good afternoon, everyone. My name is Xuexin. I'm the manager of Android
10040	20360	Red team. Today I'm really honored to present you the way to Android root exploiting your
20360	29040	GPU on smartphone with these two gentlemen. This is Xilin Gong, our security researcher.
29040	36140	And he actually did most of the work, technical work, so big credit to him. And also next
36140	41400	to Xilin is our tech lead, Eugene Rodionov. Eugene did a lot of work to help us create
41400	45980	the slides and making sure the demo runs smoothly. Big shout out to him.
47720	54040	So our story dated back to the earliest year when Xilin decided to take a look at Qualcomm
54040	63020	GPU drivers. But before we go into details, here's a brief introduction of our team. So
63020	69980	we are the Android Red team. Our goal is to increase the Android and pixel security. And
69980	78720	we do this by simulating adversaries attacking Android key features. And our work can be
78720	84400	broken down into a couple of different ways. Most obviously, we do offensive security research
84400	92940	review to verify our breaking security assumptions, which means finding bugs. And we scale our
92940	101120	work by developing tools such as continuous fuzzing or static analysis. And once we find
101120	109660	issues, we develop proof of concept just to show the real world impact as some issues are not
109660	116840	so straightforward to see their impact. Lastly, while we're developing the exploits, we're also
116840	124860	assessing the efficacy of the security mitigations that our feature team implemented. The more
124860	132220	pain we experience during our work, the more security our end user will gain. So we are
132220	142390	literally making our work harder to help end users. So here's today's agenda. We'll first talk
142390	148830	about the GPU and security background. And then we'll go through the Qualcomm Adrena GPU
148830	154710	introduction, talking about its architecture and where the issue patterns are. And then we'll
154710	162370	dive into a very technical details for the CVE-2024-23380 and how we exploit to gain root
162370	174840	privilege. Lastly, we'll conclude our talk with the methodology discussions. So before we jump
175580	186340	into engagement, usually we need to ask ourselves questions. Why do we look into this one? The
186340	191480	answer is because our team is very small. So we want to spend our time into the most impactful
191480	199680	areas. So why GPU drivers? Here we think these are the answers to that question. The biggest one
199680	208440	is there is no permission required for applications to look into GPU driver. On the right side
208440	214980	you can see a diagram. And the unprivileged applications, whatever user space library they call,
214980	222040	OpenGL, Vulkan, anything else, those libraries talk into the device node directly in the
222040	228920	applications process. So that means this device driver has to be exposed to the application. So no
228920	236460	permission required. This is the biggest problem. And this is why researchers love GPU drivers.
237220	245460	Next one. GPU driver performance is the key. And because of that, they need to have some
245460	251880	powerful functions to do this. The most important one is that they usually have access to the
251880	258860	system physical RAMs so that they can map memories from user space to kernel space and to the
258860	265440	hardware without copying them. This is a very powerful primitive and attackers want that.
266400	272540	We'll explain more later why it's powerful. And lastly, again, because of the performance
272540	280880	requirement, this involves high complexity code in the GPU driver. And because of that, it's
280880	286840	really, really hard to develop bug-free code. I'm not sure if anybody here writes bug-free code.
286840	295560	Raise your hand if you did. Wow, very brave. Anyway, and it's even harder to fix an issue. And
295560	301880	it's very common that you fix an issue, but it's not 100% fixed. There's still something left
301880	311540	over. And even worse, you fix one issue, you introduce another new issue. Or two issues. So
311540	315840	this high complexity is another reason one look into this area.
320880	326240	Hello? Hello?
326680	330120	Sorry. That's not your problem.
337450	347440	Hello? Hello?
347440	349480	I can use this one.
354590	364170	Okay, we have issues, so we fix them. So, why Qualcomm? Qualcomm is one of the most important
364170	371910	smartphone SoC vendors. And many devices use Qualcomm SoCs. And on those SoCs, Arduino GPU
371910	382550	is the one used the most. And last one is, this applies to all GPUs, that GPU is a very actively
382550	389070	developing area. Because of all the requirements, all the games keep having high resolutions,
389070	396370	faster speed, faster FPS. So there's lots of development happening that involves revolutions
396370	403930	in architecture. Hardware, software. And coincidentally, we noticed that there is a new architecture
403930	412450	recently in the Qualcomm GPU. New architecture, new software means new bugs. So we want to take a look
412450	422260	and see what's the difference and is there any issues there. And another study we did before we
422260	430260	look into our source code, I mean, our Qualcomm source code, is to check the security bulletins
430260	437160	and is there any historical issues. And here's a chart that we manually created from the Qualcomm
437160	444180	security bulletin. The size of the bars might look a little bit scary, but you can see the numbers
444180	452200	actually are single digits. So there's not a lot of issues, but my point here is that you can see this
452200	459880	is more like constant issues happening every quarter. So this chart gives us a little bit of confidence
459880	467620	that if we look into the code, we might as well find issues. Oh, by the way, I forgot to mention,
467620	473000	all our work is based on open source Qualcomm drivers, so everything is public. There's no private
473000	481140	information involved. Among all those issues, there are quite some high profile issues disclosed and
481140	489000	talked by previous security researchers. These talks are great, and we learn a lot from the talks.
489000	494600	Really big credit to them for helping us to jump into an area we've never looked at before.
496740	503260	And now we look back into just the recent three months. Here are all the issues reported to Qualcomm
503260	510860	security, disclosed by Qualcomm security bulletin. Our security researcher, Xilin, did a little bit
510860	518980	of analysis and focused on the last two columns. You can see the tech area, mostly many of the issues
518980	527060	are focusing on IOMMUs. That matches our previous assumption that physical memory is the key.
527260	535980	And also, very subjective, but based on Xilin's experience, most of the issues are easy to exploit.
535980	544740	And once exploited, they are pretty stable. Attackers want the stability. They want their code to be good.
546460	552200	Over the course of our engagement, Xilin has identified more than nine issues.
552860	560680	We report all the issues to Qualcomm immediately. And today we're going to talk about CVE-2024-23380.
560680	567240	This is one of the issues we reported. This issue has been patched and published in the security bulletin
567240	575320	of July 2024. And Qualcomm communicated to all the device vendors in April before the disclosure.
575440	582920	So, go to the security bulletins. You can see what's affecting devices. But don't worry if your device is affected
582920	587480	and check your security patch level. If it's July or later, it's fixed.
588840	596400	And from here, I'll hand over to Xilin to talk about technical details and how we exploit to gain root privilege.
601560	613280	Yeah, thank you, Xilin. So, I'll quickly introduce the basic knowledge of Andrino GPU.
613320	624620	So, here is the basic architecture. You can see in the middle is the KGSL driver, which is the glue between the user space and the hardware.
624620	637480	So, from the perspective of the user space, we will have a set of interfaces. The first one is the context, which is used to identify user space applications
637480	648020	and also to manage the GPU driver or hardware resources. And also, the user space may want to share memory with the GPU hardware.
648020	656320	So, we will have memory interfaces. There are three types of memory. The basic memory, the user space memory, the DMA memory.
656320	663920	And previously, we also have the sparse memory. But now, this sparse memory is already not used anymore.
664120	673320	And the user space also wants to send the customer GPU commands to the GPU hardware. So, we will have some command interfaces.
673320	681480	And also, the user space wants to get synced with the GPU hardware. So, we will have synchronization interfaces.
681480	691320	To accomplish these tasks in the GPU driver, we will have a command queue, which receives commands from the user space.
691320	701680	And then, the software dispatcher will get the command from the queue and add the necessary information and maybe modify the GPU command
701680	710980	and then send them to the RAM buffer. There is a simple firmware in the GPU hardware, which will receive commands from the RAM buffer
710980	717960	and send the command to the hardware. So, GPU customer commands will be run in the GPU hardware.
717960	725900	Also, we will have something like the global buffer, the registers to control the GPU hardware.
725900	736920	For memory management, we will have memory pool and MMU for the user space memory and IOMMU for controlling the GPU memory.
736920	750420	So, this is the new architecture starting from generation 7 and the later generation. You can see we have a lot of new stuff in red color.
750420	761380	The most important change is the software dispatcher is replaced by the hardware scheduler, which means the GPU command comes from the user space.
761380	768400	It will not be sent to the RAM buffer directly by the driver. The driver will not touch the RAM buffer anymore.
768400	780500	Instead, the driver will send this command directly to a HiFi command queue. So, there is a simple firmware and this firmware will take over
780500	791240	and finish the job previously finished by the driver. So, a lot of software dispatcher jobs will be moved to the firmware.
791240	801860	So, we don't have the source code of the firmware. So, I can just guess that this job previously finished by the software dispatcher will move to the firmware.
801860	808520	But how it works and whether there are any vulnerabilities, I have no idea now.
808520	819760	And also, to coordinate with these new features, some other new features like the hardware fence is added. Previously, we only had the software fence.
819760	832400	Now, we also have a hardware fence that will introduce a lot of new code, new features, and also a new hardware fence queue and new hardware fence event here.
832400	846540	For the memory, we will have a new virtual buffer object. You can see here, this is a new VBO. And the previously ARM IOMMU will be replaced by the Qualcomm-owned IOMMU.
846540	858040	So, these new features will, of course, enhance the GPU capability, but also will introduce a lot of new attack surfaces.
859680	867100	If you want to look into some new vulnerability, you can start from the new features.
867640	876040	Here, I'll also introduce the memory management. You can see here is the basic memory management called a basic memory object.
876080	884920	So, it's used in most of the cases you want to share some memory to the GPU from the user space, you will request a basic memory object.
884920	895060	It's a basic, so it's used in most of the cases. You call this our control, and you set a parameter to tell the driver how many physical pages you want.
895060	899500	Then, the driver will allocate this number of physical pages for you.
899540	906600	And then, the second step, the driver will allocate an address range in the GPU virtual address space.
906600	910920	So, you can see here, we have this virtual GPU address.
911120	917100	And then, the GPU driver will set this physical to virtual mapping for you.
917100	925360	So, at this time, the GPU hardware will be able to access to the physical page using this GPU virtual address.
925960	931700	And in most of the cases, the user space will also want to access to the physical page.
931700	937140	So, the user space will do memory map on this basic memory object.
937140	945620	And then, the driver will help you to set up the physical page to virtual mapping through the MMU.
945620	953620	So, at this time, the physical page can be accessed from both the GPU hardware and the user space.
953620	955560	So, that's the basic memory object.
955560	962380	The driver will manage all the objects in the kernel and also manage the backend physical memory.
962860	967920	And here is the second type of memory object. It's called the user space memory.
967920	973140	So, suppose you already have a user space memory, you have a backend physical memory,
973140	981120	you can use this user space memory object to import memory from the user space into the GPU hardware.
981120	986520	And here is the third type of memory. It's called the virtual buffer object.
986540	992120	From the name virtual, you may guess that it's virtual.
992400	999220	So, for this type of memory, it doesn't have its own backend physical memory.
999220	1002380	So, you call this out control with this flag.
1002380	1008020	Then, the driver will simply allocate a GPU virtual address for you.
1008020	1013260	And then, it will map this virtual address to a dummy ZeroPage.
1013260	1016940	So, it's a dummy ZeroPage. It's just a placeholder.
1017640	1023880	Of course, you can access it to the virtual memory in the GPU hardware, but it's no effect.
1023880	1026820	Whatever you read or write will have no effect.
1026820	1030080	It's just a ZeroPage. It will have no effect.
1030080	1033340	So, how to use this virtual buffer object?
1033340	1039580	You can actually map a basic memory object into this VBO.
1039580	1044620	So, suppose you already have two basic memory objects, A and B.
1044620	1048360	Both of them have their own backend physical memory.
1048360	1052640	You can bind these two basic memory objects into this VBO.
1052640	1055240	So, you call this bindRangeOutControl.
1055240	1057660	Then, the driver will do the work.
1057660	1062540	The first step, the driver will remove any existing mapping from the VBO.
1062540	1066200	Here, we already mapped the ZeroPage to the VBO.
1066200	1068340	So, this mapping will be removed.
1068340	1073580	If you have previously mapped any other basic memory object to this VBO,
1073580	1077200	these maps will also be removed.
1077620	1082840	So, the first step, we will remove any existing mapping from the VBO.
1082960	1089960	And then, we will get a connection between this basic memory object and the VBO.
1089960	1093340	So, the driver will know that there is a connection.
1093340	1096360	Somebody is using this basic memory object.
1096360	1098840	So, this object cannot be freed.
1099200	1105200	And also, the driver will help you to find out the physical memory page of this basic memory object.
1105260	1109680	And then, the driver will help you to set up this connection.
1110320	1113900	So, you can see here is the physical memory to virtual mapping.
1113900	1120980	We will map this physical page into the VBO's region at a specified offset.
1121420	1126140	And also, the driver will continue these two steps.
1126140	1129900	Find all the basic memory objects you want.
1129900	1134580	And get all the connections between the basic memory object and the VBO.
1134580	1139140	And then, map all the physical pages to this VBO.
1139140	1141540	So, that's the basic memory object.
1142420	1144420	Binding to the VBO.
1144420	1148800	It's very powerful and flexible.
1148800	1151480	But also, very vulnerable.
1151480	1156960	You can see here we have this CVE-2024-23380.
1156960	1162640	Which happens when you bind a basic memory object into a VBO.
1162640	1164920	So, we will take a look at the code.
1164920	1172520	You can see when we do the binding, we will get a connection between this basic memory object and the VBO.
1172520	1177220	So, the connection is finished by this function, intervalTreeInsert.
1177220	1181240	So, insert this basic memory object into the VBO.
1182200	1188440	Then, we will get a physical page and virtual address mapping.
1188440	1192120	We will set up this mapping using this function.
1193560	1194680	MMUMapChild.
1195620	1200900	So, of course, we will have to protect our global status.
1200980	1205920	So, we will use this mutex lock to protect the intervalTree.
1205920	1209400	So, this intervalTree is a global status.
1209520	1212080	This will be protected by the lock.
1212080	1214520	And when we finish, we will do unlock.
1214660	1217240	And here, the vulnerabilities.
1217580	1221440	This physical to virtual mapping is also a global resource.
1221440	1224340	So, it should also be protected by the lock.
1224340	1228880	But you can see here, this physical to virtual mapping is outside of the lock.
1229020	1233300	So, it's possible from the driver's perspective.
1233400	1238680	We already have this basic memory object connected to the VBO.
1238800	1244860	When we do the physical to virtual mapping, this connection might be removed by somebody else.
1244860	1246580	So, that's the vulnerability.
1247620	1249540	Let's take a look at the fix.
1249540	1255860	You can see the fix simply moves this physical to virtual mapping inside of the lock.
1255860	1257940	It's very simple fix.
1257940	1260600	It just protects this mapping.
1260800	1263480	So, that's the vulnerability.
1263480	1266560	Let's take a look at how to trigger this vulnerability.
1266700	1268520	We will need two threads.
1268520	1271660	One to the mapping, to the binding.
1271660	1274380	Binding a basic memory object to the VBO.
1274380	1278000	And at the same time, somebody else to the unbinding.
1278000	1279480	So, look at the code.
1279480	1283720	You can see when do the binding, we are getting into this add range.
1283720	1286200	This is the function we just read.
1286200	1287980	You can see we have the lock.
1287980	1293300	We will insert the basic memory object into the VBO.
1293300	1295840	Then we unlock and do the physical mapping.
1295980	1299160	And another thread to the unbinding.
1299360	1302760	You can see it's just the reverse of the binding.
1302760	1304200	You will have a lock.
1304200	1308920	And then you remove the binding.
1308920	1310640	And then you do the unlock.
1311320	1314380	So, here is how we trigger the vulnerability.
1314380	1315400	We have two threads.
1315400	1318300	Thread A running and lock.
1318300	1322320	And then onto the tree insert and do the unlock.
1323600	1327140	And at the same time, we can run thread B.
1327140	1330800	Because it's unlock, so the thread B can run in.
1330800	1334580	Then we get the lock removed and unlock.
1334580	1337000	And finally, we do the mapping.
1337040	1341520	So, here is the detailed vulnerability.
1341780	1345360	We run thread A. We acquire the mutex.
1345360	1346320	Then we connect.
1346320	1349100	You can see this connection is set up.
1349100	1354220	So, we connect the basic memory object to the VBO and release the lock.
1354220	1356380	Then we get to thread B.
1356380	1359040	Thread B also acquires the same mutex.
1359040	1364760	And you can see this connection between the basic memory object and the VBO is removed.
1364760	1367240	So, this is thread B.
1367240	1370260	Unbinding and release the mutex.
1370580	1373620	Then we get back to thread A.
1373620	1380040	The thread A will map the victim's physical page to this virtual address.
1380040	1390500	So, from the driver's perspective, the basic memory object already has no connection with the VBO.
1390500	1392060	So, it can be freed.
1392060	1396060	So, we can delete the basic memory object in the driver.
1396060	1401220	So, all the resources related with this basic memory object will be freed.
1401220	1403440	As well as the backend physical memory.
1403440	1406000	You can see this page has been freed.
1406000	1413020	By the connection here, the connection between the physical memory and the virtual address is still mapped.
1413040	1414460	So, it's still there.
1414460	1415740	That's the vulnerability.
1415780	1421080	So, we have run this code sequence and triggered the vulnerability.
1424160	1428240	It's a physical page used after free.
1428240	1432100	So, we can read and write to free the physical page.
1432100	1439200	You can read and write to this free the physical page from the GPU's virtual address.
1439320	1441940	And also, it's a worst condition issue.
1442240	1447720	We require the two threads to bind and unbind at the same time.
1448720	1453300	And here, let's summarize the exploit primitive.
1453300	1456140	We have a physical page used after free.
1456140	1458900	We return this physical virtual mapping.
1458900	1463140	So, we can access free the physical page.
1463140	1466120	And this vulnerability is pretty stable.
1466500	1476100	Usually, when we trigger used after free issue or worst condition issue, we have to trigger it multiple times.
1476100	1484680	So, it's very dangerous to trigger this issue because it will cause the system status, you know, wrong status, maybe crash the kernel.
1484680	1486740	But this issue is pretty stable.
1486740	1493640	You can trigger it multiple times without worrying about it fails or causing any crash.
1493640	1500080	And also, we have a method to get a feedback whether this issue is triggered or not.
1500080	1503030	If it's not triggered, we will get this feedback.
1503300	1510560	And if it's triggered, then we know the result so that we can know exactly how many pages we have controlled.
1510560	1513460	This will make our exploit more stable.
1513460	1515600	And this issue is pretty easy to trigger.
1516600	1524320	Without any special tricks, you don't have to adjust the thread priority or add more entries to the list.
1524320	1527400	You can easily trigger this issue.
1527400	1532480	So, this is a pretty nice exploit primitive.
1532680	1538660	So, so far, we have tricked the vulnerability.
1538660	1543280	We have controlled a lot of physical memory pages.
1543280	1547520	The question becomes the following question.
1547520	1551920	Suppose we already controlled a large amount of physical memory page.
1551920	1553300	What are we going to do?
1553300	1558120	There are lots of answers and solutions for an experienced kernel hacker.
1558120	1566520	For example, we can supply lots of this structure created into the kernel heap and then modify the UID and GID.
1566520	1572960	We can also supply lots of structure file and then modify the file permission.
1572960	1577660	And also, we can use this kernel-based memory mirroring attack.
1577660	1583520	So, we can modify and control the GPU page table and then do the mirroring.
1584060	1587140	Here, we will introduce our new method.
1587220	1593600	So, we are spraying structure KGS memory description.
1594280	1601220	So, you can see on the right, we are spraying this structure KGS memory entry.
1601220	1604640	It contains the target structure we want to spray.
1604640	1607180	It contains the memory description structure.
1607180	1609720	Also, it contains metadata.
1609940	1615480	And for this memory description, we can see it has a physical address and a size.
1615560	1618160	So, why are we using this method?
1618160	1620880	The first reason is that it is easy to spray.
1620880	1625220	You can simply call this GPU allocator control.
1625220	1629360	Then, you can spray a large amount of this structure in the kernel.
1629360	1635340	And also, because we have this metadata, this is fully controlled by the user space.
1635340	1642040	So, the user space can set a unique metadata so that you can find it easily in the memory.
1642440	1645620	And it's easy to use and very useful.
1645940	1653660	You can spray this structure and then modify the physical address and then do memory map in the user space.
1653660	1659460	When you do memory map, you will be able to map the physical address to user space.
1659460	1665660	And also, if you check the result of the memory map, then you know whether your exploit is working or not.
1665660	1670880	So, you can easily know how the exploit works.
1671240	1673460	And there's one extra bonus.
1673460	1677900	It's possible you use this method to bypass the KSR directly.
1677900	1683020	Even if you don't have a KSR, you can use this method to bypass the KSR.
1683020	1684980	We will discuss this later.
1685540	1691240	Now, suppose we already have a physical page controlled.
1691240	1693560	Like this, we control this physical page.
1693560	1700340	And in this page, we have our package structure, memory entry, which contains the metadata,
1700340	1707880	so that we can find this metadata and then we find this memory description structure.
1707880	1715180	In this structure, it will have a physical address and a size and ops.
1715180	1717420	We will modify these three fields.
1717420	1725420	We will modify the physical address of the kernel and the size to the kernel size.
1725420	1732040	And also, we will modify the ops from the KSR ops to this continuous ops.
1732800	1736940	While we modify these ops, look at the new ops.
1736940	1739060	You can see it has a VM folder.
1739060	1741040	This is used when we do...
1750860	1759560	We will modify these ops and get a new continuous ops, which contains a new VM folder.
1759560	1764780	So when the user space do memory mapping on this memory object,
1764780	1773040	it will get a user space virtual address, which the user space can access to the virtual address.
1773040	1776780	But at the first time, when the user space access to the address,
1777480	1780660	because the physical to virtual mapping is not set up yet,
1780660	1783600	so it will get into a VM folder.
1783600	1788380	So the driver will get into the VM folder to set up the physical to virtual mapping.
1788380	1792100	And look at the code. You can see this mapping is quite simple.
1792100	1795640	It just gets the physical address we just modified.
1795640	1802580	So it will use the physical address we want and then map this physical address to the user space.
1802580	1808100	So if we modify this physical address to the kernel physical address,
1808100	1811620	then the kernel memory will be mapped to the user space,
1811620	1815020	so we can do arbitrary read-write to the kernel memory.
1815020	1823060	So that's why we use this structure memory description and how the exploit works.
1823520	1826320	Let's summarize the exploitation.
1826320	1831520	So we trigger the vulnerability, and then we get a controlled physical page.
1831520	1838880	We repeat this step 200 times, then we get 200 physical pages controlled.
1838880	1845960	Then we can get to the next step. We can force the system memory into a low memory status.
1845960	1852380	So all the kernel memory, all the caches will be returned to the system,
1852380	1855320	including the physical pages that we controlled.
1855320	1860540	So the 200 pages will also be returned to the kernel.
1860940	1867300	Then we get to the next step. We do kernel heap spray using the structure we just described.
1867300	1874160	So if we are lucky, some of the entries will be located in the controller page.
1874160	1885220	So we can find these structures in the controller page using the metadata we just set.
1885220	1891740	So we can scan the controller memory and find the structure, and then we get this structure.
1891740	1895560	You can see on the right, we get the memory description structure,
1895560	1900220	which contains the physical address set and the ops we want to modify.
1900220	1905500	And here, one thing you can see, the ops is a pointer.
1905500	1909720	It's pointing to something in the kernel memory.
1909720	1915960	So if we read this ops out, then we can get the KSL information.
1915960	1920920	So in our exploit, we bypass the KSL at this step.
1920920	1925480	So we can bypass the KSL here, and then get to the next step.
1925480	1930640	We can modify the physical address, modify the size, modify the ops.
1930760	1936660	We will modify the physical address to the kernel physical address, and the size to the kernel size.
1936660	1941000	Then finally, we can map the whole kernel memory to the user space.
1941000	1945220	Then we can do arbitrary read-write to the kernel memory in the user space.
1945300	1947520	So that's the exploit.
1948440	1954140	We can actually expand this method to a more generic case.
1954140	1961980	Suppose you have a kernel heap buffer overflow, or you have a risk condition issue,
1961980	1967300	you can also use this method to make your exploit easier.
1967440	1974320	The first step, you can spray a large amount of this memory descript into the kernel heap,
1974320	1976500	and then you trigger your vulnerability.
1976500	1985280	Suppose you have a kernel heap overflow issue, you can overflow it from here into this ops.
1985280	1989760	Then you can control the physical address and ops.
1989760	1994580	And then you can try to do memory map on this memory object.
1995060	2002600	If you are lucky, you succeed, then you can map the whole kernel physical memory to the user space.
2002600	2007320	But if you are not lucky, you can try it again and again until you succeed.
2007380	2012320	So that's how we expand this method to a more generic case.
2012520	2019580	And maybe you remember we have a bonus, which we can bypass the case using this method.
2019580	2022800	So look at the structure carefully.
2022800	2031240	You may find that there are lots of kernel points, like the page table is a pointer and the host PTR.
2031240	2033320	And also we have the HTTP.
2033320	2038280	You might think, oh, we will need to get KSR information first.
2038280	2043560	We have to point this point to a digital address.
2043560	2048640	But in fact, you don't have to worry about this field, because in most of the cases,
2048640	2056000	if you don't call some special R control by yourself, these fields are not used in most of the cases.
2056000	2062560	So you can just overwrite these fields with a capital value or whatever you want.
2062560	2067720	You can just overwrite the page table, the host PTR, and the GPU address.
2067720	2069720	All this stuff is not used.
2070580	2076200	The only thing you care about is the physical address, the size, and the ops.
2076200	2079000	You might all think, oh, here we have the ops.
2079000	2080780	It's also a pointer.
2080780	2086880	So you have to know the original value, or you have to know the ASR information.
2086900	2091820	But actually, no, you don't have to know the KSR information.
2091820	2094180	You look at the original value carefully.
2094180	2100540	You can see this is the original value, and this is the target value we want to modify.
2101140	2105100	You can see that the high bytes are actually the same.
2105260	2106560	Why are they the same?
2106560	2110780	Because the KSR is based on the page.
2110780	2112080	It's page-based.
2112080	2120480	So if the two function points are in the same page, so they have the same high bytes that are in the same page.
2120480	2122800	So all these bytes are the same.
2122800	2129840	So you can actually ignore these bytes and overwrite from the beginning to the lowest byte, overwrite it to here.
2129840	2132920	Then you don't have to care about the KSR.
2132920	2135500	So that's how we bypass the KSR.
2135500	2141720	And one thing here, you can see the lowest byte is already known from the kernel firmware.
2141720	2145580	So you don't have to acquire additional information.
2145580	2149620	You can bypass the KSR and get the expert working.
2149620	2154760	You just overwrite to the lowest byte and ignore the high bytes.
2155620	2157960	Yeah, that's how we bypass KSR.
2157960	2161220	And in some cases, maybe you are not so lucky.
2161220	2164300	You get the following situation.
2164300	2169280	You can see it's not in the same page, but in the source code, they are near each other.
2169280	2175160	So in most of our case, the original value is near the target value.
2175160	2178160	So it's just like a 4-bit difference.
2178160	2181420	So for 4-bit, it's just a 16 possibility.
2181420	2183720	You can try 16 times.
2183720	2187140	So you can undo the brute force for 16 times.
2187140	2189080	Then you can bypass the KSR.
2189080	2193400	So that's how we bypass the KSR and that's the exploit.
2193400	2196720	Okay, we'll get to the demo.
2196960	2198620	The demo is online.
2198620	2201840	You can view the demo online.
2201840	2203620	Also, we'll play it here.
2203620	2206800	You can see here.
2206800	2211960	When we record this demo, we are recording it on a pretty famous smartphone
2211960	2218440	using the latest Qualcomm SoC, using Snapdragon generation 8
2218440	2221560	with the latest security patching.
2222660	2225220	We'll start with the share user.
2225220	2228160	Of course, you can also use the uncharged application user.
2228160	2229660	There's no difference.
2229720	2231960	So we are trying to get a load share.
2232360	2237020	Of course, we don't have a load privilege now, so this fails.
2237100	2239220	So we will start our exploit.
2239320	2241540	And the first step is to trigger the vulnerability
2241540	2246240	and control a large amount of physical pages.
2246400	2249080	So we trigger the vulnerability again and again.
2249080	2252660	And here we think we have enough pages.
2253300	2257180	So now you can see we have controlled enough physical pages.
2257180	2259120	Then we go to the next step.
2259120	2261680	We trigger a system no memory.
2261680	2265380	We allocate a lot of memory from the user space.
2265400	2270160	So all the cached memory or the system memory
2270160	2273560	unused system memory will be returned to the kernel.
2273660	2275980	So we can do heap spray.
2275980	2279740	We create a lot of these VBO entries.
2280020	2281800	And then we are lucky.
2281800	2286820	Some of the VBO entries will be located in the controller page.
2286820	2289460	So we scan the controller page.
2289460	2293920	And then we can find this controller object.
2293920	2298820	You can see we found one controlled memory description object.
2298820	2303520	So this object has a physical address, size, and ops we want.
2303520	2307660	So we can patch this structure.
2307800	2310580	The ops will modify the physical address.
2310580	2316440	You can see this A801 is actually the kernel physical address.
2316440	2318320	And the size is the kernel size.
2318320	2321700	So we have patched the structure.
2321700	2327220	And now we can map this structure to the user space.
2327220	2330700	So we can map the whole kernel memory to the user space.
2330700	2333280	And patch the kernel memory.
2333280	2335660	Here we have patched the kernel version.
2335740	2339300	And also we patched some of the code in the kernel.
2339300	2340840	So we can get a root.
2340840	2343900	So you can see now we are the root user.
2344200	2345560	So that's the demo.
2349500	2350880	Thank you.
2350880	2353680	I will transfer to Eugene for the next content.
2354760	2356320	Thank you very much, Shiling.
2356320	2361500	And with that, I will be speaking about the last section of this presentation.
2361500	2363200	How we found this vulnerability.
2363340	2368160	Which methodology is applicable when you are doing bug hunting for GPU kernel modules.
2368160	2375500	And what we can do to improve security of the GPU in the mobile space.
2375520	2380780	Well, first of all, we identified this vulnerability via manual code review when we were doing patch analysis.
2380780	2387300	And by patch analysis, essentially we use a collective term where we look at the security fixes.
2387540	2390700	Which are published in the Android Qualcomm security bulletin.
2390700	2394980	We also look at the security research published by other security researchers.
2395140	2398780	And this is very important for such complex cases and big targets such as GPU.
2399120	2400740	Because the state is very big.
2400740	2404580	And as Shiling explained earlier in this presentation, there is a lot of moving parts.
2404580	2418400	In order to have a holistic understanding, it's important to read others' blog reports to better understand the domain in this area.
2418400	2425660	Originally, we wanted to put on the slide a very cool chain of vulnerabilities which we did variant analysis for.
2425660	2429800	So, for example, Qualcomm internally identified one of the issues.
2429800	2432160	They published a fix in their security bulletin.
2432160	2435660	Then a security researcher looked at this fix.
2435940	2439080	They found another related issue in this area.
2439080	2442200	They wrote a blog post and published it.
2442200	2451340	While looking at these two fixes by Qualcomm and the security researcher, we managed to identify another problem in the related area.
2451340	2462180	But later we decided to remove this information because the issue might still be under remediation and not to tip off the folks working on the other side of the fence.
2462220	2468300	We decided to put this quote here, which I think reflects the idea which we would like to convey in the slide.
2470260	2473800	While speaking about methodologies, we cannot skip fuzzing.
2473800	2476980	Because fuzzing is one of the essential methodologies we use.
2476980	2484420	This is one of the most efficient and productive ways of finding bugs in the modern complicated software and the firmware.
2484540	2489720	And there is a lot of benefits, I think, quite obvious for fuzzing.
2489720	2495800	So on this slide, particularly, we will focus on challenges applicable to fuzzing GPU targets.
2497880	2503700	And think about how can we overcome those or how can we solve them.
2503700	2513780	So first of all, to enable efficient fuzzing of the GPU drivers, there is a lot of dependence on the hardware.
2513780	2518620	As we have seen, this particular vulnerability is in the misconfiguration of the IOMMU.
2518620	2523580	So in order to theoretically find this vulnerability, we would need to do on-device fuzzing.
2523580	2528220	And although this is possible, this makes fuzzing a little bit less scalable.
2528220	2535680	Because we would actually need to run it on the hardware versus, let's say, pure software fuzzing, which can scale with the number of the fuzzing cores.
2535900	2541700	This is not a limitation, but this is one of the interesting observations.
2541700	2549540	Because I know that there are some other GPU vendors which enable building their kernel-mode components in the architecture-independent way.
2549540	2559980	So basically, there is a separation between software and hardware logic, so it's possible to build driver and run it without the hardware.
2559980	2565320	To be able to test and fuzz the generic functionality implemented in the software.
2565420	2569740	And another approach is using the emulation-based fuzzing to have an emulator for that.
2569740	2576960	But I guess this is a little bit more complicated approach, because this requires manual work in order to understand how the hardware actually works.
2576960	2583220	In order to be able to emulate it in the emulator.
2583700	2589160	This particular issue was identified in the MMU and IUMMU domain.
2589160	2593980	And this is actually a very common pattern in the GPU bugs reported these days.
2593980	2598880	Where the physical pages for the backend storage are released back to the kernel.
2598920	2609040	While at the same time there is a mapping in the IUMMU for the GPU which maps these released pages back to the virtual address space of the GPU.
2609060	2612700	And this is very difficult to detect with fuzzing, because this doesn't lead to any crash.
2612700	2625700	Even if we are lucky enough to hit the race condition here, still there is no sanitizers which would report us that, hey, you have dangling MMU entries in the page tables.
2625720	2632080	This is one thing. Probably manual instrumentation of the driver with such checks would help.
2632240	2635220	But again, this is manual work which makes it less scalable.
2635400	2637820	GPU has a very complicated state machine.
2637820	2649600	As we've seen, there is multiple components and sometimes in order to hit certain functions we would need to have a set of syscalls executed in a very precise sequence.
2649600	2656020	Or if we're speaking about fuzzing with syscaller, probably this is additional custom syscalls which needs to be written for that.
2656020	2662200	And of course, fuzzing concurrent code is not straightforward.
2663340	2669780	Because there are some problems with reproducing and problems with hitting those vulnerabilities.
2672320	2676420	Probably the final slide before we wrap it up, the ultimate mitigations question mark.
2676420	2683060	Why question mark? Because, well, I guess suggesting mitigations for GPU is really not straightforward.
2683060	2691460	And this is more about thinking employees about how can we make GPU security better in the mobile space.
2691460	2698500	First of all, one of the major points why GPU is so attractive is because it is widely accessible to untrusted code.
2698740	2704180	Because the untrusted code can directly open the driver and send arbitrary data to it.
2704340	2710240	Android is very known for using IPC and binder in order to isolate components.
2710240	2715560	So maybe one of the ideas is to move GPU from in-process hull into the out-of-process hull.
2715560	2720280	I know this will impact performance and performance is very important for GPU.
2720280	2724320	This might create some backward compatibility issues, but this is one of the ideas to think about.
2724360	2732200	And additionally, the usage of memory-safe languages in the driver, I think, based on our experience,
2732200	2738500	they might mitigate the majority of root causes, which lead to problems such as integer overflows,
2738500	2742900	or in this particular case, integer race conditions.
2743820	2747380	And I think with that, we hit almost the end of our time.
2747380	2750140	And last slide, thank you very much for your attention.
2750160	2752720	A small, shameless marketing plug.
2752720	2758760	Here we have our Android offset with Google.com, where we publish our security research.
2759220	2765420	And with that, yeah, I think we're happy to take any questions here on stage or offline
2765420	2768780	using this contact information here.
2768780	2769780	Thank you very much.
