syzbot


possible deadlock in bpf_lru_push_free

Status: fixed on 2020/04/15 17:19
Subsystems: bpf
[Documentation on labels]
Reported-by: syzbot+122b5421d14e68f29cd1@syzkaller.appspotmail.com
Fix commit: b9aff38de2cb bpf: Fix a potential deadlock with bpf_map_do_batch
First crash: 1381d, last: 1375d
Cause bisection: the cause commit could be any of (bisect log):
  36a375c6dfad mailmap: add entry for Tiezhu Yang
  95c472ffca38 Documentation/ko_KR/howto: Update a broken link
  ff1e81a7e223 Documentation: build warnings related to missing blank lines after explicit markups has been fixed
  5549c2023265 Documentation/ko_KR/howto: Update broken web addresses
  599e6f8d3d23 Documentation: changes.rst: update several outdated project URLs
  4bfdebd6202d docs/locking: Fix outdated section names
  d1c9038ab5c1 Allow git builds of Sphinx
  41dcd67e8868 Merge tag 'docs-5.6-2' of git://git.lwn.net/linux
  
Discussions (7)
Title Replies (including bot) Last reply
[PATCH bpf v4] bpf: fix a potential deadlock with bpf_map_do_batch 2 (2) 2020/02/20 00:07
[PATCH bpf v3] bpf: fix a potential deadlock with bpf_map_do_batch 3 (3) 2020/02/19 23:13
[PATCH bpf v2] bpf: fix a potential deadlock with bpf_map_do_batch 3 (3) 2020/02/19 18:15
[PATCH bpf] bpf: fix a potential deadlock with bpf_map_do_batch 4 (4) 2020/02/19 16:15
Re: possible deadlock in bpf_lru_push_free 3 (3) 2020/02/19 04:55
Re: possible deadlock in bpf_lru_push_free 1 (1) 2020/02/19 04:03
possible deadlock in bpf_lru_push_free 0 (3) 2020/02/19 00:37

Sample crash report:
IPVS: ftp: loaded support on port[0] = 21
======================================================
WARNING: possible circular locking dependency detected
5.6.0-rc2-syzkaller #0 Not tainted
------------------------------------------------------
syz-executor103/9548 is trying to acquire lock:
ffffe8ffffc48f18 (&l->lock){....}, at: bpf_lru_list_push_free kernel/bpf/bpf_lru_list.c:313 [inline]
ffffe8ffffc48f18 (&l->lock){....}, at: bpf_common_lru_push_free kernel/bpf/bpf_lru_list.c:532 [inline]
ffffe8ffffc48f18 (&l->lock){....}, at: bpf_lru_push_free+0xe5/0x5b0 kernel/bpf/bpf_lru_list.c:555

but task is already holding lock:
ffff88809f4e0720 (&htab->buckets[i].lock){....}, at: __htab_map_lookup_and_delete_batch+0x617/0x1540 kernel/bpf/hashtab.c:1322

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #1 (&htab->buckets[i].lock){....}:
       __raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:110 [inline]
       _raw_spin_lock_irqsave+0x95/0xcd kernel/locking/spinlock.c:159
       htab_lru_map_delete_node+0xce/0x2f0 kernel/bpf/hashtab.c:593
       __bpf_lru_list_shrink_inactive kernel/bpf/bpf_lru_list.c:220 [inline]
       __bpf_lru_list_shrink+0xf9/0x470 kernel/bpf/bpf_lru_list.c:266
       bpf_percpu_lru_pop_free kernel/bpf/bpf_lru_list.c:416 [inline]
       bpf_lru_pop_free+0xa9f/0x1670 kernel/bpf/bpf_lru_list.c:497
       prealloc_lru_pop+0x2c/0xa0 kernel/bpf/hashtab.c:132
       __htab_lru_percpu_map_update_elem+0x67e/0xa90 kernel/bpf/hashtab.c:1069
       bpf_percpu_hash_update+0x16e/0x210 kernel/bpf/hashtab.c:1585
       bpf_map_update_value.isra.0+0x2d7/0x8e0 kernel/bpf/syscall.c:181
       map_update_elem kernel/bpf/syscall.c:1089 [inline]
       __do_sys_bpf+0x3163/0x41e0 kernel/bpf/syscall.c:3384
       __se_sys_bpf kernel/bpf/syscall.c:3355 [inline]
       __x64_sys_bpf+0x73/0xb0 kernel/bpf/syscall.c:3355
       do_syscall_64+0xfa/0x790 arch/x86/entry/common.c:294
       entry_SYSCALL_64_after_hwframe+0x49/0xbe

