WEBVTT

00:00.000 --> 00:03.180
And with no further ado, please continue.

00:07.880 --> 00:16.520
Hello, everyone, and welcome to my talk, Clash, Burn, and Exploit Manipulated Filters to Pwn Kernel CTF.

00:17.140 --> 00:22.960
I'm HexRabbit from Taiwan, currently working as a security researcher at DefCon.

00:22.960 --> 00:27.760
I specialize in binary exploit, especially in Linux kernel exploitation.

00:27.760 --> 00:35.020
I found some vulnerabilities in Linux kernel components like ksmbd, nstables, and others.

00:36.180 --> 00:41.160
Today, I will start from introducing kernel CTF and nstables.

00:41.160 --> 00:48.680
After that, we will dive into the nstable internals and talk about three vulnerabilities we discovered in nstables.

00:49.140 --> 00:57.140
And in between these three vulnerabilities, I will also share some story behind the scene during my kernel CTF journey.

00:57.740 --> 01:02.420
So, let's first talk about kernel CTF.

01:02.420 --> 01:08.760
Kernel CTF is part of Google VRP, and the way it works is quite similar to a CTF challenge.

01:08.980 --> 01:15.820
For about every two weeks, there will be a new kernel version released, and attendees will be given an unprivileged show.

01:15.820 --> 01:23.600
And you will need to exploit the Linux kernel to get flagged and submit it to Google to earn a bounty.

01:23.600 --> 01:26.240
There are three instances that can be pawned.

01:26.240 --> 01:38.120
LTS and CLS both use newer and quite similar kernel config, while the mitigation one uses an older kernel config with custom security patch to accept more one-day exploits.

01:38.560 --> 01:43.440
But the most important thing is, Google offers pretty big bounty reward.

01:44.660 --> 01:53.460
With some simple math calculation, we can quickly find for a zero-day LTS exploit, the bounty can easily surpass $50,000.

01:53.780 --> 02:07.400
And with the same vulnerability, you can earn both $21,000 maximum in both mitigation and CLS instance, which is quite appealing for the bounty hunter like me.

02:08.460 --> 02:10.940
So, why am I targeting nftables?

02:10.940 --> 02:14.760
First, nftable config is enabled in kernel CTF.

02:14.760 --> 02:20.320
And as you can see on the right, there are multiple vulnerabilities discovered just after kernel CTF is announced.

02:20.320 --> 02:25.620
So, for kernel CTF newbie like me, I think it's the right place to start.

02:26.520 --> 02:31.260
Okay, so first we take a brief intro to nftables.

02:33.060 --> 02:35.520
What exactly is nftables?

02:35.520 --> 02:39.060
nftable is a package filtering framework inside Linux kernel.

02:39.060 --> 02:45.400
It's used to replace the legacy IP, ARP, EB tables, merge them into a single entry point.

02:45.400 --> 02:53.620
It uses a simple VM design to implement its functionality and support new syntax for CY interface.

02:53.620 --> 03:01.340
As you can see on the right, instead of doing things one by one, new syntax can now allow config multiple things all at once.

03:01.440 --> 03:06.480
And these capabilities come from its design, which we will revisit later.

03:08.740 --> 03:11.700
nftable is constructed by a tree-like structure.

03:11.700 --> 03:17.380
It contains five core modules, table, chain, rule, expression, and set.

03:18.160 --> 03:22.100
Table is the top-level container for the below structures.

03:22.100 --> 03:23.910
It's used for the measurement purpose.

03:24.840 --> 03:33.120
Each table will only belong to a specific neural family, and any object contained by the table will follow the same family.

03:34.340 --> 03:42.560
Chain in nftables will hook at predefined hooking point provided by net filter infrastructure to do the packet filtering.

03:42.800 --> 03:53.200
When any packet flows through the hooking point, the chain will execute the expressions in the row it managed to accept or to block or to modify the packets.

03:53.240 --> 03:56.760
So what is the rule and what is the expression?

