WEBVTT

00:00.060 --> 00:04.580
Okay, sorry for that.

00:05.060 --> 00:07.040
Good afternoon, everyone.

00:07.180 --> 00:08.640
My name is Xuexin.

00:08.640 --> 00:11.200
I'm the manager of Android Red team.

00:11.400 --> 00:23.640
Today I'm really honored to present you the way to Android root exploiting your GPU on smartphone with these two gentlemen.

00:25.700 --> 00:29.040
This is Xilin Gong, our security researcher.

00:29.040 --> 00:35.180
And he actually did most of the work, technical work, so big credit to him.

00:35.480 --> 00:39.000
And also next to Xilin is our tech lead, Eugene Rodionov.

00:39.100 --> 00:44.280
Eugene did a lot of work to help us create the slides and making sure the demo runs smoothly.

00:44.680 --> 00:45.980
Big shout out to him.

00:47.720 --> 00:55.600
So our story dated back to the earliest year when Xilin decided to take a look at Qualcomm GPU drivers.

00:58.040 --> 01:02.840
But before we go into details, here's a brief introduction of our team.

01:02.840 --> 01:05.580
So we are the Android Red team.

01:05.740 --> 01:09.820
Our goal is to increase the Android and pixel security.

01:09.820 --> 01:16.980
And we do this by simulating adversaries attacking Android key features.

01:17.060 --> 01:21.560
And our work can be broken down into a couple of different ways.

01:21.580 --> 01:31.300
Most obviously, we do offensive security research review to verify our breaking security assumptions, which means finding bugs.

01:31.500 --> 01:39.440
And we scale our work by developing tools such as continuous fuzzing or static analysis.

01:40.160 --> 01:52.220
And once we find issues, we develop proof of concept just to show the real world impact as some issues are not so straightforward to see their impact.

01:52.880 --> 02:02.200
Lastly, while we're developing the exploits, we're also assessing the efficacy of the security mitigations that our feature team implemented.

02:03.860 --> 02:11.320
The more pain we experience during our work, the more security our end user will gain.

02:11.320 --> 02:16.980
So we are literally making our work harder to help end users.

02:19.170 --> 02:21.170
So here's today's agenda.

02:21.170 --> 02:24.990
We'll first talk about the GPU and security background.

02:25.470 --> 02:33.770
And then we'll go through the Qualcomm Adrena GPU introduction, talking about its architecture and where the issue patterns are.

02:33.770 --> 02:43.670
And then we'll dive into a very technical details for the CVE-2024-23380 and how we exploit to gain root privilege.

02:44.110 --> 02:48.750
Lastly, we'll conclude our talk with the methodology discussions.

02:51.820 --> 03:00.260
So before we jump into engagement, usually we need to ask ourselves questions.

03:00.260 --> 03:02.520
Why do we look into this one?

03:05.580 --> 03:08.500
The answer is because our team is very small.

03:08.520 --> 03:12.740
So we want to spend our time into the most impactful areas.

03:13.740 --> 03:15.520
So why GPU drivers?

03:15.880 --> 03:18.860
Here we think these are the answers to that question.

03:18.860 --> 03:26.200
The biggest one is there is no permission required for applications to look into GPU driver.

03:27.260 --> 03:30.020
On the right side you can see a diagram.

03:30.260 --> 03:43.760
And the unprivileged applications, whatever user space library they call, OpenGL, Vulkan, anything else, those libraries talk into the device node directly in the applications process.

03:43.760 --> 03:48.240
So that means this device driver has to be exposed to the application.

03:48.340 --> 03:50.700
So no permission required.

03:50.700 --> 03:53.220
This is the biggest problem.

03:53.220 --> 03:56.460
And this is why researchers love GPU drivers.

03:57.220 --> 03:58.940
Next one.

03:59.300 --> 04:02.960
GPU driver performance is the key.

04:02.960 --> 04:07.760
And because of that, they need to have some powerful functions to do this.

04:07.980 --> 04:21.420
The most important one is that they usually have access to the system physical RAMs so that they can map memories from user space to kernel space and to the hardware without copying them.

04:21.520 --> 04:25.440
This is a very powerful primitive and attackers want that.

04:26.400 --> 04:29.860
We'll explain more later why it's powerful.

04:29.940 --> 04:38.160
And lastly, again, because of the performance requirement, this involves high complexity code in the GPU driver.

04:39.020 --> 04:44.300
And because of that, it's really, really hard to develop bug-free code.

04:44.300 --> 04:46.840
I'm not sure if anybody here writes bug-free code.

04:46.840 --> 04:48.500
Raise your hand if you did.

04:48.620 --> 04:50.560
Wow, very brave.

04:51.760 --> 04:55.360
Anyway, and it's even harder to fix an issue.

04:55.360 --> 05:00.740
And it's very common that you fix an issue, but it's not 100% fixed.

05:00.740 --> 05:02.880
There's still something left over.

05:02.880 --> 05:08.040
And even worse, you fix one issue, you introduce another new issue.

05:08.040 --> 05:09.360
Or two issues.

05:10.940 --> 05:15.840
So this high complexity is another reason one look into this area.

05:20.880 --> 05:23.320
Hello?

05:24.140 --> 05:26.240
Hello?

05:26.680 --> 05:27.900
Sorry.

05:27.900 --> 05:30.120
That's not your problem.

05:37.450 --> 05:42.380
Hello?

05:45.860 --> 05:47.440
Hello?

05:47.440 --> 05:49.480
I can use this one.

05:54.590 --> 05:57.970
Okay, we have issues, so we fix them.

05:59.850 --> 06:01.950
So, why Qualcomm?

06:01.950 --> 06:06.290
Qualcomm is one of the most important smartphone SoC vendors.

06:06.630 --> 06:09.890
And many devices use Qualcomm SoCs.

06:09.890 --> 06:14.170
And on those SoCs, Arduino GPU is the one used the most.

