[syzbot] [bpf?] [net?] possible deadlock in sock_hash_delete_elem (2)

13 views
Skip to first unread message

syzbot

unread,
Mar 19, 2024, 2:11:27 PMMar 19
to and...@kernel.org, a...@kernel.org, b...@vger.kernel.org, dan...@iogearbox.net, da...@davemloft.net, edum...@google.com, ja...@cloudflare.com, john.fa...@gmail.com, ku...@kernel.org, linux-...@vger.kernel.org, net...@vger.kernel.org, pab...@redhat.com, syzkall...@googlegroups.com
Hello,

syzbot found the following issue on:

HEAD commit: 0740b6427e90 Merge branch 'bpf-arena-followups'
git tree: bpf
console output: https://syzkaller.appspot.com/x/log.txt?x=11b90ac9180000
kernel config: https://syzkaller.appspot.com/x/.config?x=6fb1be60a193d440
dashboard link: https://syzkaller.appspot.com/bug?extid=ec941d6e24f633a59172
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40

Unfortunately, I don't have any reproducer for this issue yet.

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/c9e6e9f97566/disk-0740b642.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/78476a588b62/vmlinux-0740b642.xz
kernel image: https://storage.googleapis.com/syzbot-assets/50cd6fab9ead/bzImage-0740b642.xz

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+ec941d...@syzkaller.appspotmail.com

============================================
WARNING: possible recursive locking detected
6.8.0-syzkaller-05226-g0740b6427e90 #0 Not tainted
--------------------------------------------
syz-executor.4/13471 is trying to acquire lock:
ffff888034bc90f8 (&htab->buckets[i].lock){+.-.}-{2:2}, at: spin_lock_bh include/linux/spinlock.h:356 [inline]
ffff888034bc90f8 (&htab->buckets[i].lock){+.-.}-{2:2}, at: sock_hash_delete_elem+0xb0/0x300 net/core/sock_map.c:939

but task is already holding lock:
ffff888063a77968 (&htab->buckets[i].lock){+.-.}-{2:2}, at: spin_lock_bh include/linux/spinlock.h:356 [inline]
ffff888063a77968 (&htab->buckets[i].lock){+.-.}-{2:2}, at: sock_hash_update_common+0x20c/0xa30 net/core/sock_map.c:1007

other info that might help us debug this:
Possible unsafe locking scenario:

CPU0
----
lock(&htab->buckets[i].lock);
lock(&htab->buckets[i].lock);

*** DEADLOCK ***

May be due to missing lock nesting notation

5 locks held by syz-executor.4/13471:
#0: ffff888065685258 (sk_lock-AF_UNIX){+.+.}-{0:0}, at: lock_sock include/net/sock.h:1671 [inline]
#0: ffff888065685258 (sk_lock-AF_UNIX){+.+.}-{0:0}, at: sock_map_sk_acquire net/core/sock_map.c:117 [inline]
#0: ffff888065685258 (sk_lock-AF_UNIX){+.+.}-{0:0}, at: sock_map_update_elem_sys+0x1cc/0x910 net/core/sock_map.c:575
#1: ffffffff8e131920 (rcu_read_lock){....}-{1:2}, at: rcu_lock_acquire include/linux/rcupdate.h:298 [inline]
#1: ffffffff8e131920 (rcu_read_lock){....}-{1:2}, at: rcu_read_lock include/linux/rcupdate.h:750 [inline]
#1: ffffffff8e131920 (rcu_read_lock){....}-{1:2}, at: sock_map_sk_acquire net/core/sock_map.c:118 [inline]
#1: ffffffff8e131920 (rcu_read_lock){....}-{1:2}, at: sock_map_update_elem_sys+0x1d8/0x910 net/core/sock_map.c:575
#2: ffff888063a77968 (&htab->buckets[i].lock){+.-.}-{2:2}, at: spin_lock_bh include/linux/spinlock.h:356 [inline]
#2: ffff888063a77968 (&htab->buckets[i].lock){+.-.}-{2:2}, at: sock_hash_update_common+0x20c/0xa30 net/core/sock_map.c:1007
#3: ffff88803bbbc290 (&psock->link_lock){+...}-{2:2}, at: spin_lock_bh include/linux/spinlock.h:356 [inline]
#3: ffff88803bbbc290 (&psock->link_lock){+...}-{2:2}, at: sock_map_del_link net/core/sock_map.c:145 [inline]
#3: ffff88803bbbc290 (&psock->link_lock){+...}-{2:2}, at: sock_map_unref+0xcc/0x5e0 net/core/sock_map.c:180
#4: ffffffff8e131920 (rcu_read_lock){....}-{1:2}, at: rcu_lock_acquire include/linux/rcupdate.h:298 [inline]
#4: ffffffff8e131920 (rcu_read_lock){....}-{1:2}, at: rcu_read_lock include/linux/rcupdate.h:750 [inline]
#4: ffffffff8e131920 (rcu_read_lock){....}-{1:2}, at: __bpf_trace_run kernel/trace/bpf_trace.c:2380 [inline]
#4: ffffffff8e131920 (rcu_read_lock){....}-{1:2}, at: bpf_trace_run2+0x114/0x420 kernel/trace/bpf_trace.c:2420