03:58.280 --> 04:04.960
As I mentioned earlier, nftable implement its functionality by a simple virtual machine.

04:04.960 --> 04:14.100
So you can think a rule as a small function that can contain multiple expressions, and the expression is the instruction for nftables.

04:14.460 --> 04:25.640
There are different types of expressions that can be used to manipulate VN registers, and the others can be used to load or to read or write data within packets.

04:27.260 --> 04:34.860
And thus, set is used to store a group of some type, like IP address, port, or any binary data.

04:34.960 --> 04:45.180
It can also be used as a map to map some type A to another type B, and these data stored in the set can be queried by the expressions during packet filtering.

04:47.220 --> 04:54.920
Okay, so after having some basic understanding of nftables, I will now introduce the first vulnerability I discovered.

04:55.560 --> 04:59.220
At the time, I'm not so familiar with nftables.

04:59.220 --> 05:02.580
However, I spotted something weird in the code base.

05:02.860 --> 05:07.080
These three functions are all used to delete objects in nftables.

05:07.300 --> 05:23.100
The nftable deleteRuleDeactivate will be called during rule deletion, nftFlush will be called during full config flush, and nftSetElementCatchAllDeactivate will be called during set element deletion.

05:23.940 --> 05:27.160
However, the pattern here is a bit different.

05:27.160 --> 05:35.420
The first two use nftIsActiveNext to check if the object is active.

05:35.420 --> 05:41.960
But the last one, nftSetElementCatchAllDeactivate use nftIsActive to check.

05:42.000 --> 05:44.200
So what's the difference?

05:45.160 --> 05:51.960
Actually, these two functions are used for object lifetime management in nftables.

05:51.960 --> 05:59.920
In order to understand how it works, we will need to first talk about the batch request mechanism.

06:02.300 --> 06:13.840
For a query request, for example, the getRule operation above, Netlink API will internally use netlinkReceiveXKB to get the raw information loglessly.

06:14.340 --> 06:27.640
However, if it's some operation that will modify the control plan, like new table or delete chain, nftables will use nfnetlinkReceiveBatch instead of the logless one to serve the request.

06:27.640 --> 06:36.820
The difference between them is that batch one can process a request which contains multiple operations, and they will be processed sequentially.

06:37.680 --> 06:44.260
And also because of this design, the COR interface can copy multiple things all at once.

06:44.260 --> 06:54.920
So it sounds great, but the thing becomes more complicated when any operation fails in the middle of a batch request.

06:55.420 --> 07:01.460
And what nftables do is to split batch request handling into multiple phases.

07:03.140 --> 07:07.800
There are three phases during the handling of the batch request.

07:07.800 --> 07:11.500
Prepare phase, commit phase, and abort phase.

07:11.500 --> 07:20.400
During the prepare phase, if every operation finished successfully in the batch request, it will go to the commit phase and commit the changes.

07:21.300 --> 07:29.200
However, if something went wrong, after every operation is processed, it will go to abort phase and revert all the changes.

07:29.780 --> 07:32.140
Here's the lifetime management's consign.

07:33.840 --> 07:39.920
Any object in nftables has two state variables, current generation and next generation.

07:39.940 --> 07:46.600
Only the object activated in current generation can affect the runtime behavior.

07:46.860 --> 07:51.440
And you can think the next generation as a temporary state for the prepare phase.

07:52.040 --> 08:01.440
Every operation modify the control plan, like new or delete operations, will only make changes on the next generation state in the prepare phase.

08:01.440 --> 08:04.840
So without affecting the current generation state.

08:04.840 --> 08:10.740
Then, during the commit phase, it will commit the modification.

08:11.040 --> 08:19.880
So the current generation will finally be set as the next generation, and the next generation state will be reset to a clean state.

08:20.480 --> 08:28.320
But in the case if something went wrong during the abort phase, it only needs to clean the next generation state.

08:28.780 --> 08:32.200
Let's go through some examples to know how it works.

08:33.380 --> 08:38.340
After a batch request is received, it goes into the prepare phase.

