作者: Byte Reaper
此POC尝试利用CVE-2025-39866漏洞,该漏洞是Linux系统< 6.12.16中的一个缺陷,由于缺少线程自旋锁而导致竞态条件。第一个线程尝试使用wb结构体,而第二个线程释放该结构体,导致第一个线程处理一个释放后的指针,进而引发系统内核恐慌。我们可以将利用该漏洞的思路分为以下几个阶段:
step 1 : Create thread 1 "main pid"
- get root dentry
- create file txt writeback target
- create strcut inode
- Create object wb
- save pointer wb in wb_old
Step 2:
- Create Thread 2 (kthread) that schedules a work item.
- The work item runs “inode_switch_wbs_work_fn” which updates “inode->i_wb” and schedules the critical free via “wb_put_many”.
step 3 :
- thread 2 : free wb_olb
- thread 1 -> pointer - free object wb (free old)
-> access free address -> crash kernel (segfault)
Linux x86_64
kernel linux < 6.12.16
1 - He created a Makefile and included these commands to compile and build the kernel module:
obj-m += exploit.o
KDIR := /usr/src/linux-headers-6.12.38+kali-amd64
PWD := $(shell pwd)
all:
make -C $(KDIR) M=$(PWD) modules
clean:
make -C $(KDIR) M=$(PWD) clean
# make clean
# make
1 - You will find a file named "exploit.ko," which is a kernel module. To load it into the kernel space, use the insmod tool :
# insmod exploit.ko
该错误的主要问题在于缺少用于线程同步的“自旋锁”。解决方案如下:
第一(Slab/Slub 分配):为每个线程分配一个特定的 slab/slub,没有线程可以控制或操纵另一个线程的内存大小。
第二(同步):配置工作队列以避免干扰和竞态条件,让每个线程完成自己的任务后切换到另一个线程,而不是同时切换 WB 或使用 wb_wakeup_delayed 函数。
第三(HLE/RTM):在内核中激活 HLE/RTM 取决于处理器架构,但如果处理器支持这两个特性,为何不在内核中使用它们呢?例如,在控制程序流时,或在发生错误时尝试回滚到另一个异常而不是使系统崩溃,通过 XBEGIN、XABORT、XEN 等指令实现“回滚”。
MIT