stack backtrace:
CPU: 0 PID: 13471 Comm: syz-executor.4 Not tainted 6.8.0-syzkaller-05226-g0740b6427e90 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 02/29/2024
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0x1e7/0x2e0 lib/dump_stack.c:106
check_deadlock kernel/locking/lockdep.c:3062 [inline]
validate_chain+0x15c1/0x58e0 kernel/locking/lockdep.c:3856
__lock_acquire+0x1346/0x1fd0 kernel/locking/lockdep.c:5137
lock_acquire+0x1e4/0x530 kernel/locking/lockdep.c:5754
__raw_spin_lock_bh include/linux/spinlock_api_smp.h:126 [inline]
_raw_spin_lock_bh+0x35/0x50 kernel/locking/spinlock.c:178
spin_lock_bh include/linux/spinlock.h:356 [inline]
sock_hash_delete_elem+0xb0/0x300 net/core/sock_map.c:939
bpf_prog_2c29ac5cdc6b1842+0x42/0x46
bpf_dispatcher_nop_func include/linux/bpf.h:1234 [inline]
__bpf_prog_run include/linux/filter.h:657 [inline]
bpf_prog_run include/linux/filter.h:664 [inline]
__bpf_trace_run kernel/trace/bpf_trace.c:2381 [inline]
bpf_trace_run2+0x204/0x420 kernel/trace/bpf_trace.c:2420
trace_kfree include/trace/events/kmem.h:94 [inline]
kfree+0x291/0x380 mm/slub.c:4396
sk_psock_free_link include/linux/skmsg.h:421 [inline]
sock_map_del_link net/core/sock_map.c:158 [inline]
sock_map_unref+0x3ac/0x5e0 net/core/sock_map.c:180
sock_hash_update_common+0x915/0xa30 net/core/sock_map.c:1030
sock_map_update_elem_sys+0x5a4/0x910 net/core/sock_map.c:581
map_update_elem+0x53a/0x6f0 kernel/bpf/syscall.c:1641
__sys_bpf+0x76f/0x810 kernel/bpf/syscall.c:5619
__do_sys_bpf kernel/bpf/syscall.c:5738 [inline]
__se_sys_bpf kernel/bpf/syscall.c:5736 [inline]
__x64_sys_bpf+0x7c/0x90 kernel/bpf/syscall.c:5736
do_syscall_64+0xfb/0x240
entry_SYSCALL_64_after_hwframe+0x6d/0x75
RIP: 0033:0x7f9112c7dda9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 e1 20 00 00 90 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 b0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f9113a9f0c8 EFLAGS: 00000246 ORIG_RAX: 0000000000000141
RAX: ffffffffffffffda RBX: 00007f9112dabf80 RCX: 00007f9112c7dda9
RDX: 0000000000000020 RSI: 0000000020000180 RDI: 0000000000000002
RBP: 00007f9112cca47a R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 000000000000000b R14: 00007f9112dabf80 R15: 00007ffdf604c018
</TASK>


---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzk...@googlegroups.com.

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.

If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title

If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)

If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report

If you want to undo deduplication, reply with:
#syz undup

xingwei lee

unread,
Mar 21, 2024, 4:42:31 AMMar 21
to syzbot+ec941d...@syzkaller.appspotmail.com, and...@kernel.org, a...@kernel.org, b...@vger.kernel.org, dan...@iogearbox.net, da...@davemloft.net, Eric Dumazet, ja...@cloudflare.com, john.fa...@gmail.com, ku...@kernel.org, linux-...@vger.kernel.org, net...@vger.kernel.org, pab...@redhat.com, syzkall...@googlegroups.com
Hello, I reproduced this bug and comfired in the latest net/bpf tree.

If you fix this issue, please add the following tag to the commit:
Reported-by: xingwei lee <xrive...@gmail.com>
Reported-by: yue sun <samsun...@gmail.com>

BTW, in the reproducing prograss, other crash titles may aslo related
to this issue:
WARNING in sock_hash_delete_elem
possible deadlock in hrtimer_start_range_ns
possible deadlock in hrtimer_start_range_ns
WARNING in hrtimer_interrupt
kernel BUG in irq_work_run_list
invalid opcode in irq_work_run_list
...

kernel version: bpf tree 114b5b3b4bde7358624437be2f12cde1b265224e
kernel config: https://syzkaller.appspot.com/text?tag=KernelConfig&x=5c1d7ee7e74661a8
with KASAN enabled
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40