-> #0 (&l->lock){....}:
       check_prev_add kernel/locking/lockdep.c:2475 [inline]
       check_prevs_add kernel/locking/lockdep.c:2580 [inline]
       validate_chain kernel/locking/lockdep.c:2970 [inline]
       __lock_acquire+0x2596/0x4a00 kernel/locking/lockdep.c:3954
       lock_acquire+0x190/0x410 kernel/locking/lockdep.c:4484
       __raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:110 [inline]
       _raw_spin_lock_irqsave+0x95/0xcd kernel/locking/spinlock.c:159
       bpf_lru_list_push_free kernel/bpf/bpf_lru_list.c:313 [inline]
       bpf_common_lru_push_free kernel/bpf/bpf_lru_list.c:532 [inline]
       bpf_lru_push_free+0xe5/0x5b0 kernel/bpf/bpf_lru_list.c:555
       __htab_map_lookup_and_delete_batch+0x8d4/0x1540 kernel/bpf/hashtab.c:1374
       htab_lru_percpu_map_lookup_and_delete_batch+0x37/0x40 kernel/bpf/hashtab.c:1474
       bpf_map_do_batch+0x3f5/0x510 kernel/bpf/syscall.c:3348
       __do_sys_bpf+0x1f7d/0x41e0 kernel/bpf/syscall.c:3456
       __se_sys_bpf kernel/bpf/syscall.c:3355 [inline]
       __x64_sys_bpf+0x73/0xb0 kernel/bpf/syscall.c:3355
       do_syscall_64+0xfa/0x790 arch/x86/entry/common.c:294
       entry_SYSCALL_64_after_hwframe+0x49/0xbe

other info that might help us debug this:

 Possible unsafe locking scenario:

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

 *** DEADLOCK ***

2 locks held by syz-executor103/9548:
 #0: ffffffff89bac240 (rcu_read_lock){....}, at: __htab_map_lookup_and_delete_batch+0x54b/0x1540 kernel/bpf/hashtab.c:1308
 #1: ffff88809f4e0720 (&htab->buckets[i].lock){....}, at: __htab_map_lookup_and_delete_batch+0x617/0x1540 kernel/bpf/hashtab.c:1322