08:38.860 --> 08:42.120
The first operation is delete set C.

08:42.220 --> 08:47.880
Okay, so the set C's next generation state will be set to deactivated.

08:49.080 --> 08:54.200
Next, it continues to process a set D operation.

08:55.120 --> 09:00.260
So the set D will be added into hash table with next generation in activated state.

09:02.400 --> 09:11.860
If nothing went wrong, we will go to the commit phase, and at this phase, current generation will be set as the next generation.

09:12.340 --> 09:19.620
So the set D will be available in both runtime and query operations, and also the set C will be free.

09:21.880 --> 09:33.100
If something went wrong, we will enter the abort phase, and at this phase, all operations done in the prepare phase will be reverted in a reverse order.

09:33.380 --> 09:39.500
So the add set D will be undue, and also the delete set C will be undue.

09:42.660 --> 09:44.520
So okay, back to the check.

09:44.780 --> 09:46.740
So what's the problem here?

09:46.980 --> 09:55.900
As we can see, during the NFT set element catch all deactivate, it used NFT is active to check if the element is still alive.

09:56.020 --> 10:07.520
However, NFT is active checks current generation, but the function actually runs in the prepare state, which will only modify the next generation state of an object.

10:08.020 --> 10:19.460
So the check here will always pass, and by request multiple delete operations, we can free the element multiple times in the commit phase.

10:20.160 --> 10:34.240
So the batch request to trigger double free will look at this, since the lifetime check will always pass if the element exists during the prepare phase, two delete set element of operation will both execute successfully.

10:34.320 --> 10:43.080
And so when you get to the commit phase, the same element will be free twice, and we get a set catch all element double free.

10:44.160 --> 10:48.070
Great, so I found my first bug for current CTF.

10:48.070 --> 10:58.950
But the next day, I found the maintainer also find the same bug and send a patch to kernel mailing list.

10:58.990 --> 11:00.550
I mean, why?

11:00.890 --> 11:12.970
So, okay, this means my zero day is officially turns into a one day, and according to kernel CTF rules, my bounty will decrease by 20,000 USD.

11:13.330 --> 11:14.330
Ouch.

11:15.610 --> 11:24.410
Also, one day vulnerability means that everyone will know how to trigger the vulnerability, and they may also come up with some exploit.

11:24.410 --> 11:29.370
So I definitely need to exploit it before next kernel CTF slot opens.

11:31.940 --> 11:45.980
So after we get the double free primitive, we reuse the exploit method for CVE-2023-4004 to overlap the MFT table user data and MFT object to leak address and control IP.

11:46.100 --> 11:56.440
Due to a time limit of this talk, I won't expand the detail of it, but kudos to Lonely and Calm who discovered this technique and shared it on kernel CTF repository.

11:57.560 --> 12:03.600
So now we develop the exploits and wait for the slot to reopen.

12:04.560 --> 12:08.620
Fast forward to two hours before the competition starts.

12:08.620 --> 12:16.080
I nervously check if there's any kernel updates related to NF tables, and guess what?

12:16.260 --> 12:24.200
The patch previously posted on the mailing list has been merged into the kernel, and it added one line on it.

12:24.200 --> 12:39.900
It says reported by Lonely and Calm, which this means is the patch may actually come from a zero day kernel CTF submission, and since the reporter is Lonely and Calm whose exploit I just used, this is indeed the case.

12:40.180 --> 12:46.540
So just before I have the chance to exploit an official instance, I found it's a collision.

12:48.040 --> 12:58.760
So yes, I still found the instance and report the flag, but too bad for me, the first bug do collide with an old kernel CTF submission.

12:59.600 --> 13:01.780
That's how I look after the competition.

13:04.860 --> 13:12.700
Okay, so I take some break, and after three weeks later, I found the second bug.

13:14.160 --> 13:18.280
During the research, I came across an interesting commit.

13:18.380 --> 13:22.880
NF table validate family when identifying table by handle.