WARNING: possible circular locking dependency detected
6.8.0 #1 Not tainted
------------------------------------------------------
80aaaa/8172 is trying to acquire lock:
ffff88814e959c20 (&htab->buckets[i].lock
){+...}-{2:2}, at: spin_lock_bh include/linux/spinlock.h:356 [inline]
){+...}-{2:2}, at: sock_hash_delete_elem+0xb5/0x320 net/core/sock_map.c:939
but task is already holding lock:
ffff8880b952c8d8 (
hrtimer_bases.lock
){-.-.}-{2:2}
, at: lock_hrtimer_base kernel/time/hrtimer.c:175 [inline]
, at: hrtimer_start_range_ns+0xea/0xc90 kernel/time/hrtimer.c:1303
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #2 (
hrtimer_bases.lock
){-.-.}-{2:2}
:
lock_acquire+0x1e4/0x530 kernel/locking/lockdep.c:5754
__raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:110 [inline]
_raw_spin_lock_irqsave+0xd5/0x120 kernel/locking/spinlock.c:162
lock_hrtimer_base kernel/time/hrtimer.c:175 [inline]
hrtimer_start_range_ns+0xea/0xc90 kernel/time/hrtimer.c:1303
hrtimer_start include/linux/hrtimer.h:275 [inline]
run_page_cache_worker kernel/rcu/tree.c:3341 [inline]
kvfree_call_rcu+0x5e6/0x790 kernel/rcu/tree.c:3446
rtnl_register_internal+0x4ad/0x5d0 net/core/rtnetlink.c:265
rtnl_register+0x3b/0x80 net/core/rtnetlink.c:315
ip_rt_init+0x302/0x3b0 net/ipv4/route.c:3719
ip_init+0x13/0x20 net/ipv4/ip_output.c:1664
inet_init+0x3f1/0x5a0 net/ipv4/af_inet.c:2022
do_one_initcall+0x250/0x880 init/main.c:1241
do_initcall_level+0x164/0x220 init/main.c:1303
do_initcalls+0x48/0x90 init/main.c:1319
kernel_init_freeable+0x455/0x5f0 init/main.c:1557
kernel_init+0x22/0x2c0 init/main.c:1446
ret_from_fork+0x52/0x80 arch/x86/kernel/process.c:147
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:243
-> #1
(
krc.lock
){..-.}-{2:2}
:
lock_acquire+0x1e4/0x530 kernel/locking/lockdep.c:5754
__raw_spin_lock include/linux/spinlock_api_smp.h:133 [inline]
_raw_spin_lock+0x2e/0x40 kernel/locking/spinlock.c:154
krc_this_cpu_lock kernel/rcu/tree.c:2960 [inline]
add_ptr_to_bulk_krc_lock kernel/rcu/tree.c:3359 [inline]
kvfree_call_rcu+0x18a/0x790 kernel/rcu/tree.c:3444
sock_hash_free_elem net/core/sock_map.c:900 [inline]
sock_hash_delete_from_link net/core/sock_map.c:923 [inline]
sock_map_unlink net/core/sock_map.c:1566 [inline]
sock_map_remove_links+0x497/0x580 net/core/sock_map.c:1578
sock_map_close+0x12b/0x2f0 net/core/sock_map.c:1643
inet_release+0x191/0x210 net/ipv4/af_inet.c:437
__sock_release net/socket.c:659 [inline]
sock_close+0xc3/0x250 net/socket.c:1421
__fput+0x442/0x8d0 fs/file_table.c:423
task_work_run+0x25c/0x320 kernel/task_work.c:180
exit_task_work include/linux/task_work.h:38 [inline]
do_exit+0xa46/0x28a0 kernel/exit.c:878
do_group_exit+0x20b/0x2c0 kernel/exit.c:1027
get_signal+0x17ef/0x18d0 kernel/signal.c:2907
arch_do_signal_or_restart+0x9b/0x890 arch/x86/kernel/signal.c:310
exit_to_user_mode_loop kernel/entry/common.c:105 [inline]
exit_to_user_mode_prepare include/linux/entry-common.h:328 [inline]
__syscall_exit_to_user_mode_work kernel/entry/common.c:201 [inline]
syscall_exit_to_user_mode+0xc9/0x360 kernel/entry/common.c:212
do_syscall_64+0x10a/0x240 arch/x86/entry/common.c:89
entry_SYSCALL_64_after_hwframe+0x6d/0x75
-> #0


=* repro.c =*
#define _GNU_SOURCE

#include <endian.h>
#include <errno.h>
#include <pthread.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>

#include <linux/futex.h>

#ifndef __NR_bpf
#define __NR_bpf 321
#endif

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;
}

static void thread_start(void* (*fn)(void*), void* arg) {
pthread_t th;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, 128 << 10);
int i = 0;
for (; i < 100; i++) {
if (pthread_create(&th, &attr, fn, arg) == 0) {
pthread_attr_destroy(&attr);
return;
}
if (errno == EAGAIN) {
usleep(50);
continue;
}
break;
}
exit(1);
}

#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))))

typedef struct {
int state;
} event_t;

static void event_init(event_t* ev) {
ev->state = 0;
}

static void event_reset(event_t* ev) {
ev->state = 0;
}

static void event_set(event_t* ev) {
if (ev->state)
exit(1);
__atomic_store_n(&ev->state, 1, __ATOMIC_RELEASE);
syscall(SYS_futex, &ev->state, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, 1000000);
}

static void event_wait(event_t* ev) {
while (!__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE))
syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, 0);
}

static int event_isset(event_t* ev) {
return __atomic_load_n(&ev->state, __ATOMIC_ACQUIRE);
}

static int event_timedwait(event_t* ev, uint64_t timeout) {
uint64_t start = current_time_ms();
uint64_t now = start;
for (;;) {
uint64_t remain = timeout - (now - start);
struct timespec ts;
ts.tv_sec = remain / 1000;
ts.tv_nsec = (remain % 1000) * 1000 * 1000;
syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, &ts);
if (__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE))
return 1;
now = current_time_ms();
if (now - start > timeout)
return 0;
}
}

struct thread_t {
int created, call;
event_t ready, done;
};

static struct thread_t threads[16];
static void execute_call(int call);
static int running;

static void* thr(void* arg) {
struct thread_t* th = (struct thread_t*)arg;
for (;;) {
event_wait(&th->ready);
event_reset(&th->ready);
execute_call(th->call);
__atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED);
event_set(&th->done);
}
return 0;
}