06:14.510 --> 06:24.010
And last one is, this applies to all GPUs, that GPU is a very actively developing area.

06:24.010 --> 06:31.450
Because of all the requirements, all the games keep having high resolutions, faster speed, faster FPS.

06:31.510 --> 06:37.750
So there's lots of development happening that involves revolutions in architecture.

06:37.750 --> 06:39.570
Hardware, software.

06:39.670 --> 06:46.970
And coincidentally, we noticed that there is a new architecture recently in the Qualcomm GPU.

06:46.970 --> 06:50.990
New architecture, new software means new bugs.

06:50.990 --> 06:56.370
So we want to take a look and see what's the difference and is there any issues there.

06:59.340 --> 07:13.620
And another study we did before we look into our source code, I mean, our Qualcomm source code, is to check the security bulletins and is there any historical issues.

07:13.980 --> 07:18.760
And here's a chart that we manually created from the Qualcomm security bulletin.

07:19.380 --> 07:25.600
The size of the bars might look a little bit scary, but you can see the numbers actually are single digits.

07:25.600 --> 07:36.260
So there's not a lot of issues, but my point here is that you can see this is more like constant issues happening every quarter.

07:36.420 --> 07:44.940
So this chart gives us a little bit of confidence that if we look into the code, we might as well find issues.

07:45.580 --> 07:52.240
Oh, by the way, I forgot to mention, all our work is based on open source Qualcomm drivers, so everything is public.

07:52.240 --> 07:54.700
There's no private information involved.

07:56.040 --> 08:03.900
Among all those issues, there are quite some high profile issues disclosed and talked by previous security researchers.

08:04.120 --> 08:09.000
These talks are great, and we learn a lot from the talks.

08:09.000 --> 08:14.600
Really big credit to them for helping us to jump into an area we've never looked at before.

08:16.740 --> 08:20.800
And now we look back into just the recent three months.

08:20.800 --> 08:26.840
Here are all the issues reported to Qualcomm security, disclosed by Qualcomm security bulletin.

08:27.740 --> 08:35.700
Our security researcher, Xilin, did a little bit of analysis and focused on the last two columns.

08:35.700 --> 08:41.800
You can see the tech area, mostly many of the issues are focusing on IOMMUs.

08:41.800 --> 08:47.060
That matches our previous assumption that physical memory is the key.

08:47.260 --> 08:55.980
And also, very subjective, but based on Xilin's experience, most of the issues are easy to exploit.

08:55.980 --> 09:00.300
And once exploited, they are pretty stable.

09:00.300 --> 09:02.160
Attackers want the stability.

09:02.160 --> 09:04.740
They want their code to be good.

09:06.460 --> 09:12.200
Over the course of our engagement, Xilin has identified more than nine issues.

09:12.860 --> 09:15.980
We report all the issues to Qualcomm immediately.

09:16.460 --> 09:20.680
And today we're going to talk about CVE-2024-23380.

09:20.680 --> 09:22.780
This is one of the issues we reported.

09:23.060 --> 09:28.780
This issue has been patched and published in the security bulletin of July 2024.

09:29.260 --> 09:35.320
And Qualcomm communicated to all the device vendors in April before the disclosure.

09:35.440 --> 09:38.620
So, go to the security bulletins.

09:38.620 --> 09:40.640
You can see what's affecting devices.

09:40.740 --> 09:45.180
But don't worry if your device is affected and check your security patch level.

09:45.180 --> 09:47.480
If it's July or later, it's fixed.

09:48.840 --> 09:56.400
And from here, I'll hand over to Xilin to talk about technical details and how we exploit to gain root privilege.

10:01.560 --> 10:03.520
Yeah, thank you, Xilin.

10:03.940 --> 10:13.280
So, I'll quickly introduce the basic knowledge of Andrino GPU.

10:13.320 --> 10:15.960
So, here is the basic architecture.

10:16.160 --> 10:24.620
You can see in the middle is the KGSL driver, which is the glue between the user space and the hardware.

10:24.620 --> 10:31.280
So, from the perspective of the user space, we will have a set of interfaces.

10:31.280 --> 10:42.960
The first one is the context, which is used to identify user space applications and also to manage the GPU driver or hardware resources.

10:43.000 --> 10:48.020
And also, the user space may want to share memory with the GPU hardware.

10:48.020 --> 10:50.300
So, we will have memory interfaces.

10:50.420 --> 10:52.380
There are three types of memory.

10:52.380 --> 10:56.320
The basic memory, the user space memory, the DMA memory.

10:56.320 --> 10:59.400
And previously, we also have the sparse memory.

10:59.400 --> 11:03.920
But now, this sparse memory is already not used anymore.

11:04.120 --> 11:09.900
And the user space also wants to send the customer GPU commands to the GPU hardware.

11:09.900 --> 11:13.320
So, we will have some command interfaces.

11:13.320 --> 11:18.420
And also, the user space wants to get synced with the GPU hardware.

11:18.420 --> 11:21.480
So, we will have synchronization interfaces.

11:21.480 --> 11:31.320
To accomplish these tasks in the GPU driver, we will have a command queue, which receives commands from the user space.

11:31.320 --> 11:44.380
And then, the software dispatcher will get the command from the queue and add the necessary information and maybe modify the GPU command and then send them to the RAM buffer.

11:44.860 --> 11:53.460
There is a simple firmware in the GPU hardware, which will receive commands from the RAM buffer and send the command to the hardware.

11:53.460 --> 11:57.960
So, GPU customer commands will be run in the GPU hardware.

11:57.960 --> 12:05.900
Also, we will have something like the global buffer, the registers to control the GPU hardware.

12:05.900 --> 12:16.920
For memory management, we will have memory pool and MMU for the user space memory and IOMMU for controlling the GPU memory.

12:16.920 --> 12:25.600
So, this is the new architecture starting from generation 7 and the later generation.