13:23.500 --> 13:30.800
The commit is added after the mitigation instance kernel version, so it can be used upon the mitigation instance as a one day.

13:31.300 --> 13:41.440
It added a check on NFC table lookup by handle function, which is used for searching a register table by the provided handle.

13:41.940 --> 13:52.740
Without the commit, during the table lookup, we can provide a family different from the one which table belongs to, but what can we do with this inconsistency?

13:54.160 --> 13:59.360
Let's trace where the family parameter comes from and where it goes.

13:59.360 --> 14:10.020
NF table lookup by handle is only code from NF table delete table, and this function is used to delete user-specified table from NF tables.

14:10.140 --> 14:22.500
The family variable is directly get from user-provided input and is saved into context family and passed to NFT flush table function.

14:23.640 --> 14:30.800
In NFT flush table, context argument is passed into every function handling object deletion.

14:30.800 --> 14:44.520
For me, trace which function use the context family is quite annoying, so instead of just tracing into each function, I take the shortcut to trace where it is used.

14:45.060 --> 14:50.420
So I just grab the whole code base to find where the context family is used.

14:52.460 --> 15:03.480
Grabbing context family gives us a lot of result, most of which comes from the NF table expressions, like count limit, net, T proxy, and et cetera.

15:03.900 --> 15:11.660
However, most of them cannot be used for the exploit, but I finally found one that can be exploited.

15:12.040 --> 15:14.900
It is in the NFT log expression.

15:16.700 --> 15:20.640
The trigger path I found starts from the NFT log destroy.

15:20.640 --> 15:25.580
This function takes context family as an argument and code to NF log output.

15:26.660 --> 15:33.210
Now it's becoming the PF argument and used as an index to de-reference the loggers array.

15:34.340 --> 15:40.440
The value range of our input context family and also the PF here is zero to 255.

15:40.460 --> 15:49.060
But if we check the size of loggers array, we can find it only has 13 elements in the first dimension.

15:49.440 --> 15:54.120
So we get the global array out of bound access here.

15:54.260 --> 15:56.460
But what can we do with it?

15:58.160 --> 16:04.500
After taking the logger out, it de-referenced the me field and feed it into the module put.

16:05.440 --> 16:11.740
The module put will again de-reference and decrease the refcon value in the module object.

16:12.220 --> 16:17.840
With this vulnerability, logger can be any pointer store adjacent to a loggers array.

16:17.840 --> 16:23.080
So we may cause some type confusion here and decrease some variable by one.

16:23.320 --> 16:27.420
However, we are dealing with an awkward situation here.

16:27.420 --> 16:34.480
In order to utilize this bug, we have to find a pointer store on global and can be de-referenced twice.

16:35.160 --> 16:41.780
The first is to take our logger me and the second is to take our module refcon.

16:43.640 --> 17:03.720
To sum up what we have by now, first, the maximum value of PF value we can control is 255 and we can trigger an out of bound reference count decrement by using a PF value larger than 12, which will execute like the code here.

17:04.140 --> 17:11.240
To exploit this, the first thing we need to do is to find a global pointer placed near the loggers array.

17:12.340 --> 17:14.400
So what do we have on the global?

17:14.920 --> 17:23.540
By inspect the marrying GDB, we quickly find there's an NFCT expect hash placed near the loggers array.

17:24.120 --> 17:25.920
And it's a hash table.

17:25.920 --> 17:33.560
So in this case, it seems to be a good target since the pointer point to an array of pointers.

17:33.560 --> 17:36.300
Therefore, it can be de-referenced twice.

17:38.320 --> 17:42.060
So let's check how the code normally works.

17:42.540 --> 17:51.860
First, it gets the me field at offset 1x and then get the refcon at offset 340x.

17:52.880 --> 17:56.280
Now let's check the out of bound access case.

17:56.280 --> 18:01.580
First, we set PF to 19 to get a hash table pointer, NFCT expect hash.

18:01.960 --> 18:07.180
The first de-reference we got is the index tree entry of the hash table.

18:07.660 --> 18:13.500
The entry points to the HNO field of a contract expect object.

