Subject: [syzbot] [bpf?] [net?] general protection fault in bpf_struct_ops_link_create

From: syzbot <[email-masked]>
Date: Thu, 23 Mar 2023 23:11:45 -0700

Hello,

syzbot found the following issue on:

HEAD commit:    226bc6ae6405 Merge branch 'Transit between BPF TCP congest..
git tree:       bpf-next
console+strace: https://syzkaller.appspot.com/x/log.txt?x=139c727ac80000
kernel config:  https://syzkaller.appspot.com/x/.config?x=cab35c936731a347
dashboard link: https://syzkaller.appspot.com/bug?extid=71ccc0fe37abb458406b
compiler:       gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=11ef67a1c80000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=119c20fec80000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/ac055f681ed7/disk-226bc6ae.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/3895cc8a51d2/vmlinux-226bc6ae.xz
kernel image: https://storage.googleapis.com/syzbot-assets/1b18bb9fae05/bzImage-226bc6ae.xz

The issue was bisected to:

commit 68b04864ca425d1894c96b8141d4fba1181f11cb
Author: Kui-Feng Lee <[email-masked]>
Date:   Thu Mar 23 03:24:00 2023 +0000

    bpf: Create links for BPF struct_ops maps.

bisection log:  https://syzkaller.appspot.com/x/bisect.txt?x=116731b1c80000
final oops:     https://syzkaller.appspot.com/x/report.txt?x=136731b1c80000
console output: https://syzkaller.appspot.com/x/log.txt?x=156731b1c80000

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: [email-masked]
Fixes: 68b04864ca42 ("bpf: Create links for BPF struct_ops maps.")

general protection fault, probably for non-canonical address 0xdffffc0000000001: 0000 [#1] PREEMPT SMP KASAN
KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f]
CPU: 1 PID: 5081 Comm: syz-executor182 Not tainted 6.2.0-syzkaller-13084-g226bc6ae6405 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/02/2023
RIP: 0010:bpf_struct_ops_valid_to_reg kernel/bpf/bpf_struct_ops.c:764 [inline]
RIP: 0010:bpf_struct_ops_link_create+0xb1/0x390 kernel/bpf/bpf_struct_ops.c:879
Code: 95 81 eb ff 48 85 c0 48 89 c5 0f 84 9e 02 00 00 e8 24 27 dd ff 48 8d 7d 18 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <0f> b6 04 02 84 c0 74 08 3c 03 0f 8e 60 02 00 00 44 8b 65 18 bf 1a
RSP: 0018:ffffc90003b8fc38 EFLAGS: 00010203
RAX: dffffc0000000000 RBX: 1ffff92000771f87 RCX: 0000000000000000
RDX: 0000000000000001 RSI: ffffffff81a7dc8c RDI: 000000000000000f
RBP: fffffffffffffff7 R08: 0000000000000007 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000000 R12: dffffc0000000000
R13: 000000000000002c R14: ffffc90003b8fde8 R15: 0000000000000000
FS:  0000555556538300(0000) GS:ffff8880b9900000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000eaa388 CR3: 00000000206d2000 CR4: 00000000003506e0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
 <TASK>
 link_create kernel/bpf/syscall.c:4585 [inline]
 __sys_bpf+0x3b77/0x53b0 kernel/bpf/syscall.c:5129
 __do_sys_bpf kernel/bpf/syscall.c:5163 [inline]
 __se_sys_bpf kernel/bpf/syscall.c:5161 [inline]
 __x64_sys_bpf+0x79/0xc0 kernel/bpf/syscall.c:5161
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7fc374490ae9
Code: 28 c3 e8 2a 14 00 00 66 2e 0f 1f 84 00 00 00 00 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 73 01 c3 48 c7 c1 c0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fffe2184578 EFLAGS: 00000246 ORIG_RAX: 0000000000000141
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007fc374490ae9
RDX: 0000000000000010 RSI: 0000000020001340 RDI: 000000000000001c
RBP: 00007fc374454c90 R08: 0000000000000000 R09: 0000000000000000
R10: 00000000ffffffff R11: 0000000000000246 R12: 00007fc374454d20
R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
 </TASK>
Modules linked in:
---[ end trace 0000000000000000 ]---
RIP: 0010:bpf_struct_ops_valid_to_reg kernel/bpf/bpf_struct_ops.c:764 [inline]
RIP: 0010:bpf_struct_ops_link_create+0xb1/0x390 kernel/bpf/bpf_struct_ops.c:879
Code: 95 81 eb ff 48 85 c0 48 89 c5 0f 84 9e 02 00 00 e8 24 27 dd ff 48 8d 7d 18 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <0f> b6 04 02 84 c0 74 08 3c 03 0f 8e 60 02 00 00 44 8b 65 18 bf 1a
RSP: 0018:ffffc90003b8fc38 EFLAGS: 00010203
RAX: dffffc0000000000 RBX: 1ffff92000771f87 RCX: 0000000000000000
RDX: 0000000000000001 RSI: ffffffff81a7dc8c RDI: 000000000000000f
RBP: fffffffffffffff7 R08: 0000000000000007 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000000 R12: dffffc0000000000
R13: 000000000000002c R14: ffffc90003b8fde8 R15: 0000000000000000
FS:  0000555556538300(0000) GS:ffff8880b9900000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000eaa388 CR3: 00000000206d2000 CR4: 00000000003506e0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
----------------
Code disassembly (best guess):
   0:	95                   	xchg   %eax,%ebp
   1:	81 eb ff 48 85 c0    	sub    $0xc08548ff,%ebx
   7:	48 89 c5             	mov    %rax,%rbp
   a:	0f 84 9e 02 00 00    	je     0x2ae
  10:	e8 24 27 dd ff       	callq  0xffdd2739
  15:	48 8d 7d 18          	lea    0x18(%rbp),%rdi
  19:	48 b8 00 00 00 00 00 	movabs $0xdffffc0000000000,%rax
  20:	fc ff df
  23:	48 89 fa             	mov    %rdi,%rdx
  26:	48 c1 ea 03          	shr    $0x3,%rdx
* 2a:	0f b6 04 02          	movzbl (%rdx,%rax,1),%eax <-- trapping instruction
  2e:	84 c0                	test   %al,%al
  30:	74 08                	je     0x3a
  32:	3c 03                	cmp    $0x3,%al
  34:	0f 8e 60 02 00 00    	jle    0x29a
  3a:	44 8b 65 18          	mov    0x18(%rbp),%r12d
  3e:	bf                   	.byte 0xbf
  3f:	1a                   	.byte 0x1a

---
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 [email-masked].

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
For information about bisection process see: https://goo.gl/tpsmEJ#bisection
syzbot can test patches for this issue, for details see:
https://goo.gl/tpsmEJ#testing-patches