static void loop(void) {
int i, call, thread;
for (call = 0; call < 11; call++) {
for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0]));
thread++) {
struct thread_t* th = &threads[thread];
if (!th->created) {
th->created = 1;
event_init(&th->ready);
event_init(&th->done);
event_set(&th->done);
thread_start(thr, th);
}
if (!event_isset(&th->done))
continue;
event_reset(&th->done);
th->call = call;
__atomic_fetch_add(&running, 1, __ATOMIC_RELAXED);
event_set(&th->ready);
event_timedwait(&th->done, 50 + (call == 0 ? 500 : 0) +
(call == 5 ? 500 : 0) +
(call == 10 ? 500 : 0));
break;
}
}
for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++)
sleep_ms(1);
}

uint64_t r[5] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff,
0xffffffffffffffff, 0xffffffffffffffff};

void execute_call(int call) {
intptr_t res = 0;
switch (call) {
case 0:
*(uint32_t*)0x20002c80 = 3;
*(uint32_t*)0x20002c84 = 5;
*(uint64_t*)0x20002c88 = 0x20000340;
sprintf((char*)0x20000340, "%020llu", (long long)0);
*(uint64_t*)0x20002c90 = 0x20000080;
memcpy((void*)0x20000080, "GPL\000", 4);
*(uint32_t*)0x20002c98 = 4;
*(uint32_t*)0x20002c9c = 0;
*(uint64_t*)0x20002ca0 = 0;
*(uint32_t*)0x20002ca8 = 0;
*(uint32_t*)0x20002cac = 0;
memset((void*)0x20002cb0, 0, 16);
*(uint32_t*)0x20002cc0 = 0;
*(uint32_t*)0x20002cc4 = 0;
*(uint32_t*)0x20002cc8 = -1;
*(uint32_t*)0x20002ccc = 8;
*(uint64_t*)0x20002cd0 = 0;
*(uint32_t*)0x20002cd8 = 0;
*(uint32_t*)0x20002cdc = 0x10;
*(uint64_t*)0x20002ce0 = 0;
*(uint32_t*)0x20002ce8 = 0;
*(uint32_t*)0x20002cec = 0;
*(uint32_t*)0x20002cf0 = 0;
*(uint32_t*)0x20002cf4 = 0;
*(uint64_t*)0x20002cf8 = 0;
*(uint64_t*)0x20002d00 = 0;
*(uint32_t*)0x20002d08 = 0x10;
*(uint32_t*)0x20002d0c = 0;
res =
syscall(__NR_bpf, /*cmd=*/5ul, /*arg=*/0x20002c80ul, /*size=*/0x90ul);
if (res != -1)
r[0] = res;
break;
case 1:
*(uint32_t*)0x200009c0 = 0x12;
*(uint32_t*)0x200009c4 = 4;
*(uint32_t*)0x200009c8 = 8;
*(uint32_t*)0x200009cc = 8;
*(uint32_t*)0x200009d0 = 0;
*(uint32_t*)0x200009d4 = -1;
*(uint32_t*)0x200009d8 = 0;
memset((void*)0x200009dc, 0, 16);
*(uint32_t*)0x200009ec = 0;
*(uint32_t*)0x200009f0 = -1;
*(uint32_t*)0x200009f4 = 0;
*(uint32_t*)0x200009f8 = 0;
*(uint32_t*)0x200009fc = 0;
*(uint64_t*)0x20000a00 = 0;
res =
syscall(__NR_bpf, /*cmd=*/0ul, /*arg=*/0x200009c0ul, /*size=*/0x48ul);
if (res != -1)
r[1] = res;
break;
case 2:
res = syscall(__NR_socket, /*domain=*/0xaul, /*type=*/2ul, /*proto=*/0);
if (res != -1)
r[2] = res;
break;
case 3:
*(uint32_t*)0x20000080 = r[1];
*(uint64_t*)0x20000088 = 0x20000a40;
memcpy((void*)0x20000a40, "\x90\xb4", 2);
*(uint64_t*)0x20000090 = 0x20000040;
*(uint32_t*)0x20000040 = r[2];
*(uint64_t*)0x20000098 = 0;
syscall(__NR_bpf, /*cmd=*/2ul, /*arg=*/0x20000080ul, /*size=*/0x20ul);
break;
case 4:
*(uint32_t*)0x200000c0 = 0x11;
*(uint32_t*)0x200000c4 = 0xc;
*(uint64_t*)0x200000c8 = 0x20000440;
*(uint8_t*)0x20000440 = 0x18;
STORE_BY_BITMASK(uint8_t, , 0x20000441, 0, 0, 4);
STORE_BY_BITMASK(uint8_t, , 0x20000441, 0, 4, 4);
*(uint16_t*)0x20000442 = 0;
*(uint32_t*)0x20000444 = 0;
*(uint8_t*)0x20000448 = 0;
*(uint8_t*)0x20000449 = 0;
*(uint16_t*)0x2000044a = 0;
*(uint32_t*)0x2000044c = 0;
*(uint8_t*)0x20000450 = 0x18;
STORE_BY_BITMASK(uint8_t, , 0x20000451, 1, 0, 4);
STORE_BY_BITMASK(uint8_t, , 0x20000451, 1, 4, 4);
*(uint16_t*)0x20000452 = 0;
*(uint32_t*)0x20000454 = r[1];
*(uint8_t*)0x20000458 = 0;
*(uint8_t*)0x20000459 = 0;
*(uint16_t*)0x2000045a = 0;
*(uint32_t*)0x2000045c = 0;
STORE_BY_BITMASK(uint8_t, , 0x20000460, 7, 0, 3);
STORE_BY_BITMASK(uint8_t, , 0x20000460, 0, 3, 1);
STORE_BY_BITMASK(uint8_t, , 0x20000460, 0xb, 4, 4);
STORE_BY_BITMASK(uint8_t, , 0x20000461, 8, 0, 4);
STORE_BY_BITMASK(uint8_t, , 0x20000461, 0, 4, 4);
*(uint16_t*)0x20000462 = 0;
*(uint32_t*)0x20000464 = 0;
STORE_BY_BITMASK(uint8_t, , 0x20000468, 3, 0, 3);
STORE_BY_BITMASK(uint8_t, , 0x20000468, 3, 3, 2);
STORE_BY_BITMASK(uint8_t, , 0x20000468, 3, 5, 3);
STORE_BY_BITMASK(uint8_t, , 0x20000469, 0xa, 0, 4);
STORE_BY_BITMASK(uint8_t, , 0x20000469, 8, 4, 4);
*(uint16_t*)0x2000046a = 0xfff8;
*(uint32_t*)0x2000046c = 0;
STORE_BY_BITMASK(uint8_t, , 0x20000470, 7, 0, 3);
STORE_BY_BITMASK(uint8_t, , 0x20000470, 1, 3, 1);
STORE_BY_BITMASK(uint8_t, , 0x20000470, 0xb, 4, 4);
STORE_BY_BITMASK(uint8_t, , 0x20000471, 2, 0, 4);
STORE_BY_BITMASK(uint8_t, , 0x20000471, 0xa, 4, 4);
*(uint16_t*)0x20000472 = 0;
*(uint32_t*)0x20000474 = 0;
STORE_BY_BITMASK(uint8_t, , 0x20000478, 7, 0, 3);
STORE_BY_BITMASK(uint8_t, , 0x20000478, 0, 3, 1);
STORE_BY_BITMASK(uint8_t, , 0x20000478, 0, 4, 4);
STORE_BY_BITMASK(uint8_t, , 0x20000479, 2, 0, 4);
STORE_BY_BITMASK(uint8_t, , 0x20000479, 0, 4, 4);
*(uint16_t*)0x2000047a = 0;
*(uint32_t*)0x2000047c = 0xfffffff8;
STORE_BY_BITMASK(uint8_t, , 0x20000480, 7, 0, 3);
STORE_BY_BITMASK(uint8_t, , 0x20000480, 0, 3, 1);
STORE_BY_BITMASK(uint8_t, , 0x20000480, 0xb, 4, 4);
STORE_BY_BITMASK(uint8_t, , 0x20000481, 3, 0, 4);
STORE_BY_BITMASK(uint8_t, , 0x20000481, 0, 4, 4);
*(uint16_t*)0x20000482 = 0;
*(uint32_t*)0x20000484 = 8;
STORE_BY_BITMASK(uint8_t, , 0x20000488, 7, 0, 3);
STORE_BY_BITMASK(uint8_t, , 0x20000488, 0, 3, 1);
STORE_BY_BITMASK(uint8_t, , 0x20000488, 0xb, 4, 4);
STORE_BY_BITMASK(uint8_t, , 0x20000489, 4, 0, 4);
STORE_BY_BITMASK(uint8_t, , 0x20000489, 0, 4, 4);
*(uint16_t*)0x2000048a = 0;
*(uint32_t*)0x2000048c = 0;
*(uint8_t*)0x20000490 = 0x85;
*(uint8_t*)0x20000491 = 0;
*(uint16_t*)0x20000492 = 0;
*(uint32_t*)0x20000494 = 3;
*(uint8_t*)0x20000498 = 0x95;
*(uint8_t*)0x20000499 = 0;
*(uint16_t*)0x2000049a = 0;
*(uint32_t*)0x2000049c = 0;
*(uint64_t*)0x200000d0 = 0x20000240;
memcpy((void*)0x20000240, "GPL\000", 4);
*(uint32_t*)0x200000d8 = 0;
*(uint32_t*)0x200000dc = 0;
*(uint64_t*)0x200000e0 = 0;
*(uint32_t*)0x200000e8 = 0;
*(uint32_t*)0x200000ec = 0;
memset((void*)0x200000f0, 0, 16);
*(uint32_t*)0x20000100 = 0;
*(uint32_t*)0x20000104 = 0;
*(uint32_t*)0x20000108 = -1;
*(uint32_t*)0x2000010c = 0;
*(uint64_t*)0x20000110 = 0;
*(uint32_t*)0x20000118 = 0;
*(uint32_t*)0x2000011c = 0;
*(uint64_t*)0x20000120 = 0;
*(uint32_t*)0x20000128 = 0;
*(uint32_t*)0x2000012c = 0;
*(uint32_t*)0x20000130 = 0;
*(uint32_t*)0x20000134 = 0;
*(uint64_t*)0x20000138 = 0;
*(uint64_t*)0x20000140 = 0;
*(uint32_t*)0x20000148 = 0;
*(uint32_t*)0x2000014c = 0;
res =
syscall(__NR_bpf, /*cmd=*/5ul, /*arg=*/0x200000c0ul, /*size=*/0x90ul);
if (res != -1)
r[3] = res;
break;
case 5:
*(uint64_t*)0x20000000 = 0x20000640;
memcpy((void*)0x20000640, "ext4_es_find_extent_range_enter\000", 32);
*(uint32_t*)0x20000008 = r[3];
syscall(__NR_bpf, /*cmd=*/0x11ul, /*arg=*/0x20000000ul, /*size=*/0x10ul);
break;
case 6:
*(uint32_t*)0x20000a80 = r[0];
*(uint32_t*)0x20000a84 = 0xe0;
*(uint64_t*)0x20000a88 = 0x200008c0;
*(uint32_t*)0x200008f4 = 8;
*(uint64_t*)0x200008f8 = 0x20000680;
*(uint32_t*)0x20000928 = 9;
*(uint32_t*)0x2000092c = 1;
*(uint64_t*)0x20000930 = 0x200006c0;
*(uint64_t*)0x20000938 = 0x20000740;
*(uint32_t*)0x20000944 = 0x8b;
*(uint64_t*)0x20000948 = 0x20000780;
*(uint32_t*)0x20000950 = 0x48;
*(uint32_t*)0x20000954 = 0x10;
*(uint64_t*)0x20000958 = 0x20000800;
*(uint64_t*)0x20000960 = 0x20000840;
*(uint32_t*)0x20000968 = 8;
*(uint32_t*)0x2000096c = 0xc7;
*(uint32_t*)0x20000970 = 8;
*(uint32_t*)0x20000974 = 8;
*(uint64_t*)0x20000978 = 0x20000880;
syscall(__NR_bpf, /*cmd=*/0xful, /*arg=*/0x20000a80ul, /*size=*/0x10ul);
break;
case 7:
res = syscall(__NR_pipe, /*pipefd=*/0x20000000ul);
if (res != -1)
r[4] = *(uint32_t*)0x20000004;
break;
case 8:
*(uint64_t*)0x20000100 = 0x20000580;
memset((void*)0x20000580, 128, 1);
*(uint64_t*)0x20000108 = 1;
syscall(__NR_vmsplice, /*fd=*/r[4], /*vec=*/0x20000100ul, /*vlen=*/1ul,
/*f=*/0ul);
break;
case 9:
*(uint32_t*)0x20000040 = r[4];
*(uint16_t*)0x20000044 = 0;
*(uint16_t*)0x20000046 = 0;
syscall(__NR_poll, /*fds=*/0x20000040ul, /*nfds=*/1ul,
/*timeout=*/0x8001);
break;
case 10:
*(uint64_t*)0x20000280 = 0x20000240;
memcpy((void*)0x20000240, "hrtimer_start\000", 14);
*(uint32_t*)0x20000288 = r[3];
syscall(__NR_bpf, /*cmd=*/0x11ul, /*arg=*/0x20000280ul, /*size=*/0x10ul);
break;
}
}
int main(void) {
syscall(__NR_mmap, /*addr=*/0x1ffff000ul, /*len=*/0x1000ul, /*prot=*/0ul,
/*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1,
/*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x20000000ul, /*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=*/0x21000000ul, /*len=*/0x1000ul, /*prot=*/0ul,
/*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1,
/*offset=*/0ul);
loop();
return 0;
}