18:13.580 --> 18:19.900
So after one more de-reference, it will access offset 340x down below the expect object.

18:20.240 --> 18:26.280
But since the expect object only has a D at size, it will access out of bounds.

18:27.100 --> 18:33.600
Fortunately, all NF contract expect object allocated in a dedicated Cayman cache.

18:34.420 --> 18:40.040
So the memory space below will also contain NF contract expect objects.

18:40.920 --> 18:46.860
So it will access to an RCU field and decrease the next pointer in the structure.

18:46.860 --> 18:50.680
But what does this next pointer use for?

18:52.140 --> 18:58.620
As we know, after RCU objects free, Linux kernel will not instantly free the object.

18:58.620 --> 19:05.180
Instead, it will hold the object for a grace period to wait for all other RCU readers to finish.

19:05.360 --> 19:14.080
So the next pointer in the RCU hash structure is used for temporary storing them and waiting for the RCU thread to process, to free them.

19:15.640 --> 19:22.400
So after the contract expect object are free, they will be like this, trained by the next pointer.

19:24.580 --> 19:31.720
And since we can decrease the next pointer in RCU head, we can make it point to another field inside the contract expect object.

19:33.140 --> 19:41.300
And to exploit it, we choose to land it on a user controllable field, which contains a union of IPv4 and IPv6 address.

19:41.440 --> 19:49.040
So when RCU callback triggered, it will read the fake function pointer we set, and we can control the IP.

19:50.660 --> 19:55.520
However, to actually exploit the vulnerability, we came across some roadblocks.

19:55.880 --> 20:04.240
First, we need the index tree of the hash table point to some expect object, so we can use it to do the out-of-bound write.

20:04.780 --> 20:09.760
But unfortunately, the hash value is unpredictable.

20:11.100 --> 20:19.480
Next, the out-of-bound written expect object needs to be in the grace period, so we can decrease its next pointer.

20:20.400 --> 20:27.220
But the next period is a small time window, and how to control when the kernel actually frees the object.

20:28.560 --> 20:34.600
Well, so long story short, we eventually found a way to exploit it by brute force and race.

20:35.900 --> 20:42.040
So to exploit this, first we use a tight loop to create a lot of expect objects.

20:42.800 --> 20:52.440
And at some point, the expect count exceeded the value max expected and start to evict the oldest expect object.

20:53.620 --> 20:58.260
So the oldest expect object will be placed into the RCU free list.

20:58.960 --> 21:01.980
And so on, and so on.

21:02.000 --> 21:08.180
And at some point, RCU thread gets scheduled by the kernel and starting to process objects.

21:11.160 --> 21:20.560
At this point, we add another thread to trigger out-of-bound decrement in a batch request and keep this system running for a bit.

21:22.520 --> 21:26.360
So we hope for a race scenario like this to emerge.

21:27.520 --> 21:38.840
First, the expect object allocated into index three of the hash table, and then the expect object we want to out-of-bound write is freed into the RCU free list.

21:39.220 --> 21:43.360
Then it continues to free another expect object.

21:44.420 --> 21:53.620
After that, we trigger the vulnerability 28 times in a batch request to make the next pointer point to a user-controllable value.

21:53.960 --> 22:00.360
And finally, the RCU start to process these free object and runs our set callback function.

22:01.860 --> 22:02.960
Great.

22:02.960 --> 22:04.940
Let's try it on local build.

22:05.020 --> 22:10.620
And we successful successfully control the IP to form, form, form, form.

22:12.220 --> 22:14.560
So what about remote?

22:16.440 --> 22:17.760
Let's try.

22:17.780 --> 22:22.680
And we got an error message while trying to add the lock expression.

22:23.080 --> 22:30.680
Since I have no idea what happened on the remote environment, I decided to download the official busy image to debug it locally.

22:32.360 --> 22:44.620
So I open the GDB and set some breakpoint on the functions, but when I set the break on nft-lock-destroy function, GDB complained that it was not defined.