12:25.600 --> 12:30.420
You can see we have a lot of new stuff in red color.

12:30.420 --> 12:41.380
The most important change is the software dispatcher is replaced by the hardware scheduler, which means the GPU command comes from the user space.

12:41.380 --> 12:44.960
It will not be sent to the RAM buffer directly by the driver.

12:44.960 --> 12:48.400
The driver will not touch the RAM buffer anymore.

12:48.400 --> 12:54.960
Instead, the driver will send this command directly to a HiFi command queue.

12:54.960 --> 13:05.480
So, there is a simple firmware and this firmware will take over and finish the job previously finished by the driver.

13:05.480 --> 13:11.240
So, a lot of software dispatcher jobs will be moved to the firmware.

13:11.240 --> 13:13.680
So, we don't have the source code of the firmware.

13:13.680 --> 13:21.860
So, I can just guess that this job previously finished by the software dispatcher will move to the firmware.

13:21.860 --> 13:28.520
But how it works and whether there are any vulnerabilities, I have no idea now.

13:28.520 --> 13:37.140
And also, to coordinate with these new features, some other new features like the hardware fence is added.

13:37.140 --> 13:39.760
Previously, we only had the software fence.

13:39.760 --> 13:52.400
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.

13:52.400 --> 13:58.100
For the memory, we will have a new virtual buffer object.

13:58.100 --> 14:00.700
You can see here, this is a new VBO.

14:00.760 --> 14:06.540
And the previously ARM IOMMU will be replaced by the Qualcomm-owned IOMMU.

14:06.540 --> 14:18.040
So, these new features will, of course, enhance the GPU capability, but also will introduce a lot of new attack surfaces.

14:19.680 --> 14:27.100
If you want to look into some new vulnerability, you can start from the new features.

14:27.640 --> 14:30.640
Here, I'll also introduce the memory management.

14:30.720 --> 14:36.040
You can see here is the basic memory management called a basic memory object.

14:36.080 --> 14:44.920
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.

14:44.920 --> 14:48.240
It's a basic, so it's used in most of the cases.

14:48.240 --> 14:55.060
You call this our control, and you set a parameter to tell the driver how many physical pages you want.

14:55.060 --> 14:59.500
Then, the driver will allocate this number of physical pages for you.

14:59.540 --> 15:06.600
And then, the second step, the driver will allocate an address range in the GPU virtual address space.

15:06.600 --> 15:10.920
So, you can see here, we have this virtual GPU address.

15:11.120 --> 15:17.100
And then, the GPU driver will set this physical to virtual mapping for you.

15:17.100 --> 15:25.360
So, at this time, the GPU hardware will be able to access to the physical page using this GPU virtual address.

15:25.960 --> 15:31.700
And in most of the cases, the user space will also want to access to the physical page.

15:31.700 --> 15:37.140
So, the user space will do memory map on this basic memory object.

15:37.140 --> 15:45.620
And then, the driver will help you to set up the physical page to virtual mapping through the MMU.

15:45.620 --> 15:53.620
So, at this time, the physical page can be accessed from both the GPU hardware and the user space.

15:53.620 --> 15:55.560
So, that's the basic memory object.

15:55.560 --> 16:02.380
The driver will manage all the objects in the kernel and also manage the backend physical memory.

16:02.860 --> 16:05.740
And here is the second type of memory object.

16:05.740 --> 16:07.920
It's called the user space memory.

16:07.920 --> 16:21.120
So, suppose you already have a user space memory, you have a backend physical memory, you can use this user space memory object to import memory from the user space into the GPU hardware.

16:21.120 --> 16:24.560
And here is the third type of memory.

16:24.560 --> 16:26.520
It's called the virtual buffer object.

16:26.540 --> 16:32.120
From the name virtual, you may guess that it's virtual.

16:32.400 --> 16:39.220
So, for this type of memory, it doesn't have its own backend physical memory.

16:39.220 --> 16:42.380
So, you call this out control with this flag.

16:42.380 --> 16:48.020
Then, the driver will simply allocate a GPU virtual address for you.

16:48.020 --> 16:53.260
And then, it will map this virtual address to a dummy ZeroPage.

16:53.260 --> 16:55.160
So, it's a dummy ZeroPage.

16:55.160 --> 16:56.940
It's just a placeholder.

16:57.640 --> 17:03.880
Of course, you can access it to the virtual memory in the GPU hardware, but it's no effect.

17:03.880 --> 17:06.820
Whatever you read or write will have no effect.

17:06.820 --> 17:08.740
It's just a ZeroPage.

17:08.740 --> 17:10.080
It will have no effect.

17:10.080 --> 17:13.340
So, how to use this virtual buffer object?

17:13.340 --> 17:19.580
You can actually map a basic memory object into this VBO.

17:19.580 --> 17:24.620
So, suppose you already have two basic memory objects, A and B.

17:24.620 --> 17:28.360
Both of them have their own backend physical memory.

17:28.360 --> 17:32.640
You can bind these two basic memory objects into this VBO.

17:32.640 --> 17:35.240
So, you call this bindRangeOutControl.

17:35.240 --> 17:37.660
Then, the driver will do the work.

17:37.660 --> 17:42.540
The first step, the driver will remove any existing mapping from the VBO.

17:42.540 --> 17:46.200
Here, we already mapped the ZeroPage to the VBO.

17:46.200 --> 17:48.340
So, this mapping will be removed.

17:48.340 --> 17:57.200
If you have previously mapped any other basic memory object to this VBO, these maps will also be removed.

17:57.620 --> 18:02.840
So, the first step, we will remove any existing mapping from the VBO.

18:02.960 --> 18:09.960
And then, we will get a connection between this basic memory object and the VBO.

18:09.960 --> 18:13.340
So, the driver will know that there is a connection.

18:13.340 --> 18:16.360
Somebody is using this basic memory object.

18:16.360 --> 18:18.840
So, this object cannot be freed.

