Setup
Link to the original vulnerability report can be found here.a
Setting up environment
To get up and running as quick as possible, setup your environment as follows:
|
|
Then download the most recent affected version:
Building
Make a default config with:
|
|
and then nf_tables
support with:
|
|
I also have a working config here (will add soon once post is finished).
Then build the kernel with:
|
|
Then we also need to setup directories for libguestfs
to work properly.
|
|
Then
|
|
Then run this script:
|
|
This will create an unprivileged user as well as set passwords.
Getting Exploit
Download Google’s security-research
repo into your host, and modify pocs/linux/kernelctf/CVE-2024-0193_cos/exploit/cos-105-17412.226.52/Makefile
by adding -g
to CFLAGS
and removing the -s
flag.
Then copy it over to your qemu container with:
|
|
GDB and QEMU
Follow this guide to create a bridged network between qemu and your host.
In order to connect GDB to this container, run the following command and login as root:
|
|
Once inside, run:
|
|
This should give you an IP address. Now we have to install gdb for debugging userspace code.
|
|
Then build the exploit from whatever directory you copied it into:
|
|
Then run gdb:
|
|
Getting load address
Next, we have load the symbols from vmlinux
into gdb at the correct address.
After you have gotten a shell in qemu as root, run:
|
|
This will give you the address of the strncpy_from_user
function.
You can of course use any function, but this is the one I chose for my example.
You will see the address at which the function is loaded.
I know from my own testing and calculations that strncpy_from_user
is 0x548170
bytes from the load address.
So whatever address you got from kallsyms
, just subtract this amount from it, and you will get your load address.
Then you can load in the symbols file with:
|
|
Background
So I will be using the following versions:
libnftnl
: libnftnl-1.2.6
pipapo
“Pipelined Adaptive Packet Process”, and a pipapo set refers to a specific data struct used for efficiently storing and looking up elements. It provides fast lookup and is built for handling large sets of elements.
nftnl_table
ntfnl_table_set_str
|
|
Vulnerability
In the exploit given, the creates sets set1
and set2
, with catchall elements set1_elem
and set2_elem
respectively.
They are then deleted by building and sending a NFT_MSG_DELSET
type Netlink message, which deactivates the data of the set elements.
Then the catchall element should be GC’d (garbage collected), which deactivates its data again, resulting ins a double free.
This is achieved by setting a short timeout on a set element. Timeouts determine how long that element needs to stay in the set before it gets automatically removed. Then create the delay. Then delete the vulnerable pipapo set. We can break it down in GDB to match the sections in the original disclosure.
Triggering:
Set breakpoints at nftnl_set_alloc
.