stack backtrace:
CPU: 0 PID: 9548 Comm: syz-executor103 Not tainted 5.6.0-rc2-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
 __dump_stack lib/dump_stack.c:77 [inline]
 dump_stack+0x197/0x210 lib/dump_stack.c:118
 print_circular_bug.isra.0.cold+0x163/0x172 kernel/locking/lockdep.c:1684
 check_noncircular+0x32e/0x3e0 kernel/locking/lockdep.c:1808
 check_prev_add kernel/locking/lockdep.c:2475 [inline]
 check_prevs_add kernel/locking/lockdep.c:2580 [inline]
 validate_chain kernel/locking/lockdep.c:2970 [inline]
 __lock_acquire+0x2596/0x4a00 kernel/locking/lockdep.c:3954
 lock_acquire+0x190/0x410 kernel/locking/lockdep.c:4484
 __raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:110 [inline]
 _raw_spin_lock_irqsave+0x95/0xcd kernel/locking/spinlock.c:159
 bpf_lru_list_push_free kernel/bpf/bpf_lru_list.c:313 [inline]
 bpf_common_lru_push_free kernel/bpf/bpf_lru_list.c:532 [inline]
 bpf_lru_push_free+0xe5/0x5b0 kernel/bpf/bpf_lru_list.c:555
 __htab_map_lookup_and_delete_batch+0x8d4/0x1540 kernel/bpf/hashtab.c:1374
 htab_lru_percpu_map_lookup_and_delete_batch+0x37/0x40 kernel/bpf/hashtab.c:1474
 bpf_map_do_batch+0x3f5/0x510 kernel/bpf/syscall.c:3348
 __do_sys_bpf+0x1f7d/0x41e0 kernel/bpf/syscall.c:3456
 __se_sys_bpf kernel/bpf/syscall.c:3355 [inline]
 __x64_sys_bpf+0x73/0xb0 kernel/bpf/syscall.c:3355
 do_syscall_64+0xfa/0x790 arch/x86/entry/common.c:294
 entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x440bf9
Code: 18 89 d0 c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 00 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 0f 83 7b 10 fc ff c3 66 2e 0f 1f 84 00 00 00 00
RSP: 002b:00007ffcd0f094d8 EFLAGS: 00000246 ORIG_RAX: 0000000000000141
RAX: ffffffffffffffda RBX: 00000000004a2390 RCX: 0000000000440bf9
RDX: 0000000000000038 RSI: 0000000020000100 RDI: 0000000000000019
RBP: 00000000006cb018 R08: 0000254c20080522 R09: 0000254c20080522
R10: 0000254c20080522 R11: 0000000000000246 R12: 00000000