18:19.200 --> 18:25.200
And also, the driver will help you to find out the physical memory page of this basic memory object.

18:25.260 --> 18:29.680
And then, the driver will help you to set up this connection.

18:30.320 --> 18:33.900
So, you can see here is the physical memory to virtual mapping.

18:33.900 --> 18:40.980
We will map this physical page into the VBO's region at a specified offset.

18:41.420 --> 18:46.140
And also, the driver will continue these two steps.

18:46.140 --> 18:49.900
Find all the basic memory objects you want.

18:49.900 --> 18:54.580
And get all the connections between the basic memory object and the VBO.

18:54.580 --> 18:59.140
And then, map all the physical pages to this VBO.

18:59.140 --> 19:01.540
So, that's the basic memory object.

19:02.420 --> 19:04.420
Binding to the VBO.

19:04.420 --> 19:08.800
It's very powerful and flexible.

19:08.800 --> 19:11.480
But also, very vulnerable.

19:11.480 --> 19:16.960
You can see here we have this CVE-2024-23380.

19:16.960 --> 19:22.640
Which happens when you bind a basic memory object into a VBO.

19:22.640 --> 19:24.920
So, we will take a look at the code.

19:24.920 --> 19:32.520
You can see when we do the binding, we will get a connection between this basic memory object and the VBO.

19:32.520 --> 19:37.220
So, the connection is finished by this function, intervalTreeInsert.

19:37.220 --> 19:41.240
So, insert this basic memory object into the VBO.

19:42.200 --> 19:48.440
Then, we will get a physical page and virtual address mapping.

19:48.440 --> 19:52.120
We will set up this mapping using this function.

19:53.560 --> 19:54.680
MMUMapChild.

19:55.620 --> 20:00.900
So, of course, we will have to protect our global status.

20:00.980 --> 20:05.920
So, we will use this mutex lock to protect the intervalTree.

20:05.920 --> 20:09.400
So, this intervalTree is a global status.

20:09.520 --> 20:12.080
This will be protected by the lock.

20:12.080 --> 20:14.520
And when we finish, we will do unlock.

20:14.660 --> 20:17.240
And here, the vulnerabilities.

20:17.580 --> 20:21.440
This physical to virtual mapping is also a global resource.

20:21.440 --> 20:24.340
So, it should also be protected by the lock.

20:24.340 --> 20:28.880
But you can see here, this physical to virtual mapping is outside of the lock.

20:29.020 --> 20:33.300
So, it's possible from the driver's perspective.

20:33.400 --> 20:38.680
We already have this basic memory object connected to the VBO.

20:38.800 --> 20:44.860
When we do the physical to virtual mapping, this connection might be removed by somebody else.

20:44.860 --> 20:46.580
So, that's the vulnerability.

20:47.620 --> 20:49.540
Let's take a look at the fix.

20:49.540 --> 20:55.860
You can see the fix simply moves this physical to virtual mapping inside of the lock.

20:55.860 --> 20:57.940
It's very simple fix.

20:57.940 --> 21:00.600
It just protects this mapping.

21:00.800 --> 21:03.480
So, that's the vulnerability.

21:03.480 --> 21:06.560
Let's take a look at how to trigger this vulnerability.

21:06.700 --> 21:08.520
We will need two threads.

21:08.520 --> 21:11.660
One to the mapping, to the binding.

21:11.660 --> 21:14.380
Binding a basic memory object to the VBO.

21:14.380 --> 21:18.000
And at the same time, somebody else to the unbinding.

21:18.000 --> 21:19.480
So, look at the code.

21:19.480 --> 21:23.720
You can see when do the binding, we are getting into this add range.

21:23.720 --> 21:26.200
This is the function we just read.

21:26.200 --> 21:27.980
You can see we have the lock.

21:27.980 --> 21:33.300
We will insert the basic memory object into the VBO.

21:33.300 --> 21:35.840
Then we unlock and do the physical mapping.

21:35.980 --> 21:39.160
And another thread to the unbinding.

21:39.360 --> 21:42.760
You can see it's just the reverse of the binding.

21:42.760 --> 21:44.200
You will have a lock.

21:44.200 --> 21:48.920
And then you remove the binding.

21:48.920 --> 21:50.640
And then you do the unlock.

21:51.320 --> 21:54.380
So, here is how we trigger the vulnerability.

21:54.380 --> 21:55.400
We have two threads.

21:55.400 --> 21:58.300
Thread A running and lock.

21:58.300 --> 22:02.320
And then onto the tree insert and do the unlock.

22:03.600 --> 22:07.140
And at the same time, we can run thread B.

22:07.140 --> 22:10.800
Because it's unlock, so the thread B can run in.

22:10.800 --> 22:14.580
Then we get the lock removed and unlock.

22:14.580 --> 22:17.000
And finally, we do the mapping.

22:17.040 --> 22:21.520
So, here is the detailed vulnerability.

22:21.780 --> 22:23.400
We run thread A.

22:23.400 --> 22:25.360
We acquire the mutex.

22:25.360 --> 22:26.320
Then we connect.

22:26.320 --> 22:29.100
You can see this connection is set up.

22:29.100 --> 22:34.220
So, we connect the basic memory object to the VBO and release the lock.

22:34.220 --> 22:36.380
Then we get to thread B.

22:36.380 --> 22:39.040
Thread B also acquires the same mutex.

22:39.040 --> 22:44.760
And you can see this connection between the basic memory object and the VBO is removed.

22:44.760 --> 22:47.240
So, this is thread B.

22:47.240 --> 22:50.260
Unbinding and release the mutex.

22:50.580 --> 22:53.620
Then we get back to thread A.

22:53.620 --> 23:00.040
The thread A will map the victim's physical page to this virtual address.

23:00.040 --> 23:10.500
So, from the driver's perspective, the basic memory object already has no connection with the VBO.