=* repro.txt =*
r0 = bpf$BPF_PROG_RAW_TRACEPOINT_LOAD(0x5, &(0x7f0000002c80)={0x3,
0x5, &(0x7f0000000340)=ANY=[@ANYRESDEC=0x0],
&(0x7f0000000080)='GPL\x00', 0x4}, 0x90)
r1 = bpf$MAP_CREATE(0x0, &(0x7f00000009c0)=@base={0x12, 0x4, 0x8, 0x8}, 0x48)
r2 = socket$inet6_udp(0xa, 0x2, 0x0)
bpf$MAP_UPDATE_ELEM(0x2, &(0x7f0000000080)={r1,
&(0x7f0000000a40)="90b4", &(0x7f0000000040)=@udp6=r2}, 0x20)
r3 = bpf$PROG_LOAD(0x5, &(0x7f00000000c0)={0x11, 0xc,
&(0x7f0000000440)=@framed={{}, [@ringbuf_output={{0x18, 0x1, 0x1, 0x0,
r1}, {}, {}, {}, {}, {}, {}, {0x85, 0x0, 0x0, 0x3}}]},
&(0x7f0000000240)='GPL\x00', 0x0, 0x0, 0x0, 0x0, 0x0, '\x00', 0x0,
0x0, 0xffffffffffffffff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0}, 0x90)
bpf$BPF_RAW_TRACEPOINT_OPEN(0x11,
&(0x7f0000000000)={&(0x7f0000000640)='ext4_es_find_extent_range_enter\x00',
r3}, 0x10)
bpf$BPF_GET_PROG_INFO(0xf, &(0x7f0000000a80)={r0, 0xe0,
&(0x7f00000008c0)={0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x8,
&(0x7f0000000680)=[0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0], ""/16,
0x0, 0x0, 0x0, 0x0, 0x9, 0x1, &(0x7f00000006c0)=[0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0], &(0x7f0000000740)=[0x0], 0x0, 0x8b,
&(0x7f0000000780)=[{}, {}, {}, {}, {}, {}, {}, {}, {}], 0x48, 0x10,
&(0x7f0000000800), &(0x7f0000000840), 0x8, 0xc7, 0x8, 0x8,
&(0x7f0000000880)}}, 0x10)
pipe(&(0x7f0000000000)={0xffffffffffffffff, <r4=>0xffffffffffffffff})
vmsplice(r4, &(0x7f0000000100)=[{&(0x7f0000000580)="80", 0x1}], 0x1, 0x0)
poll(&(0x7f0000000040)=[{r4}], 0x1, 0x8001)
bpf$BPF_RAW_TRACEPOINT_OPEN(0x11,
&(0x7f0000000280)={&(0x7f0000000240)='hrtimer_start\x00', r3}, 0x10)