Crashes (609):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2020/02/22 02:24 upstream b0dd1eb220c0 2ffa6679 .config console log report syz C ci-upstream-kasan-gce-root
2020/02/19 04:55 net-old 9facfdb54673 135c18aa .config console log report syz C ci-upstream-net-this-kasan-gce
2020/02/19 00:36 bpf e20d3a055a45 012fbc32 .config console log report syz C ci-upstream-bpf-kasan-gce
2020/02/19 00:56 net-next-old b182a66792fe 012fbc32 .config console log report syz C ci-upstream-net-kasan-gce
2020/02/19 00:40 bpf-next 92df9f8a745e 012fbc32 .config console log report syz C ci-upstream-bpf-next-kasan-gce
2020/02/20 16:34 upstream ca7e1fd1026c 81230308 .config console log report syz ci-upstream-kasan-gce-selinux-root
2020/02/18 20:27 upstream b1da3acc781c 012fbc32 .config console log report syz ci-upstream-kasan-gce-root
2020/02/17 07:57 upstream 11a48a5a18c6 1f448cd6 .config console log report syz ci-upstream-kasan-gce-smack-root
2020/02/16 16:39 bpf eecd618b4516 cf914200 .config console log report syz ci-upstream-bpf-kasan-gce
2020/02/16 15:06 net-old 2019fc96af22 cf914200 .config console log report syz ci-upstream-net-this-kasan-gce
2020/02/16 12:16 net-old 2019fc96af22 cf914200 .config console log report syz ci-upstream-net-this-kasan-gce
2020/02/16 15:43 bpf-next 2019fc96af22 cf914200 .config console log report syz ci-upstream-bpf-next-kasan-gce
2020/02/16 15:24 net-next-old 2019fc96af22 cf914200 .config console log report syz ci-upstream-net-kasan-gce
2020/02/16 12:52 bpf-next 2019fc96af22 cf914200 .config console log report syz ci-upstream-bpf-next-kasan-gce
2020/02/21 20:51 upstream ca7e1fd1026c 2ffa6679 .config console log report ci-upstream-kasan-gce-smack-root
2020/02/20 08:32 upstream ca7e1fd1026c 81230308 .config console log report ci-upstream-kasan-gce-root
2020/02/20 00:16 bpf 1dcc98dedc4d b690a6e3 .config console log report ci-upstream-bpf-kasan-gce
2020/02/16 10:53 net-old 2019fc96af22 cf914200 .config console log report ci-upstream-net-this-kasan-gce
2020/02/16 10:39 bpf eecd618b4516 cf914200 .config console log report ci-upstream-bpf-kasan-gce
2020/02/22 10:57 bpf-next e42da4c62abb 2ffa6679 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/22 10:26 bpf-next e42da4c62abb 2ffa6679 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/22 09:25 bpf-next e42da4c62abb 2ffa6679 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/22 08:19 bpf-next e42da4c62abb 2ffa6679 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/22 07:25 bpf-next e42da4c62abb 2ffa6679 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/22 06:22 bpf-next e42da4c62abb 2ffa6679 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/22 05:02 bpf-next e42da4c62abb 2ffa6679 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/22 04:36 bpf-next e42da4c62abb 2ffa6679 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/22 03:25 bpf-next e42da4c62abb 2ffa6679 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/22 01:51 bpf-next e42da4c62abb 2ffa6679 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/22 01:37 bpf-next e42da4c62abb 2ffa6679 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/22 00:35 bpf-next e42da4c62abb 2ffa6679 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/21 22:12 bpf-next e42da4c62abb 2ffa6679 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/21 19:41 net-next-old 5f9721a2d119 2ffa6679 .config console log report ci-upstream-net-kasan-gce
2020/02/21 19:25 bpf-next e42da4c62abb 2ffa6679 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/21 15:47 net-next-old 5f9721a2d119 bd2a74a3 .config console log report ci-upstream-net-kasan-gce
2020/02/21 14:46 bpf-next 5327644614a1 bd2a74a3 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/21 13:36 bpf-next 5327644614a1 bd2a74a3 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/21 12:39 bpf-next 5327644614a1 bd2a74a3 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/21 11:15 net-next-old 2e92a2d0e450 bd2a74a3 .config console log report ci-upstream-net-kasan-gce
2020/02/21 10:14 bpf-next 5327644614a1 bd2a74a3 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/21 10:01 bpf-next 5327644614a1 bd2a74a3 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/21 08:43 bpf-next 5327644614a1 bd2a74a3 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/21 07:31 bpf-next 5327644614a1 bd2a74a3 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/21 06:13 bpf-next 5327644614a1 bd2a74a3 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/21 04:34 bpf-next 5327644614a1 bd2a74a3 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/21 03:23 bpf-next 5327644614a1 bd2a74a3 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/21 02:20 bpf-next 5327644614a1 bd2a74a3 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/21 00:42 bpf-next 5327644614a1 bd2a74a3 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/20 23:37 bpf-next 5327644614a1 bd2a74a3 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/20 22:26 bpf-next 5327644614a1 bd2a74a3 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/20 20:29 bpf-next 5327644614a1 bd2a74a3 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/20 19:21 net-next-old 2bb07f4e1d86 81230308 .config console log report ci-upstream-net-kasan-gce
2020/02/20 18:17 bpf-next 500897804a36 81230308 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/20 16:20 bpf-next 500897804a36 81230308 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/20 15:09 bpf-next 500897804a36 81230308 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/20 13:41 bpf-next 500897804a36 81230308 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/20 12:39 bpf-next 500897804a36 81230308 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/20 12:17 bpf-next 500897804a36 81230308 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/20 10:54 bpf-next 500897804a36 81230308 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/20 07:01 bpf-next 500897804a36 81230308 .config console log report ci-upstream-bpf-next-kasan-gce
2020/02/19 17:51 linux-next 1d7f85df0f9c b690a6e3 .config console log report ci-upstream-linux-next-kasan-gce-root
* Struck through repros no longer work on HEAD.