23:10.500 --> 23:12.060
So, it can be freed.

23:12.060 --> 23:16.060
So, we can delete the basic memory object in the driver.

23:16.060 --> 23:21.220
So, all the resources related with this basic memory object will be freed.

23:21.220 --> 23:23.440
As well as the backend physical memory.

23:23.440 --> 23:26.000
You can see this page has been freed.

23:26.000 --> 23:33.020
By the connection here, the connection between the physical memory and the virtual address is still mapped.

23:33.040 --> 23:34.460
So, it's still there.

23:34.460 --> 23:35.740
That's the vulnerability.

23:35.780 --> 23:41.080
So, we have run this code sequence and triggered the vulnerability.

23:44.160 --> 23:48.240
It's a physical page used after free.

23:48.240 --> 23:52.100
So, we can read and write to free the physical page.

23:52.100 --> 23:59.200
You can read and write to this free the physical page from the GPU's virtual address.

23:59.320 --> 24:01.940
And also, it's a worst condition issue.

24:02.240 --> 24:07.720
We require the two threads to bind and unbind at the same time.

24:08.720 --> 24:13.300
And here, let's summarize the exploit primitive.

24:13.300 --> 24:16.140
We have a physical page used after free.

24:16.140 --> 24:18.900
We return this physical virtual mapping.

24:18.900 --> 24:23.140
So, we can access free the physical page.

24:23.140 --> 24:26.120
And this vulnerability is pretty stable.

24:26.500 --> 24:36.100
Usually, when we trigger used after free issue or worst condition issue, we have to trigger it multiple times.

24:36.100 --> 24:44.680
So, it's very dangerous to trigger this issue because it will cause the system status, you know, wrong status, maybe crash the kernel.

24:44.680 --> 24:46.740
But this issue is pretty stable.

24:46.740 --> 24:53.640
You can trigger it multiple times without worrying about it fails or causing any crash.

24:53.640 --> 25:00.080
And also, we have a method to get a feedback whether this issue is triggered or not.

25:00.080 --> 25:03.030
If it's not triggered, we will get this feedback.

25:03.300 --> 25:10.560
And if it's triggered, then we know the result so that we can know exactly how many pages we have controlled.

25:10.560 --> 25:13.460
This will make our exploit more stable.

25:13.460 --> 25:15.600
And this issue is pretty easy to trigger.

25:16.600 --> 25:24.320
Without any special tricks, you don't have to adjust the thread priority or add more entries to the list.

25:24.320 --> 25:27.400
You can easily trigger this issue.

25:27.400 --> 25:32.480
So , this is a pretty nice exploit primitive.

25:32.680 --> 25:38.660
So, so far, we have tricked the vulnerability.

25:38.660 --> 25:43.280
We have controlled a lot of physical memory pages.

25:43.280 --> 25:47.520
The question becomes the following question.

25:47.520 --> 25:51.920
Suppose we already controlled a large amount of physical memory page.

25:51.920 --> 25:53.300
What are we going to do?

25:53.300 --> 25:58.120
There are lots of answers and solutions for an experienced kernel hacker.

25:58.120 --> 26:06.520
For example, we can supply lots of this structure created into the kernel heap and then modify the UID and GID.

26:06.520 --> 26:12.960
We can also supply lots of structure file and then modify the file permission.

26:12.960 --> 26:17.660
And also, we can use this kernel-based memory mirroring attack.

26:17.660 --> 26:23.520
So, we can modify and control the GPU page table and then do the mirroring.

26:24.060 --> 26:27.140
Here, we will introduce our new method.

26:27.220 --> 26:33.600
So, we are spraying structure KGS memory description.

26:34.280 --> 26:41.220
So, you can see on the right, we are spraying this structure KGS memory entry.

26:41.220 --> 26:44.640
It contains the target structure we want to spray.

26:44.640 --> 26:47.180
It contains the memory description structure.

26:47.180 --> 26:49.720
Also, it contains metadata.

26:49.940 --> 26:55.480
And for this memory description, we can see it has a physical address and a size.

26:55.560 --> 26:58.160
So, why are we using this method?

26:58.160 --> 27:00.880
The first reason is that it is easy to spray.

27:00.880 --> 27:05.220
You can simply call this GPU allocator control.

27:05.220 --> 27:09.360
Then, you can spray a large amount of this structure in the kernel.

27:09.360 --> 27:15.340
And also, because we have this metadata, this is fully controlled by the user space.

27:15.340 --> 27:22.040
So, the user space can set a unique metadata so that you can find it easily in the memory.

27:22.440 --> 27:25.620
And it's easy to use and very useful.

27:25.940 --> 27:33.660
You can spray this structure and then modify the physical address and then do memory map in the user space.

27:33.660 --> 27:39.460
When you do memory map, you will be able to map the physical address to user space.

27:39.460 --> 27:45.660
And also, if you check the result of the memory map, then you know whether your exploit is working or not.

27:45.660 --> 27:50.880
So, you can easily know how the exploit works.

27:51.240 --> 27:53.460
And there's one extra bonus.

27:53.460 --> 27:57.900
It's possible you use this method to bypass the KSR directly.

27:57.900 --> 28:03.020
Even if you don't have a KSR, you can use this method to bypass the KSR.

28:03.020 --> 28:04.980
We will discuss this later.

28:05.540 --> 28:11.240
Now, suppose we already have a physical page controlled.

28:11.240 --> 28:13.560
Like this, we control this physical page.

28:13.560 --> 28:27.880
And in this page, we have our package structure, memory entry, which contains the metadata, so that we can find this metadata and then we find this memory description structure.

28:27.880 --> 28:35.180
In this structure, it will have a physical address and a size and ops.

28:35.180 --> 28:37.420
We will modify these three fields.

28:37.420 --> 28:45.420
We will modify the physical address of the kernel and the size to the kernel size.

28:45.420 --> 28:52.040
And also, we will modify the ops from the KSR ops to this continuous ops.