22:44.620 --> 22:45.620
What's wrong here?

22:48.100 --> 22:56.460
I later found that it's because the kernel config I used is different from the one used in the official environment.

22:56.460 --> 23:09.520
So the log expression I used to exploit the vulnerability not even compiled into the official image, but I'm using the official build script to view the local test image.

23:09.520 --> 23:12.100
Why on earth there can be any difference?

23:14.380 --> 23:16.460
I mean, why?

23:19.540 --> 23:24.200
Eventually, I found it is caused by the official build script.

23:24.200 --> 23:32.080
The mitigation instance is built by COS kernel config plus the Google custom security security patch.

23:32.180 --> 23:38.600
And the official mitigation instance use COS config 6.1.55.

23:39.480 --> 23:48.220
The nftable expression are enabled in COS config after the version 6.1.64.

23:48.220 --> 24:01.820
However, the build script will always fetch the latest COS config, so the mitigation kernel I built has the nftable expression enabled, but in the official image, they're actually disabled.

24:03.780 --> 24:09.820
So, well, I think next time I should definitely check out the config first.

24:14.100 --> 24:22.840
Okay, so after my second failure, I revisit some old patch and I found a new bug.

24:25.170 --> 24:30.610
The patch I was looking at is a patch which introduced the first bug.

24:30.670 --> 24:37.930
The title says nftable, a set backend to use GC transaction API.

24:38.210 --> 24:40.570
So what does the GC mean?

24:40.990 --> 24:44.950
Here it means the set garbage collection.

24:45.110 --> 24:51.910
There are some set implementation support user to set a timeout on any set element.

24:51.910 --> 24:56.570
And there are two types of GC to clean the expired element.

24:56.570 --> 25:07.910
The first one, the synchronous one will be called in the commit phase, and the asynchronous one will be triggered periodically in the background.

25:08.370 --> 25:13.070
But here we only focus on the asynchronous one.

25:13.390 --> 25:15.770
So back to the patch.

25:16.370 --> 25:25.510
In the commit message, it says use GC transaction API to replace the old and buggy GC API and the busy mark approach.

25:26.190 --> 25:30.130
So what is the difference between the new and the old one?

25:30.390 --> 25:34.150
Let's take a look of the old GC design.

25:35.110 --> 25:42.150
In the old design, the synchronous GC will run loglessly and can be triggered at any time.

25:42.410 --> 25:54.190
So in order to protect GC threads from raising with the landing API, both of them will check a busy mark set on the element before delete it to prevent double free.

25:56.330 --> 26:01.670
But sometimes the developer might forget to check against it.

26:01.790 --> 26:09.110
In this case, there's a new function called NFT map deactivate forgot to check a busy mark.

26:09.270 --> 26:12.170
And this leads to a double free vulnerability.

26:13.410 --> 26:21.050
So in order to avoid this kind of issues, NFT developer decided to replace it with a new design.

26:22.250 --> 26:26.690
In the new GC design, it introduced the GC sequence.

26:26.830 --> 26:36.190
The GC sequence is a per net variable and it will be increased before and after any modification to the control plan.

26:36.210 --> 26:43.750
So it will increase at the beginning and at the end of both the commit and the abort phase.

26:44.390 --> 26:49.970
During a GC procedure, GC thread will record and check it to prevent raise.

26:50.270 --> 26:58.150
Even though the GC thread still run loglessly, during the check, it will now quad the commit mutex lock.

27:01.030 --> 27:03.630
The new GC design look like this.

27:05.010 --> 27:12.210
During batch request handling, GC sequence will increase both before and after the commit and abort phase.

27:12.330 --> 27:21.250
And in the GC thread, it will first run locklessly to store the GC sequence and collect all the expired elements.

27:21.530 --> 27:27.770
After that, it will quad the lock and check if the current GC sequence match the safe one.

27:28.170 --> 27:32.270
If they are the same, then the elements will be released.

27:33.350 --> 27:40.530
For this normal case, since GC thread does not raise with the batch request, the GC sequence will be the same.

