[<prev] [next>] [day] [month] [year] [list]
Message-ID: <3a701a0.8f4a.196860948e3.Coremail.luckd0g@163.com>
Date: Wed, 30 Apr 2025 17:31:17 +0800 (CST)
From: "Jianzhou Zhao" <luckd0g@....com>
To: stable@...r.kernel.org
Cc: rostedt@...dmis.org, mhiramat@...nel.org, mathieu.desnoyers@...icios.com,
linux-kernel@...r.kernel.org, linux-trace-kernel@...r.kernel.org
Subject: KASAN: slab-use-after-free Read in perf_uprobe_destroy in
linux6.12.25(longterm maintenance)
Hello, I found a potential bug titled " KASAN: slab-use-after-free Read in perf_uprobe_destroy " with modified syzkaller in the Linux6.12.25(longterm maintenance, last updated on April 25, 2025)
If you fix this issue, please add the following tag to the commit: Reported-by: Jianzhou Zhao <luckd0g@....com>, xingwei lee <xrivendell7@...il.com>, Penglei Jiang <superman.xpt@...il.com>
The commit of the kernel is : ef4999852d307d38cfdecd91ed6892cc03beb9b8
kernel config: https://syzkaller.appspot.com/text?tag=KernelConfig&x=55f8591b98dd132
compiler: gcc version 11.4.0
I put the reproduction program of this bug at the end of the email.
------------[ cut here ]-----------------------------------------
TITLE: KASAN: slab-use-after-free Read in perf_uprobe_destroy
------------[ cut here ]------------
==================================================================
BUG: KASAN: slab-use-after-free in perf_trace_event_close kernel/trace/trace_event_perf.c:190 [inline]
BUG: KASAN: slab-use-after-free in perf_uprobe_destroy+0x1d6/0x200 kernel/trace/trace_event_perf.c:344
Read of size 8 at addr ffff888028f59060 by task syz.0.14/12239
CPU: 0 UID: 0 PID: 12239 Comm: syz.0.14 Not tainted 6.12.25 #1
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:94 [inline]
dump_stack_lvl+0x116/0x1b0 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:377 [inline]
print_report+0xc0/0x5e0 mm/kasan/report.c:488
kasan_report+0x93/0xc0 mm/kasan/report.c:601
perf_trace_event_close kernel/trace/trace_event_perf.c:190 [inline]
perf_uprobe_destroy+0x1d6/0x200 kernel/trace/trace_event_perf.c:344
__free_event+0x1d9/0x870 kernel/events/core.c:5330
perf_event_alloc kernel/events/core.c:12437 [inline]
perf_event_alloc+0x1246/0x37d0 kernel/events/core.c:12210
__do_sys_perf_event_open+0x44c/0x2aa0 kernel/events/core.c:12847
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xcf/0x250 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fb0d09ac5ad
Code: 02 b8 ff ff ff ff c3 66 0f 1f 44 00 00 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fb0d18f5f98 EFLAGS: 00000246 ORIG_RAX: 000000000000012a
RAX: ffffffffffffffda RBX: 00007fb0d0be5fa0 RCX: 00007fb0d09ac5ad
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000200000000040
RBP: 00007fb0d0a4458e R08: 000000000000000a R09: 0000000000000000
R10: ffffffffffffffff R11: 0000000000000246 R12: 0000000000000000
R13: 0000000000000000 R14: 00007fb0d0be5fa0 R15: 00007fb0d18d6000
</TASK>
Allocated by task 12239:
kasan_save_stack+0x24/0x50 mm/kasan/common.c:47
kasan_save_track+0x14/0x30 mm/kasan/common.c:68
poison_kmalloc_redzone mm/kasan/common.c:377 [inline]
__kasan_kmalloc+0xaa/0xb0 mm/kasan/common.c:394
kasan_kmalloc include/linux/kasan.h:260 [inline]
__kmalloc_cache_noprof+0x1a5/0x3e0 mm/slub.c:4327
kmalloc_noprof include/linux/slab.h:878 [inline]
kzalloc_noprof include/linux/slab.h:1014 [inline]
trace_probe_init+0xbc/0x5f0 kernel/trace/trace_probe.c:2050
alloc_trace_uprobe+0xa5/0x310 kernel/trace/trace_uprobe.c:347
create_local_trace_uprobe+0x10d/0x4c0 kernel/trace/trace_uprobe.c:1643
perf_uprobe_init+0x13a/0x220 kernel/trace/trace_event_perf.c:319
perf_uprobe_event_init+0x103/0x1d0 kernel/events/core.c:10715
perf_try_init_event+0x137/0xd70 kernel/events/core.c:11976
perf_init_event kernel/events/core.c:12064 [inline]
perf_event_alloc kernel/events/core.c:12345 [inline]
perf_event_alloc+0x101a/0x37d0 kernel/events/core.c:12210
__do_sys_perf_event_open+0x44c/0x2aa0 kernel/events/core.c:12847
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xcf/0x250 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 12239:
kasan_save_stack+0x24/0x50 mm/kasan/common.c:47
kasan_save_track+0x14/0x30 mm/kasan/common.c:68
kasan_save_free_info+0x3a/0x60 mm/kasan/generic.c:579
poison_slab_object mm/kasan/common.c:247 [inline]
__kasan_slab_free+0x54/0x70 mm/kasan/common.c:264
kasan_slab_free include/linux/kasan.h:233 [inline]
slab_free_hook mm/slub.c:2372 [inline]
slab_free mm/slub.c:4611 [inline]
kfree+0x14e/0x4a0 mm/slub.c:4759
trace_probe_unlink+0x185/0x200 kernel/trace/trace_probe.c:2016
trace_probe_cleanup+0x168/0x1d0 kernel/trace/trace_probe.c:2034
free_trace_uprobe.part.0+0x1b/0x80 kernel/trace/trace_uprobe.c:371
free_trace_uprobe kernel/trace/trace_uprobe.c:367 [inline]
destroy_local_trace_uprobe+0x5d/0x80 kernel/trace/trace_uprobe.c:1682
perf_try_init_event+0x44b/0xd70 kernel/events/core.c:12007
perf_init_event kernel/events/core.c:12064 [inline]
perf_event_alloc kernel/events/core.c:12345 [inline]
perf_event_alloc+0x101a/0x37d0 kernel/events/core.c:12210
__do_sys_perf_event_open+0x44c/0x2aa0 kernel/events/core.c:12847
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xcf/0x250 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x77/0x7f
The buggy address belongs to the object at ffff888028f59000
which belongs to the cache kmalloc-512 of size 512
The buggy address is located 96 bytes inside of
freed 512-byte region [ffff888028f59000, ffff888028f59200)
The buggy address belongs to the physical page:
page: refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x28f58
head: order:2 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0xfff00000000040(head|node=0|zone=1|lastcpupid=0x7ff)
page_type: f5(slab)
raw: 00fff00000000040 ffff88801b041c80 ffffea0000a70200 dead000000000002
raw: 0000000000000000 0000000000100010 00000001f5000000 0000000000000000
head: 00fff00000000040 ffff88801b041c80 ffffea0000a70200 dead000000000002
head: 0000000000000000 0000000000100010 00000001f5000000 0000000000000000
head: 00fff00000000002 ffffea0000a3d601 ffffffffffffffff 0000000000000000
head: 0000000000000004 0000000000000000 00000000ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 2, migratetype Unmovable, gfp_mask 0xd20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 9461, tgid 9461 (syz-executor), ts 105252344888, free_ts 105090780548
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook mm/page_alloc.c:1558 [inline]
prep_new_page+0x31b/0x3a0 mm/page_alloc.c:1566
get_page_from_freelist+0x19fb/0x33b0 mm/page_alloc.c:3476
__alloc_pages_noprof+0x324/0x6b0 mm/page_alloc.c:4754
alloc_pages_mpol_noprof+0x2ce/0x610 mm/mempolicy.c:2269
alloc_slab_page mm/slub.c:2442 [inline]
allocate_slab mm/slub.c:2608 [inline]
new_slab+0x253/0x430 mm/slub.c:2662
___slab_alloc+0xe1c/0x1720 mm/slub.c:3850
__slab_alloc.isra.0+0x56/0xb0 mm/slub.c:3940
__slab_alloc_node mm/slub.c:3993 [inline]
slab_alloc_node mm/slub.c:4154 [inline]
__kmalloc_cache_noprof+0x37f/0x3e0 mm/slub.c:4322
kmalloc_noprof include/linux/slab.h:878 [inline]
kzalloc_noprof include/linux/slab.h:1014 [inline]
fib6_info_alloc+0xc9/0x290 net/ipv6/ip6_fib.c:155
ip6_route_info_create+0x341/0x1610 net/ipv6/route.c:3802
ip6_route_add+0x26/0x160 net/ipv6/route.c:3896
addrconf_prefix_route.isra.0+0x302/0x510 net/ipv6/addrconf.c:2486
inet6_addr_add+0x73a/0xc10 net/ipv6/addrconf.c:3083
inet6_rtm_newaddr+0x116a/0x18b0 net/ipv6/addrconf.c:5068
rtnetlink_rcv_msg+0x3c9/0xfc0 net/core/rtnetlink.c:6678
netlink_rcv_skb+0x165/0x450 net/netlink/af_netlink.c:2537
page last free pid 9499 tgid 9499 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
free_pages_prepare mm/page_alloc.c:1127 [inline]
free_unref_page+0x799/0x1320 mm/page_alloc.c:2659
__put_partials+0x151/0x170 mm/slub.c:3177
qlink_free mm/kasan/quarantine.c:163 [inline]
qlist_free_all+0x50/0x130 mm/kasan/quarantine.c:179
kasan_quarantine_reduce+0x165/0x1c0 mm/kasan/quarantine.c:286
__kasan_slab_alloc+0x67/0x90 mm/kasan/common.c:329
kasan_slab_alloc include/linux/kasan.h:250 [inline]
slab_post_alloc_hook mm/slub.c:4117 [inline]
slab_alloc_node mm/slub.c:4166 [inline]
__kmalloc_cache_noprof+0x12a/0x3e0 mm/slub.c:4322
kmalloc_noprof include/linux/slab.h:878 [inline]
call_modprobe kernel/module/kmod.c:84 [inline]
__request_module+0x2a2/0x6b0 kernel/module/kmod.c:173
dev_load+0x1ff/0x240 net/core/dev_ioctl.c:645
dev_ioctl+0x518/0x10b0 net/core/dev_ioctl.c:709
sock_do_ioctl+0x1ca/0x260 net/socket.c:1241
sock_ioctl+0x23a/0x6c0 net/socket.c:1346
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:907 [inline]
__se_sys_ioctl fs/ioctl.c:893 [inline]
__x64_sys_ioctl+0x19d/0x210 fs/ioctl.c:893
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xcf/0x250 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Memory state around the buggy address:
ffff888028f58f00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff888028f58f80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff888028f59000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff888028f59080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888028f59100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <dirent.h>
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/prctl.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
static void sleep_ms(uint64_t ms)
{
usleep(ms * 1000);
}
static uint64_t current_time_ms(void)
{
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts))
exit(1);
return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
}
#define BITMASK(bf_off, bf_len) (((1ull << (bf_len)) - 1) << (bf_off))
#define STORE_BY_BITMASK(type, htobe, addr, val, bf_off, bf_len) \
*(type*)(addr) = \
htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | \
(((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len))))
static bool write_file(const char* file, const char* what, ...)
{
char buf[1024];
va_list args;
va_start(args, what);
vsnprintf(buf, sizeof(buf), what, args);
va_end(args);
buf[sizeof(buf) - 1] = 0;
int len = strlen(buf);
int fd = open(file, O_WRONLY | O_CLOEXEC);
if (fd == -1)
return false;
if (write(fd, buf, len) != len) {
int err = errno;
close(fd);
errno = err;
return false;
}
close(fd);
return true;
}
static void kill_and_wait(int pid, int* status)
{
kill(-pid, SIGKILL);
kill(pid, SIGKILL);
for (int i = 0; i < 100; i++) {
if (waitpid(-1, status, WNOHANG | __WALL) == pid)
return;
usleep(1000);
}
DIR* dir = opendir("/sys/fs/fuse/connections");
if (dir) {
for (;;) {
struct dirent* ent = readdir(dir);
if (!ent)
break;
if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
continue;
char abort[300];
snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort",
ent->d_name);
int fd = open(abort, O_WRONLY);
if (fd == -1) {
continue;
}
if (write(fd, abort, 1) < 0) {
}
close(fd);
}
closedir(dir);
} else {
}
while (waitpid(-1, status, __WALL) != pid) {
}
}
static void setup_test()
{
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setpgrp();
write_file("/proc/self/oom_score_adj", "1000");
}
static void execute_one(void);
#define WAIT_FLAGS __WALL
static void loop(void)
{
int iter = 0;
for (;; iter++) {
int pid = fork();
if (pid < 0)
exit(1);
if (pid == 0) {
setup_test();
execute_one();
exit(0);
}
int status = 0;
uint64_t start = current_time_ms();
for (;;) {
sleep_ms(10);
if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
break;
if (current_time_ms() - start < 5000)
continue;
kill_and_wait(pid, &status);
break;
}
}
}
void execute_one(void)
{
if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {
}
memcpy((void*)0x200000000000, ".pending_reads\000", 15);
syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x200000000000ul,
/*flags=O_SYNC|O_NOATIME|O_LARGEFILE|O_CREAT|O_APPEND*/ 0x149440,
/*mode=*/0);
*(uint32_t*)0x200000000040 = 8;
*(uint32_t*)0x200000000044 = 0x80;
*(uint8_t*)0x200000000048 = 2;
*(uint8_t*)0x200000000049 = 0;
*(uint8_t*)0x20000000004a = 0;
*(uint8_t*)0x20000000004b = 0;
*(uint32_t*)0x20000000004c = 0;
*(uint64_t*)0x200000000050 = 0;
*(uint64_t*)0x200000000058 = 0x6a484;
*(uint64_t*)0x200000000060 = 4;
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 0, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 1, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 2, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 3, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 4, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 5, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 6, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 7, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 8, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 9, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 10, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 11, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 12, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 13, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 14, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 15, 2);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 17, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 18, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 1, 19, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 20, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 21, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 22, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 23, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 24, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 25, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 26, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 27, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 28, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 29, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 30, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 31, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 32, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 33, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 34, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 35, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 36, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 37, 1);
STORE_BY_BITMASK(uint64_t, , 0x200000000068, 0, 38, 26);
*(uint32_t*)0x200000000070 = 7;
*(uint32_t*)0x200000000074 = 0;
*(uint64_t*)0x200000000078 = 0x200000000000;
*(uint64_t*)0x200000000080 = 0;
*(uint64_t*)0x200000000088 = 0;
*(uint64_t*)0x200000000090 = 0;
*(uint32_t*)0x200000000098 = 0;
*(uint32_t*)0x20000000009c = 0;
*(uint64_t*)0x2000000000a0 = 0x40000000000000;
*(uint32_t*)0x2000000000a8 = 0;
*(uint16_t*)0x2000000000ac = 0;
*(uint16_t*)0x2000000000ae = 0;
*(uint32_t*)0x2000000000b0 = 9;
*(uint32_t*)0x2000000000b4 = 0;
*(uint64_t*)0x2000000000b8 = 0;
syscall(__NR_perf_event_open, /*attr=*/0x200000000040ul, /*pid=*/0,
/*cpu=*/0ul, /*group=*/-1,
/*flags=PERF_FLAG_FD_CLOEXEC|PERF_FLAG_FD_OUTPUT*/ 0xaul);
}
int main(void)
{
syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul,
/*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1,
/*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000ul,
/*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul,
/*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1,
/*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000ul, /*prot=*/0ul,
/*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1,
/*offset=*/0ul);
const char* reason;
(void)reason;
loop();
return 0;
}
===================================================================
I hope it helps.
Best regards
Jianzhou Zhao
Powered by blists - more mailing lists