28:52.800 --> 28:56.940
While we modify these ops, look at the new ops.

28:56.940 --> 28:59.060
You can see it has a VM folder.

28:59.060 --> 29:01.040
This is used when we do...

29:10.860 --> 29:19.560
We will modify these ops and get a new continuous ops, which contains a new VM folder.

29:19.560 --> 29:33.040
So when the user space do memory mapping on this memory object, it will get a user space virtual address, which the user space can access to the virtual address.

29:33.040 --> 29:43.600
But at the first time, when the user space access to the address, because the physical to virtual mapping is not set up yet, so it will get into a VM folder.

29:43.600 --> 29:48.380
So the driver will get into the VM folder to set up the physical to virtual mapping.

29:48.380 --> 29:49.680
And look at the code.

29:49.680 --> 29:52.100
You can see this mapping is quite simple.

29:52.100 --> 29:55.640
It just gets the physical address we just modified.

29:55.640 --> 30:02.580
So it will use the physical address we want and then map this physical address to the user space.

30:02.580 --> 30:15.020
So if we modify this physical address to the kernel physical address, then the kernel memory will be mapped to the user space, so we can do arbitrary read-write to the kernel memory.

30:15.020 --> 30:23.060
So that's why we use this structure memory description and how the exploit works.

30:23.520 --> 30:26.320
Let's summarize the exploitation.

30:26.320 --> 30:31.520
So we trigger the vulnerability, and then we get a controlled physical page.

30:31.520 --> 30:38.880
We repeat this step 200 times, then we get 200 physical pages controlled.

30:38.880 --> 30:41.660
Then we can get to the next step.

30:41.660 --> 30:45.960
We can force the system memory into a low memory status.

30:45.960 --> 30:55.320
So all the kernel memory, all the caches will be returned to the system, including the physical pages that we controlled.

30:55.320 --> 31:00.540
So the 200 pages will also be returned to the kernel.

31:00.940 --> 31:02.740
Then we get to the next step.

31:02.740 --> 31:07.300
We do kernel heap spray using the structure we just described.

31:07.300 --> 31:14.160
So if we are lucky, some of the entries will be located in the controller page.

31:14.160 --> 31:25.220
So we can find these structures in the controller page using the metadata we just set.

31:25.220 --> 31:31.740
So we can scan the controller memory and find the structure, and then we get this structure.

31:31.740 --> 31:40.220
You can see on the right, we get the memory description structure, which contains the physical address set and the ops we want to modify.

31:40.220 --> 31:45.500
And here, one thing you can see, the ops is a pointer.

31:45.500 --> 31:49.720
It's pointing to something in the kernel memory.

31:49.720 --> 31:55.960
So if we read this ops out, then we can get the KSL information.

31:55.960 --> 32:00.920
So in our exploit, we bypass the KSL at this step.

32:00.920 --> 32:05.480
So we can bypass the KSL here, and then get to the next step.

32:05.480 --> 32:10.640
We can modify the physical address, modify the size, modify the ops.

32:10.760 --> 32:16.660
We will modify the physical address to the kernel physical address, and the size to the kernel size.

32:16.660 --> 32:21.000
Then finally, we can map the whole kernel memory to the user space.

32:21.000 --> 32:25.220
Then we can do arbitrary read-write to the kernel memory in the user space.

32:25.300 --> 32:27.520
So that's the exploit.

32:28.440 --> 32:34.140
We can actually expand this method to a more generic case.

32:34.140 --> 32:47.300
Suppose you have a kernel heap buffer overflow, or you have a risk condition issue, you can also use this method to make your exploit easier.

32:47.440 --> 32:56.500
The first step, you can spray a large amount of this memory descript into the kernel heap, and then you trigger your vulnerability.

32:56.500 --> 33:05.280
Suppose you have a kernel heap overflow issue, you can overflow it from here into this ops.

33:05.280 --> 33:09.760
Then you can control the physical address and ops.

33:09.760 --> 33:14.580
And then you can try to do memory map on this memory object.

33:15.060 --> 33:22.600
If you are lucky, you succeed, then you can map the whole kernel physical memory to the user space.

33:22.600 --> 33:27.320
But if you are not lucky, you can try it again and again until you succeed.

33:27.380 --> 33:32.320
So that's how we expand this method to a more generic case.

33:32.520 --> 33:39.580
And maybe you remember we have a bonus, which we can bypass the case using this method.

33:39.580 --> 33:42.800
So look at the structure carefully.

33:42.800 --> 33:51.240
You may find that there are lots of kernel points, like the page table is a pointer and the host PTR.

33:51.240 --> 33:53.320
And also we have the HTTP.

33:53.320 --> 33:58.280
You might think, oh, we will need to get KSR information first.

33:58.280 --> 34:03.560
We have to point this point to a digital address.

34:03.560 --> 34:16.000
But in fact, you don't have to worry about this field, because in most of the cases, if you don't call some special R control by yourself, these fields are not used in most of the cases.

34:16.000 --> 34:22.560
So you can just overwrite these fields with a capital value or whatever you want.

34:22.560 --> 34:27.720
You can just overwrite the page table, the host PTR, and the GPU address.

34:27.720 --> 34:29.720
All this stuff is not used.

34:30.580 --> 34:36.200
The only thing you care about is the physical address, the size, and the ops.

34:36.200 --> 34:39.000
You might all think, oh, here we have the ops.

34:39.000 --> 34:40.780
It's also a pointer.

34:40.780 --> 34:46.880
So you have to know the original value, or you have to know the ASR information.

34:46.900 --> 34:51.820
But actually, no, you don't have to know the KSR information.

34:51.820 --> 34:54.180
You look at the original value carefully.

34:54.180 --> 35:00.540
You can see this is the original value, and this is the target value we want to modify.

35:01.140 --> 35:05.100
You can see that the high bytes are actually the same.