and see also in
https://gist.github.com/xrivendell7/f829da1471add4307c9a435d88de5ecc

I hope it helps.
Best regards
xingwei Lee

syzbot

unread,
2:08 AM (3 hours ago) 2:08 AM
to and...@kernel.org, a...@kernel.org, b...@vger.kernel.org, dan...@iogearbox.net, da...@davemloft.net, edum...@google.com, ja...@cloudflare.com, john.fa...@gmail.com, ku...@kernel.org, linux-...@vger.kernel.org, net...@vger.kernel.org, pab...@redhat.com, syzkall...@googlegroups.com, xrive...@gmail.com
syzbot has found a reproducer for the following issue on:

HEAD commit: b2ff42c6d3ab Merge tag 'for-netdev' of https://git.kernel...
git tree: bpf
console+strace: https://syzkaller.appspot.com/x/log.txt?x=157ea5e8980000
kernel config: https://syzkaller.appspot.com/x/.config?x=98d5a8e00ed1044a
dashboard link: https://syzkaller.appspot.com/bug?extid=ec941d6e24f633a59172
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=145682f8980000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=13c06aa0980000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/bbdf1d091619/disk-b2ff42c6.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/4bf7c5b24257/vmlinux-b2ff42c6.xz
kernel image: https://storage.googleapis.com/syzbot-assets/41fcb792fc43/bzImage-b2ff42c6.xz

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+ec941d...@syzkaller.appspotmail.com