27:41.230 --> 27:44.490
And the element can be freed by the GC thread.

27:47.960 --> 27:51.860
Next, we check if it still works in the raise case.

27:51.980 --> 28:10.680
If during the prepare phase, GC thread triggered and stored the global GC sequence into transfer objects, it will continue to run loglessly to find all the expired elements and wait for the mutex lock.

28:12.420 --> 28:21.340
At the same time, the main thread stepped into the commit phase, and some of the elements in the set can be released in this phase.

28:22.320 --> 28:33.220
The GC thread will need to wait until the main thread releases the mutex lock, so it can finally check the safe GC sequence and delete the element.

28:33.720 --> 28:44.360
But in this case, since GC sequence is recorded in the prepare phase, and we check it after the batch request is done, the GC sequence will be different.

28:44.540 --> 28:48.320
So, the element deletion will be skipped to avoid double free.

28:49.200 --> 28:54.540
Next, let's check the case if GC sequence is recorded in the commit phase.

28:54.540 --> 29:12.780
In this case, since GC sequence increased after the commit phase, the GC thread can only check GC sequence after the commit mutex unlocked.

29:13.900 --> 29:17.040
This raise will also be detected.

29:18.220 --> 29:27.640
So, to sum up, the new GC design requires both the batch request and the GC sequence check to hold the lock.

29:27.640 --> 29:37.580
This ensures that even there's a raise while collecting the expired element, the check will always happen after the GC sequence has increased.

29:40.670 --> 29:46.430
But does the batch request always lock mean there's no raise?

29:46.430 --> 29:55.390
Actually, if you look closely, we will find, well, it's not always locked.

29:57.940 --> 30:03.780
To find where it release the lock, let's first talk about the module autoload.

30:03.960 --> 30:20.300
During the prepare phase, if there's some expression type in the request is not found during the type resolution, it will instantly abort and try to load the type module during the end of the abort phase.

30:20.820 --> 30:25.160
After that, it will retry the whole batch request again.

30:27.920 --> 30:41.780
However, maybe there's some efficiency consideration or to just only prevent that lock before the function tries to load the request module, the mutex lock will be released.

30:42.480 --> 30:44.700
But could it cause any problem?

30:47.080 --> 30:48.760
Back to the diagram.

30:48.820 --> 30:54.480
Now there's a little time window in the abort phase that it will not hold the mutex lock.

30:54.560 --> 31:04.360
So there's a chance during the abort phase, the GC check kicks in, recalls the expired element and do a GC sequence check.

31:04.720 --> 31:08.640
In this case, however, the check will be bypassed.

31:08.640 --> 31:13.260
And the GC thread can delete arbitrary expired elements.

31:16.770 --> 31:21.250
Okay, so now the question is, how do we actually exploit the race?

31:23.110 --> 31:28.790
Our exploit plan is first, we add a set element with a short timeout.

31:28.790 --> 31:35.370
And then we trigger module autoload to force it to revert the commit and free the element we just added.

31:35.750 --> 31:41.610
And at the same time, we trigger GC to collect that element.

31:43.950 --> 31:52.130
Next, module autoload will release the mutex and we hope that the GC thread will grab it and bypass the check.

31:52.890 --> 31:57.750
So as a result, the element we just added will be double free.

31:59.210 --> 32:05.070
But in order to trigger double free, there are two time windows we need to enlarge.

32:06.050 --> 32:11.290
The first time window is from the abort phase start to the set element released.

32:11.510 --> 32:17.820
So the GC thread can recall the expired element before they get a link by the revert procedure.

32:19.290 --> 32:24.130
The second time window is from the load module to its end.

32:24.130 --> 32:28.190
So the GC thread can grab the lock and bypass the check.

32:31.470 --> 32:43.690
For the first one, since the abort phase will revert the operations in reverse order, we add a bunch of requests after the add set element request to delay the link operation.

32:44.870 --> 32:51.150
For the second one, we just request multiple unknown type to make module autoload runs longer.

