Skip to content

Commit 94a696f

Browse files
G0RiyAclaude
andcommitted
Add kernelCTF CVE-2026-23278_cos (#exp462)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6226291 commit 94a696f

7 files changed

Lines changed: 1738 additions & 0 deletions

File tree

pocs/linux/kernelctf/CVE-2026-23278_cos/docs/exploit.md

Lines changed: 635 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Vulnerability
2+
3+
A use-after-free vulnerability was found in the Linux kernel's Netfilter nf_tables subsystem (`net/netfilter/nf_tables_api.c`). A `break` statement in both `nft_map_catchall_deactivate()` and `nft_map_catchall_activate()` causes incomplete processing when two catchall elements coexist in a verdict map during the same transaction. When the set is also being deleted in the same batch, the `break` causes the second catchall element's chain reference to be mismanaged during the abort path, leading to a `chain->use` counter underflow to zero and a subsequent use-after-free of the `nft_chain` object. This leads to local privilege escalation (LPE).
4+
5+
## Requirements to trigger the vulnerability:
6+
- Capabilities: To trigger the vulnerability, `CAP_NET_ADMIN` capability is required to access the Netfilter system.
7+
- Kernel configuration: Kernel configs related to the Netfilter nf_tables system (e.g., `CONFIG_NETFILTER`, `CONFIG_NF_TABLES`) are required to trigger this vulnerability. This config is generally enabled by default (ex. x86_64_defconfig).
8+
- Are user namespaces needed?: Yes. As this vulnerability requires `CAP_NET_ADMIN`, which is not usually given to the normal user, we used the unprivileged user namespace to achieve this capability.
9+
10+
## Commit which introduced the vulnerability
11+
- This vulnerability was introduced in Linux v6.4, with commit [628bd3e49cba1c066228e23d71a852c23e26da73](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=628bd3e49cba1c066228e23d71a852c23e26da73)
12+
- This commit ("netfilter: nf_tables: drop map element references from preparation phase") restructured the handling of map element data references such that a pending `DELSETELEM` and a `NEWSETELEM` in the same batch can both leave catchall elements in the set's `catchall_list` simultaneously, exposing the latent `break`-statement bug in `nft_map_catchall_deactivate()` and `nft_map_catchall_activate()`.
13+
14+
## Commit which fixed the vulnerability
15+
- This vulnerability was fixed with commit [7cb9a23d7ae40a702577d3d8bacb7026f04ac2a9](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=7cb9a23d7ae40a702577d3d8bacb7026f04ac2a9) ("netfilter: nf_tables: always walk all pending catchall elements"), which removes the `break` statements from both `nft_map_catchall_deactivate()` and `nft_map_catchall_activate()` so that all catchall elements are processed — not just the first matching one — when a verdict map containing multiple pending catchalls is toggled during a transaction.
16+
17+
## Affected kernel versions
18+
- Linux versions containing commit 628bd3e49cba and lacking the fix ("netfilter: nf_tables: always walk all pending catchall elements") are affected.
19+
20+
## Affected component, subsystem
21+
- net/netfilter (nf_tables)
22+
23+
## Cause (UAF, BoF, race condition, double free, refcount overflow, etc)
24+
- Use-after-free (`chain->use` counter underflow to zero via incomplete catchall processing → premature `kfree` of `nft_chain`)
25+
26+
## Which syscalls or syscall parameters are needed to be blocked to prevent triggering the vulnerability? (If there is any easy way to block it.)
27+
- Disable syscalls for Netfilter (specifically, Netfilter nf_tables) system (ex. `socket`, `sendmsg` with Netlink socket) to prevent this vulnerability.
28+
- Disable syscalls for unprivileged user namespace (ex. `clone`, `unshare`) can reduce the attack surface since the Netfilter system requires `CAP_NET_ADMIN` to use.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
CC = g++
2+
SRCS := ./exploit.cpp
3+
TARGET := exploit
4+
LIBMNL_DIR = $(realpath ./)/libmnl_build
5+
LIBNFTNL_DIR = $(realpath ./)/libnftnl_build
6+
LIBXDK_DIR = $(realpath ./)/libxdk_build
7+
8+
CFLAGS = -w -static -Wall -fpermissive
9+
LIBS = -L$(LIBMNL_DIR)/install/usr/local/lib -L$(LIBNFTNL_DIR)/install/usr/local/lib -L$(LIBXDK_DIR)/lib -lnftnl -lmnl -lkernelXDK -lkeyutils
10+
INCLUDES = -I$(LIBMNL_DIR)/install/usr/local/include -I$(LIBNFTNL_DIR)/install/usr/local/include -I$(LIBXDK_DIR)/include
11+
12+
$(TARGET) : libmnl-build libnftnl-build libxdk-build target_db.kxdb
13+
$(CC) $(CFLAGS) $(SRCS) -o $(TARGET) $(INCLUDES) $(LIBS)
14+
15+
libmnl-build : libmnl-download
16+
tar -C $(LIBMNL_DIR) -xvf $(LIBMNL_DIR)/libmnl-1.0.5.tar.bz2
17+
cd $(LIBMNL_DIR)/libmnl-1.0.5 && ./configure --enable-static
18+
cd $(LIBMNL_DIR)/libmnl-1.0.5 && make -j`nproc`
19+
cd $(LIBMNL_DIR)/libmnl-1.0.5 && mkdir ../install && make DESTDIR=`realpath ../install` install
20+
21+
libnftnl-build : libmnl-build libnftnl-download
22+
tar -C $(LIBNFTNL_DIR) -xvf $(LIBNFTNL_DIR)/libnftnl-1.2.1.tar.bz2
23+
cd $(LIBNFTNL_DIR)/libnftnl-1.2.1 && PKG_CONFIG_PATH=$(LIBMNL_DIR)/install/usr/local/lib/pkgconfig ./configure --enable-static
24+
cd $(LIBNFTNL_DIR)/libnftnl-1.2.1 && C_INCLUDE_PATH=$(C_INCLUDE_PATH):$(LIBMNL_DIR)/install/usr/local/include LD_LIBRARY_PATH=$(LD_LIBRARY_PATH):$(LIBMNL_DIR)/install/usr/local/lib make -j`nproc`
25+
cd $(LIBNFTNL_DIR)/libnftnl-1.2.1 && mkdir ../install && make DESTDIR=`realpath ../install` install
26+
27+
libmnl-download :
28+
mkdir $(LIBMNL_DIR)
29+
wget -P $(LIBMNL_DIR) https://netfilter.org/projects/libmnl/files/libmnl-1.0.5.tar.bz2
30+
31+
libnftnl-download :
32+
mkdir $(LIBNFTNL_DIR)
33+
wget -P $(LIBNFTNL_DIR) https://netfilter.org/projects/libnftnl/files/libnftnl-1.2.1.tar.bz2
34+
35+
libxdk-build :
36+
mkdir -p $(LIBXDK_DIR)
37+
wget -O $(LIBXDK_DIR)/libxdk-v0.1.tar.gz https://github.com/google/kernel-research/releases/download/libxdk/v0.1/libxdk-v0.1.tar.gz
38+
tar -C $(LIBXDK_DIR) -xzf $(LIBXDK_DIR)/libxdk-v0.1.tar.gz
39+
40+
target_db.kxdb :
41+
wget -O target_db.kxdb https://storage.googleapis.com/kernelxdk/db/kernelctf.kxdb
42+
43+
.PHONY: libmnl-build libnftnl-build libxdk-build libmnl-download libnftnl-download clean
44+
45+
clean:
46+
rm -f $(TARGET)
47+
if [ -d $(LIBMNL_DIR)/libmnl-1.0.5 ]; then cd $(LIBMNL_DIR)/libmnl-1.0.5 && make DESTDIR=`realpath ../install` uninstall; fi
48+
if [ -d $(LIBNFTNL_DIR)/libnftnl-1.2.1 ]; then cd $(LIBNFTNL_DIR)/libnftnl-1.2.1 && make DESTDIR=`realpath ../install` uninstall; fi
49+
rm -rf $(LIBMNL_DIR)
50+
rm -rf $(LIBNFTNL_DIR)
51+
rm -rf $(LIBXDK_DIR)
52+
rm -f target_db.kxdb
Binary file not shown.

0 commit comments

Comments
 (0)