============================================
WARNING: possible recursive locking detected
6.9.0-rc5-syzkaller-00171-gb2ff42c6d3ab #0 Not tainted
--------------------------------------------
syz-executor361/5090 is trying to acquire lock:
ffff888022c83260 (&htab->buckets[i].lock){+...}-{2:2}, at: spin_lock_bh include/linux/spinlock.h:356 [inline]
ffff888022c83260 (&htab->buckets[i].lock){+...}-{2:2}, at: sock_hash_delete_elem+0x17c/0x400 net/core/sock_map.c:945

but task is already holding lock:
ffff88807b2af8f8 (&htab->buckets[i].lock){+...}-{2:2}, at: spin_lock_bh include/linux/spinlock.h:356 [inline]
ffff88807b2af8f8 (&htab->buckets[i].lock){+...}-{2:2}, at: sock_hash_delete_elem+0x17c/0x400 net/core/sock_map.c:945

other info that might help us debug this:
Possible unsafe locking scenario:

CPU0
----
lock(&htab->buckets[i].lock);
lock(&htab->buckets[i].lock);

*** DEADLOCK ***

May be due to missing lock nesting notation

4 locks held by syz-executor361/5090:
#0: ffffffff8e334d20 (rcu_read_lock){....}-{1:2}, at: rcu_lock_acquire include/linux/rcupdate.h:329 [inline]
#0: ffffffff8e334d20 (rcu_read_lock){....}-{1:2}, at: rcu_read_lock include/linux/rcupdate.h:781 [inline]
#0: ffffffff8e334d20 (rcu_read_lock){....}-{1:2}, at: map_delete_elem+0x388/0x5e0 kernel/bpf/syscall.c:1695
#1: ffff88807b2af8f8 (&htab->buckets[i].lock){+...}-{2:2}, at: spin_lock_bh include/linux/spinlock.h:356 [inline]
#1: ffff88807b2af8f8 (&htab->buckets[i].lock){+...}-{2:2}, at: sock_hash_delete_elem+0x17c/0x400 net/core/sock_map.c:945
#2: ffff88801c2a4290 (&psock->link_lock){+...}-{2:2}, at: spin_lock_bh include/linux/spinlock.h:356 [inline]
#2: ffff88801c2a4290 (&psock->link_lock){+...}-{2:2}, at: sock_map_del_link net/core/sock_map.c:145 [inline]
#2: ffff88801c2a4290 (&psock->link_lock){+...}-{2:2}, at: sock_map_unref+0xcc/0x5e0 net/core/sock_map.c:180
#3: ffffffff8e334d20 (rcu_read_lock){....}-{1:2}, at: rcu_lock_acquire include/linux/rcupdate.h:329 [inline]
#3: ffffffff8e334d20 (rcu_read_lock){....}-{1:2}, at: rcu_read_lock include/linux/rcupdate.h:781 [inline]
#3: ffffffff8e334d20 (rcu_read_lock){....}-{1:2}, at: __bpf_trace_run kernel/trace/bpf_trace.c:2380 [inline]
#3: ffffffff8e334d20 (rcu_read_lock){....}-{1:2}, at: bpf_trace_run2+0x114/0x420 kernel/trace/bpf_trace.c:2420