35:05.260 --> 35:06.560
Why are they the same?

35:06.560 --> 35:10.780
Because the KSR is based on the page.

35:10.780 --> 35:12.080
It's page-based.

35:12.080 --> 35:20.480
So if the two function points are in the same page, so they have the same high bytes that are in the same page.

35:20.480 --> 35:22.800
So all these bytes are the same.

35:22.800 --> 35:29.840
So you can actually ignore these bytes and overwrite from the beginning to the lowest byte, overwrite it to here.

35:29.840 --> 35:32.920
Then you don't have to care about the KSR.

35:32.920 --> 35:35.500
So that's how we bypass the KSR.

35:35.500 --> 35:41.720
And one thing here, you can see the lowest byte is already known from the kernel firmware.

35:41.720 --> 35:45.580
So you don't have to acquire additional information.

35:45.580 --> 35:49.620
You can bypass the KSR and get the expert working.

35:49.620 --> 35:54.760
You just overwrite to the lowest byte and ignore the high bytes.

35:55.620 --> 35:57.960
Yeah, that's how we bypass KSR.

35:57.960 --> 36:01.220
And in some cases, maybe you are not so lucky.

36:01.220 --> 36:04.300
You get the following situation.

36:04.300 --> 36:09.280
You can see it's not in the same page, but in the source code, they are near each other.

36:09.280 --> 36:15.160
So in most of our case, the original value is near the target value.

36:15.160 --> 36:18.160
So it's just like a 4-bit difference.

36:18.160 --> 36:21.420
So for 4-bit, it's just a 16 possibility.

36:21.420 --> 36:23.720
You can try 16 times.

36:23.720 --> 36:27.140
So you can undo the brute force for 16 times.

36:27.140 --> 36:29.080
Then you can bypass the KSR.

36:29.080 --> 36:33.400
So that's how we bypass the KSR and that's the exploit.

36:33.400 --> 36:36.720
Okay, we'll get to the demo.

36:36.960 --> 36:38.620
The demo is online.

36:38.620 --> 36:41.840
You can view the demo online.

36:41.840 --> 36:43.620
Also, we'll play it here.

36:43.620 --> 36:46.800
You can see here.

36:46.800 --> 37:01.560
When we record this demo, we are recording it on a pretty famous smartphone using the latest Qualcomm SoC, using Snapdragon generation 8 with the latest security patching.

37:02.660 --> 37:05.220
We'll start with the share user.

37:05.220 --> 37:08.160
Of course, you can also use the uncharged application user.

37:08.160 --> 37:09.660
There's no difference.

37:09.720 --> 37:11.960
So we are trying to get a load share.

37:12.360 --> 37:17.020
Of course, we don't have a load privilege now, so this fails.

37:17.100 --> 37:19.220
So we will start our exploit.

37:19.320 --> 37:26.240
And the first step is to trigger the vulnerability and control a large amount of physical pages.

37:26.400 --> 37:29.080
So we trigger the vulnerability again and again.

37:29.080 --> 37:32.660
And here we think we have enough pages.

37:33.300 --> 37:37.180
So now you can see we have controlled enough physical pages.

37:37.180 --> 37:39.120
Then we go to the next step.

37:39.120 --> 37:41.680
We trigger a system no memory.

37:41.680 --> 37:45.380
We allocate a lot of memory from the user space.

37:45.400 --> 37:53.560
So all the cached memory or the system memory unused system memory will be returned to the kernel.

37:53.660 --> 37:55.980
So we can do heap spray.

37:55.980 --> 37:59.740
We create a lot of these VBO entries.

38:00.020 --> 38:01.800
And then we are lucky.

38:01.800 --> 38:06.820
Some of the VBO entries will be located in the controller page.

38:06.820 --> 38:09.460
So we scan the controller page.

38:09.460 --> 38:13.920
And then we can find this controller object.

38:13.920 --> 38:18.820
You can see we found one controlled memory description object.

38:18.820 --> 38:23.520
So this object has a physical address, size, and ops we want.

38:23.520 --> 38:27.660
So we can patch this structure.

38:27.800 --> 38:30.580
The ops will modify the physical address.

38:30.580 --> 38:36.440
You can see this A801 is actually the kernel physical address.

38:36.440 --> 38:38.320
And the size is the kernel size.

38:38.320 --> 38:41.700
So we have patched the structure.

38:41.700 --> 38:47.220
And now we can map this structure to the user space.

38:47.220 --> 38:50.700
So we can map the whole kernel memory to the user space.

38:50.700 --> 38:53.280
And patch the kernel memory.

38:53.280 --> 38:55.660
Here we have patched the kernel version.

38:55.740 --> 38:59.300
And also we patched some of the code in the kernel.

38:59.300 --> 39:00.840
So we can get a root.

39:00.840 --> 39:03.900
So you can see now we are the root user.

39:04.200 --> 39:05.560
So that's the demo.

39:09.500 --> 39:10.880
Thank you.

39:10.880 --> 39:13.680
I will transfer to Eugene for the next content.

39:14.760 --> 39:16.320
Thank you very much, Shiling.

39:16.320 --> 39:21.500
And with that, I will be speaking about the last section of this presentation.

39:21.500 --> 39:23.200
How we found this vulnerability.

39:23.340 --> 39:28.160
Which methodology is applicable when you are doing bug hunting for GPU kernel modules.

39:28.160 --> 39:35.500
And what we can do to improve security of the GPU in the mobile space.

39:35.520 --> 39:40.780
Well, first of all, we identified this vulnerability via manual code review when we were doing patch analysis.

39:40.780 --> 39:47.300
And by patch analysis, essentially we use a collective term where we look at the security fixes.

39:47.540 --> 39:50.700
Which are published in the Android Qualcomm security bulletin.

39:50.700 --> 39:54.980
We also look at the security research published by other security researchers.

39:55.140 --> 39:58.780
And this is very important for such complex cases and big targets such as GPU.