32:54.510 --> 32:56.270
And here's the demo.

32:58.190 --> 32:58.610
Okay.

32:58.610 --> 33:08.410
So first we boot our machine and check the UID is a normal user and then we run the exploit.

33:08.990 --> 33:14.970
So here we will first measure the execution time to set up timing parameter for the race.

33:15.570 --> 33:20.330
And after that, we set up the environment to enlarge the race time windows.

33:22.450 --> 33:28.030
Then we trigger double free to leak address and control IP.

33:28.970 --> 33:31.390
And we got the root shell.

33:37.220 --> 33:38.900
Thank you, guys.

33:40.860 --> 33:42.060
Great.

33:42.220 --> 33:46.900
So now I write the exploit and submit it to kernel CTF.

33:47.660 --> 33:50.360
And this is my kernel CTF submission.

33:50.840 --> 33:55.700
I exploited the LTS instance on kernel version 6.1.81.

33:55.720 --> 33:59.540
But as you can see, it is marked with a dupe in that line.

34:00.440 --> 34:06.760
It is because for every LTS slot, only the first zero day or one day exploit will be accepted.

34:06.960 --> 34:14.940
And there's someone who also submitted a LTS exploit which beat me by nine seconds.

34:16.080 --> 34:18.060
That's too bad.

34:18.720 --> 34:22.160
So we have to wait for the slot to reopen.

34:23.520 --> 34:29.540
So, yes, just wait for about two weeks and the slot will reopen.

34:30.080 --> 34:31.180
Right?

34:32.920 --> 34:35.280
Wait until it starts to reopen.

34:35.780 --> 34:36.560
Yep.

34:36.980 --> 34:41.160
But do you know the F table will be disabled for April 1st?

34:41.660 --> 34:42.600
What?

34:46.080 --> 34:48.780
Actually, there's an announcement on kernel CTF.

34:48.920 --> 34:55.240
It says they are going to disable NF tables along with the switch to kernel version 6.6.

34:55.240 --> 35:03.080
It starts from March 15th but actually they delay the switch so it's from April 1st.

35:03.160 --> 35:04.120
Okay.

35:04.120 --> 35:06.500
So what's the date today?

35:06.900 --> 35:09.960
It's actually March 22nd.

35:10.580 --> 35:21.240
And the kernel CTF slot opens about every two weeks on average which means I won't be able to exploit before they disable the NF tables.

35:21.880 --> 35:29.360
So on my third kernel CTF attempt, I still could not get a bounty which is pretty sad.

35:30.800 --> 35:38.920
To sum up my journey, first I have hope and then I found bug one, a lifetime issue.

35:39.380 --> 35:41.840
And it collides with another submission.

35:42.560 --> 35:46.360
Then I found the bug two, a hard to use one day.

35:46.780 --> 35:51.020
But I used the wrong config so it's unusable.

35:51.440 --> 35:55.600
Then I found the bug three, a locking issue.

35:56.300 --> 36:02.280
But I lose the submission race and NF table will be disabled so it's killed.

36:02.980 --> 36:06.600
However, there's a final plot twist.

36:10.370 --> 36:16.850
A few days after, I found there's some changes in the kernel CTF spreadsheet.

36:17.590 --> 36:25.190
The person who previously got ahead of me is disqualified due to a bug collision.

36:26.070 --> 36:32.390
And so this time, I finally take over the slot and report it to Google.

36:34.330 --> 36:41.050
And this month, I got my kernel CTF bounty from Google which is my first Google VIP bounty.

36:41.050 --> 36:42.870
I'm so proud of myself.

36:50.630 --> 36:51.590
Thanks.

36:51.810 --> 36:55.930
So, well, I think this concludes my kernel CTF journey.

36:56.430 --> 36:57.810
And thank you, guys.

37:05.110 --> 37:06.830
Is there any questions?

37:15.320 --> 37:18.560
Yeah, if there's any questions, you can come up here to this microphone.

37:37.670 --> 37:38.610
Thank you.