stack backtrace:
CPU: 1 PID: 5090 Comm: syz-executor361 Not tainted 6.9.0-rc5-syzkaller-00171-gb2ff42c6d3ab #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/27/2024
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0x241/0x360 lib/dump_stack.c:114
check_deadlock kernel/locking/lockdep.c:3062 [inline]
validate_chain+0x15c1/0x58e0 kernel/locking/lockdep.c:3856
__lock_acquire+0x1346/0x1fd0 kernel/locking/lockdep.c:5137
lock_acquire+0x1ed/0x550 kernel/locking/lockdep.c:5754
__raw_spin_lock_bh include/linux/spinlock_api_smp.h:126 [inline]
_raw_spin_lock_bh+0x35/0x50 kernel/locking/spinlock.c:178
spin_lock_bh include/linux/spinlock.h:356 [inline]
sock_hash_delete_elem+0x17c/0x400 net/core/sock_map.c:945
bpf_prog_174bfe9d52de9121+0x4f/0x53
bpf_dispatcher_nop_func include/linux/bpf.h:1234 [inline]
__bpf_prog_run include/linux/filter.h:657 [inline]
bpf_prog_run include/linux/filter.h:664 [inline]
__bpf_trace_run kernel/trace/bpf_trace.c:2381 [inline]
bpf_trace_run2+0x204/0x420 kernel/trace/bpf_trace.c:2420
trace_kfree include/trace/events/kmem.h:94 [inline]
kfree+0x2af/0x3a0 mm/slub.c:4377
sk_psock_free_link include/linux/skmsg.h:421 [inline]
sock_map_del_link net/core/sock_map.c:158 [inline]
sock_map_unref+0x3ac/0x5e0 net/core/sock_map.c:180
sock_hash_delete_elem+0x392/0x400 net/core/sock_map.c:949
map_delete_elem+0x464/0x5e0 kernel/bpf/syscall.c:1696
__sys_bpf+0x598/0x810 kernel/bpf/syscall.c:5651
__do_sys_bpf kernel/bpf/syscall.c:5767 [inline]
__se_sys_bpf kernel/bpf/syscall.c:5765 [inline]
__x64_sys_bpf+0x7c/0x90 kernel/bpf/syscall.c:5765
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xf5/0x240 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f1dbe94ce29
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 c1 17 00 00 90 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 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffff608ae88 EFLAGS: 00000246 ORIG_RAX: 0000000000000141
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f1dbe94ce29
RDX: 0000000000000020 RSI: 0000000020000080 RDI: 0000000000000003
RBP: 00000000000f4240 R08: 00000000000000a0 R09: 00000000000000a0
R10: 00000000000000a0 R11: 0000000000000246 R12: 0000000000000001
R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
</TASK>


---
If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.

Hillf Danton

unread,
4:15 AM (1 hour ago) 4:15 AM
to syzbot, linux-...@vger.kernel.org, syzkall...@googlegroups.com
On Fri, 26 Apr 2024 23:08:19 -0700
> syzbot has found a reproducer for the following issue on:
>
> HEAD commit: b2ff42c6d3ab Merge tag 'for-netdev' of https://git.kernel...
> git tree: bpf
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=13c06aa0980000

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git b2ff42c6d3ab

--- x/net/core/sock_map.c
+++ y/net/core/sock_map.c
@@ -928,6 +928,7 @@ static void sock_hash_delete_from_link(s
spin_unlock_bh(&bucket->lock);
}

+static DEFINE_PER_CPU(int, subclass);
static long sock_hash_delete_elem(struct bpf_map *map, void *key)
{
struct bpf_shtab *htab = container_of(map, struct bpf_shtab, map);
@@ -935,6 +936,7 @@ static long sock_hash_delete_elem(struct
struct bpf_shtab_bucket *bucket;
struct bpf_shtab_elem *elem;
int ret = -ENOENT;
+ int *class;

if (irqs_disabled())
return -EOPNOTSUPP; /* locks here are hardirq-unsafe */
@@ -942,7 +944,10 @@ static long sock_hash_delete_elem(struct
hash = sock_hash_bucket_hash(key, key_size);
bucket = sock_hash_select_bucket(htab, hash);

- spin_lock_bh(&bucket->lock);
+ local_bh_disable();
+ class = this_cpu_ptr(&subclass);
+ *class += 1;
+ spin_lock_nested(&bucket->lock, *class);
elem = sock_hash_lookup_elem_raw(&bucket->head, hash, key, key_size);
if (elem) {
hlist_del_rcu(&elem->node);
@@ -950,6 +955,7 @@ static long sock_hash_delete_elem(struct
sock_hash_free_elem(htab, elem);
ret = 0;
}
+ *class -= 1;
spin_unlock_bh(&bucket->lock);
return ret;
}
--

syzbot

unread,
4:45 AM (13 minutes ago) 4:45 AM
to hda...@sina.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-and-tested-by: syzbot+ec941d...@syzkaller.appspotmail.com

Tested on:

commit: b2ff42c6 Merge tag 'for-netdev' of https://git.kernel...
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git
console output: https://syzkaller.appspot.com/x/log.txt?x=141a3d30980000
kernel config: https://syzkaller.appspot.com/x/.config?x=98d5a8e00ed1044a
dashboard link: https://syzkaller.appspot.com/bug?extid=ec941d6e24f633a59172
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=118d1937180000

Note: testing is done by a robot and is best-effort only.
Reply all
Reply to author
Forward
0 new messages