39:59.120 --> 40:00.740
Because the state is very big.

40:00.740 --> 40:04.580
And as Shiling explained earlier in this presentation, there is a lot of moving parts.

40:04.580 --> 40:18.400
In order to have a holistic understanding, it's important to read others' blog reports to better understand the domain in this area.

40:18.400 --> 40:25.660
Originally, we wanted to put on the slide a very cool chain of vulnerabilities which we did variant analysis for.

40:25.660 --> 40:29.800
So, for example, Qualcomm internally identified one of the issues.

40:29.800 --> 40:32.160
They published a fix in their security bulletin.

40:32.160 --> 40:35.660
Then a security researcher looked at this fix.

40:35.940 --> 40:39.080
They found another related issue in this area.

40:39.080 --> 40:42.200
They wrote a blog post and published it.

40:42.200 --> 40:51.340
While looking at these two fixes by Qualcomm and the security researcher, we managed to identify another problem in the related area.

40:51.340 --> 41:02.180
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.

41:02.220 --> 41:08.300
We decided to put this quote here, which I think reflects the idea which we would like to convey in the slide.

41:10.260 --> 41:13.800
While speaking about methodologies, we cannot skip fuzzing.

41:13.800 --> 41:16.980
Because fuzzing is one of the essential methodologies we use.

41:16.980 --> 41:24.420
This is one of the most efficient and productive ways of finding bugs in the modern complicated software and the firmware.

41:24.540 --> 41:29.720
And there is a lot of benefits, I think, quite obvious for fuzzing.

41:29.720 --> 41:35.800
So on this slide, particularly, we will focus on challenges applicable to fuzzing GPU targets.

41:37.880 --> 41:43.700
And think about how can we overcome those or how can we solve them.

41:43.700 --> 41:53.780
So first of all, to enable efficient fuzzing of the GPU drivers, there is a lot of dependence on the hardware.

41:53.780 --> 41:58.620
As we have seen, this particular vulnerability is in the misconfiguration of the IOMMU.

41:58.620 --> 42:03.580
So in order to theoretically find this vulnerability, we would need to do on-device fuzzing.

42:03.580 --> 42:08.220
And although this is possible, this makes fuzzing a little bit less scalable.

42:08.220 --> 42:15.680
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.

42:15.900 --> 42:21.700
This is not a limitation, but this is one of the interesting observations.

42:21.700 --> 42:29.540
Because I know that there are some other GPU vendors which enable building their kernel-mode components in the architecture-independent way.

42:29.540 --> 42:39.980
So basically, there is a separation between software and hardware logic, so it's possible to build driver and run it without the hardware.

42:39.980 --> 42:45.320
To be able to test and fuzz the generic functionality implemented in the software.

42:45.420 --> 42:49.740
And another approach is using the emulation-based fuzzing to have an emulator for that.

42:49.740 --> 42:56.960
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.

42:56.960 --> 43:03.220
In order to be able to emulate it in the emulator.

43:03.700 --> 43:09.160
This particular issue was identified in the MMU and IUMMU domain.

43:09.160 --> 43:13.980
And this is actually a very common pattern in the GPU bugs reported these days.

43:13.980 --> 43:18.880
Where the physical pages for the backend storage are released back to the kernel.

43:18.920 --> 43:29.040
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.

43:29.060 --> 43:32.700
And this is very difficult to detect with fuzzing, because this doesn't lead to any crash.

43:32.700 --> 43:45.700
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.

43:45.720 --> 43:46.840
This is one thing.

43:46.840 --> 43:52.080
Probably manual instrumentation of the driver with such checks would help.

43:52.240 --> 43:55.220
But again, this is manual work which makes it less scalable.

43:55.400 --> 43:57.820
GPU has a very complicated state machine.

43:57.820 --> 44:09.600
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.

44:09.600 --> 44:16.020
Or if we're speaking about fuzzing with syscaller, probably this is additional custom syscalls which needs to be written for that.

44:16.020 --> 44:22.200
And of course, fuzzing concurrent code is not straightforward.

44:23.340 --> 44:29.780
Because there are some problems with reproducing and problems with hitting those vulnerabilities.

44:32.320 --> 44:36.420
Probably the final slide before we wrap it up, the ultimate mitigations question mark.

44:36.420 --> 44:37.240
Why question mark?

44:37.240 --> 44:43.060
Because, well, I guess suggesting mitigations for GPU is really not straightforward.

44:43.060 --> 44:51.460
And this is more about thinking employees about how can we make GPU security better in the mobile space.

44:51.460 --> 44:58.500
First of all, one of the major points why GPU is so attractive is because it is widely accessible to untrusted code.

44:58.740 --> 45:04.180
Because the untrusted code can directly open the driver and send arbitrary data to it.

45:04.340 --> 45:10.240
Android is very known for using IPC and binder in order to isolate components.

45:10.240 --> 45:15.560
So maybe one of the ideas is to move GPU from in-process hull into the out-of-process hull.

45:15.560 --> 45:20.280
I know this will impact performance and performance is very important for GPU.

45:20.280 --> 45:24.320
This might create some backward compatibility issues, but this is one of the ideas to think about.

45:24.360 --> 45:42.900
And additionally, the usage of memory-safe languages in the driver, I think, based on our experience, they might mitigate the majority of root causes, which lead to problems such as integer overflows, or in this particular case, integer race conditions.

45:43.820 --> 45:47.380
And I think with that, we hit almost the end of our time.

45:47.380 --> 45:50.140
And last slide, thank you very much for your attention.

45:50.160 --> 45:52.720
A small, shameless marketing plug.

45:52.720 --> 45:58.760
Here we have our Android offset with Google.com, where we publish our security research.

45:59.220 --> 46:08.780
And with that, yeah, I think we're happy to take any questions here on stage or offline using this contact information here.

46:08.780 --> 46:09.780
Thank you very much.

