linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* KASAN: use-after-free Read in v4l2_fh_open
@ 2021-02-15 15:18 syzbot
  2021-05-04 21:28 ` SyzScope
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: syzbot @ 2021-02-15 15:18 UTC (permalink / raw)
  To: linux-kernel, linux-media, mchehab, syzkaller-bugs

Hello,

syzbot found the following issue on:

HEAD commit:    291009f6 Merge tag 'pm-5.11-rc8' of git://git.kernel.org/p..
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=17260814d00000
kernel config:  https://syzkaller.appspot.com/x/.config?x=6a218c95bd23063a
dashboard link: https://syzkaller.appspot.com/bug?extid=b2391895514ed9ef4a8e
compiler:       Debian clang version 11.0.1-2
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=14ec5814d00000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=17179dd4d00000

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

==================================================================
BUG: KASAN: use-after-free in v4l2_fh_init drivers/media/v4l2-core/v4l2-fh.c:25 [inline]
BUG: KASAN: use-after-free in v4l2_fh_open+0xc7/0x430 drivers/media/v4l2-core/v4l2-fh.c:63
Read of size 8 at addr ffff8880228b88b8 by task v4l_id/18349

CPU: 1 PID: 18349 Comm: v4l_id Not tainted 5.11.0-rc7-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
 __dump_stack lib/dump_stack.c:79 [inline]
 dump_stack+0x137/0x1be lib/dump_stack.c:120
 print_address_description+0x5f/0x3a0 mm/kasan/report.c:230
 __kasan_report mm/kasan/report.c:396 [inline]
 kasan_report+0x15e/0x200 mm/kasan/report.c:413
 v4l2_fh_init drivers/media/v4l2-core/v4l2-fh.c:25 [inline]
 v4l2_fh_open+0xc7/0x430 drivers/media/v4l2-core/v4l2-fh.c:63
 em28xx_v4l2_open+0x15c/0xa60 drivers/media/usb/em28xx/em28xx-video.c:2163
 v4l2_open+0x229/0x360 drivers/media/v4l2-core/v4l2-dev.c:423
 chrdev_open+0x4a0/0x570 fs/char_dev.c:414
 do_dentry_open+0x7cb/0x1010 fs/open.c:817
 do_open fs/namei.c:3254 [inline]
 path_openat+0x2791/0x37a0 fs/namei.c:3371
 do_filp_open+0x191/0x3a0 fs/namei.c:3398
 do_sys_openat2+0xba/0x380 fs/open.c:1172
 do_sys_open fs/open.c:1188 [inline]
 __do_sys_open fs/open.c:1196 [inline]
 __se_sys_open fs/open.c:1192 [inline]
 __x64_sys_open+0x1af/0x1e0 fs/open.c:1192
 do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x7fdd62b00840
Code: 73 01 c3 48 8b 0d 68 77 20 00 f7 d8 64 89 01 48 83 c8 ff c3 66 0f 1f 44 00 00 83 3d 89 bb 20 00 00 75 10 b8 02 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 31 c3 48 83 ec 08 e8 1e f6 ff ff 48 89 04 24
RSP: 002b:00007ffe8bb255b8 EFLAGS: 00000246 ORIG_RAX: 0000000000000002
RAX: ffffffffffffffda RBX: 00007ffe8bb25728 RCX: 00007fdd62b00840
RDX: 00007fdd62aecea0 RSI: 0000000000000000 RDI: 00007ffe8bb26f1c
RBP: 0000000000000003 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000002 R11: 0000000000000246 R12: 000055f8a7dee8d0
R13: 00007ffe8bb25720 R14: 0000000000000000 R15: 0000000000000000

The buggy address belongs to the page:
page:00000000b7dd9778 refcount:0 mapcount:-128 mapping:0000000000000000 index:0x0 pfn:0x228b8
flags: 0xfff00000000000()
raw: 00fff00000000000 ffffea0000580108 ffff88813fffb910 0000000000000000
raw: 0000000000000000 0000000000000002 00000000ffffff7f 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
 ffff8880228b8780: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
 ffff8880228b8800: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
>ffff8880228b8880: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
                                        ^
 ffff8880228b8900: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
 ffff8880228b8980: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
==================================================================


---
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 syzkaller@googlegroups.com.

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: KASAN: use-after-free Read in v4l2_fh_open
  2021-02-15 15:18 KASAN: use-after-free Read in v4l2_fh_open syzbot
@ 2021-05-04 21:28 ` SyzScope
  2024-03-02 10:56 ` Hillf Danton
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: SyzScope @ 2021-05-04 21:28 UTC (permalink / raw)
  To: linux-kernel, linux-media, mchehab

Hi,

This is SyzScope, a research project that aims to reveal high-risk 
primitives from a seemingly low-risk bug (UAF/OOB read, WARNING, BUG, etc.).

We are currently testing seemingly low-risk bugs on syzbot's open 
section(https://syzkaller.appspot.com/upstream), and try to reach out to 
kernel developers as long as SyzScope discovers any high-risk primitives.

Please let us know if SyzScope indeed helps, and any suggestions/feedback.

Regrading the bug "KASAN: use-after-free Read in v4l2_fh_open", SyzScope 
reports 1 memory write capability.

The detailed comments can be found at 
https://sites.google.com/view/syzscope/kasan-use-after-free-read-in-v4l2_fh_open

On 2/15/2021 7:18 AM, syzbot wrote:

> Hello,
>
> syzbot found the following issue on:
>
> HEAD commit:    291009f6 Merge tag 'pm-5.11-rc8' of git://git.kernel.org/p..
> git tree:       upstream
> console output: https://syzkaller.appspot.com/x/log.txt?x=17260814d00000
> kernel config:  https://syzkaller.appspot.com/x/.config?x=6a218c95bd23063a
> dashboard link: https://syzkaller.appspot.com/bug?extid=b2391895514ed9ef4a8e
> compiler:       Debian clang version 11.0.1-2
> syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=14ec5814d00000
> C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=17179dd4d00000
>
> IMPORTANT: if you fix the issue, please add the following tag to the commit:
> Reported-by: syzbot+b2391895514ed9ef4a8e@syzkaller.appspotmail.com
>
> ==================================================================
> BUG: KASAN: use-after-free in v4l2_fh_init drivers/media/v4l2-core/v4l2-fh.c:25 [inline]
> BUG: KASAN: use-after-free in v4l2_fh_open+0xc7/0x430 drivers/media/v4l2-core/v4l2-fh.c:63
> Read of size 8 at addr ffff8880228b88b8 by task v4l_id/18349
>
> CPU: 1 PID: 18349 Comm: v4l_id Not tainted 5.11.0-rc7-syzkaller #0
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
> Call Trace:
>   __dump_stack lib/dump_stack.c:79 [inline]
>   dump_stack+0x137/0x1be lib/dump_stack.c:120
>   print_address_description+0x5f/0x3a0 mm/kasan/report.c:230
>   __kasan_report mm/kasan/report.c:396 [inline]
>   kasan_report+0x15e/0x200 mm/kasan/report.c:413
>   v4l2_fh_init drivers/media/v4l2-core/v4l2-fh.c:25 [inline]
>   v4l2_fh_open+0xc7/0x430 drivers/media/v4l2-core/v4l2-fh.c:63
>   em28xx_v4l2_open+0x15c/0xa60 drivers/media/usb/em28xx/em28xx-video.c:2163
>   v4l2_open+0x229/0x360 drivers/media/v4l2-core/v4l2-dev.c:423
>   chrdev_open+0x4a0/0x570 fs/char_dev.c:414
>   do_dentry_open+0x7cb/0x1010 fs/open.c:817
>   do_open fs/namei.c:3254 [inline]
>   path_openat+0x2791/0x37a0 fs/namei.c:3371
>   do_filp_open+0x191/0x3a0 fs/namei.c:3398
>   do_sys_openat2+0xba/0x380 fs/open.c:1172
>   do_sys_open fs/open.c:1188 [inline]
>   __do_sys_open fs/open.c:1196 [inline]
>   __se_sys_open fs/open.c:1192 [inline]
>   __x64_sys_open+0x1af/0x1e0 fs/open.c:1192
>   do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
>   entry_SYSCALL_64_after_hwframe+0x44/0xa9
> RIP: 0033:0x7fdd62b00840
> Code: 73 01 c3 48 8b 0d 68 77 20 00 f7 d8 64 89 01 48 83 c8 ff c3 66 0f 1f 44 00 00 83 3d 89 bb 20 00 00 75 10 b8 02 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 31 c3 48 83 ec 08 e8 1e f6 ff ff 48 89 04 24
> RSP: 002b:00007ffe8bb255b8 EFLAGS: 00000246 ORIG_RAX: 0000000000000002
> RAX: ffffffffffffffda RBX: 00007ffe8bb25728 RCX: 00007fdd62b00840
> RDX: 00007fdd62aecea0 RSI: 0000000000000000 RDI: 00007ffe8bb26f1c
> RBP: 0000000000000003 R08: 0000000000000000 R09: 0000000000000000
> R10: 0000000000000002 R11: 0000000000000246 R12: 000055f8a7dee8d0
> R13: 00007ffe8bb25720 R14: 0000000000000000 R15: 0000000000000000
>
> The buggy address belongs to the page:
> page:00000000b7dd9778 refcount:0 mapcount:-128 mapping:0000000000000000 index:0x0 pfn:0x228b8
> flags: 0xfff00000000000()
> raw: 00fff00000000000 ffffea0000580108 ffff88813fffb910 0000000000000000
> raw: 0000000000000000 0000000000000002 00000000ffffff7f 0000000000000000
> page dumped because: kasan: bad access detected
>
> Memory state around the buggy address:
>   ffff8880228b8780: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
>   ffff8880228b8800: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
>> ffff8880228b8880: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
>                                          ^
>   ffff8880228b8900: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
>   ffff8880228b8980: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
> ==================================================================
>
>
> ---
> 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 syzkaller@googlegroups.com.
>
> syzbot will keep track of this issue. See:
> https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
> syzbot can test patches for this issue, for details see:
> https://goo.gl/tpsmEJ#testing-patches
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: KASAN: use-after-free Read in v4l2_fh_open
  2021-02-15 15:18 KASAN: use-after-free Read in v4l2_fh_open syzbot
  2021-05-04 21:28 ` SyzScope
@ 2024-03-02 10:56 ` Hillf Danton
  2024-03-02 13:02   ` [syzbot] [usb?] [media?] " syzbot
  2024-03-02 23:07 ` Hillf Danton
  2024-03-03  1:43 ` Hillf Danton
  3 siblings, 1 reply; 9+ messages in thread
From: Hillf Danton @ 2024-03-02 10:56 UTC (permalink / raw)
  To: syzbot; +Cc: linux-kernel, syzkaller-bugs

On Mon, 15 Feb 2021 07:18:22 -0800
> syzbot found the following issue on:
> 
> HEAD commit:    291009f6 Merge tag 'pm-5.11-rc8' of git://git.kernel.org/p..
> git tree:       upstream
> C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=17179dd4d00000

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git  master

--- x/drivers/media/usb/em28xx/em28xx-video.c
+++ y/drivers/media/usb/em28xx/em28xx-video.c
@@ -2152,6 +2152,10 @@ static int em28xx_v4l2_open(struct file
 	if (mutex_lock_interruptible(&dev->lock))
 		return -ERESTARTSYS;
 
+	if (!dev->v4l2) {
+		mutex_unlock(&dev->lock);
+		return -ENODEV;
+	}
 	ret = v4l2_fh_open(filp);
 	if (ret) {
 		dev_err(&dev->intf->dev,
@@ -2161,6 +2165,7 @@ static int em28xx_v4l2_open(struct file
 		return ret;
 	}
 
+	v4l2 = dev->v4l2;
 	if (v4l2->users == 0) {
 		em28xx_set_mode(dev, EM28XX_ANALOG_MODE);
 
--

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [syzbot] [usb?] [media?] KASAN: use-after-free Read in v4l2_fh_open
  2024-03-02 10:56 ` Hillf Danton
@ 2024-03-02 13:02   ` syzbot
  0 siblings, 0 replies; 9+ messages in thread
From: syzbot @ 2024-03-02 13:02 UTC (permalink / raw)
  To: hdanton, linux-kernel, syzkaller-bugs

Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KASAN: slab-use-after-free Read in v4l2_open

==================================================================
BUG: KASAN: slab-use-after-free in v4l2_open+0x342/0x360 drivers/media/v4l2-core/v4l2-dev.c:432
Read of size 4 at addr ffff888024454800 by task v4l_id/5646

CPU: 1 PID: 5646 Comm: v4l_id Not tainted 6.8.0-rc6-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/25/2024
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x1b5/0x2a0 lib/dump_stack.c:106
 print_address_description mm/kasan/report.c:377 [inline]
 print_report+0x163/0x510 mm/kasan/report.c:488
 kasan_report+0xcd/0x100 mm/kasan/report.c:601
 v4l2_open+0x342/0x360 drivers/media/v4l2-core/v4l2-dev.c:432
 chrdev_open+0x50f/0x5d0 fs/char_dev.c:414
 do_dentry_open+0x8fd/0x1590 fs/open.c:953
 path_openat+0x280d/0x31d0 fs/namei.c:3645
 do_filp_open+0x26d/0x500 fs/namei.c:3829
 do_sys_openat2+0x12f/0x1c0 fs/open.c:1404
 do_sys_open fs/open.c:1419 [inline]
 __do_sys_openat fs/open.c:1435 [inline]
 __se_sys_openat fs/open.c:1430 [inline]
 __x64_sys_openat+0x247/0x290 fs/open.c:1430
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0x85/0x160 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x63/0x6b
RIP: 0033:0x7f3dabb169a4
Code: 24 20 48 8d 44 24 30 48 89 44 24 28 64 8b 04 25 18 00 00 00 85 c0 75 2c 44 89 e2 48 89 ee bf 9c ff ff ff b8 01 01 00 00 0f 05 <48> 3d 00 f0 ff ff 76 60 48 8b 15 55 a4 0d 00 f7 d8 64 89 02 48 83
RSP: 002b:00007ffc466ecd40 EFLAGS: 00000246 ORIG_RAX: 0000000000000101
RAX: ffffffffffffffda RBX: 00007ffc466ecf58 RCX: 00007f3dabb169a4
RDX: 0000000000000000 RSI: 00007ffc466edf1e RDI: 00000000ffffff9c
RBP: 00007ffc466edf1e R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007ffc466ecf70 R14: 0000555aa0ec0670 R15: 00007f3dac0aca80
 </TASK>

Allocated by task 8:
 kasan_save_stack mm/kasan/common.c:47 [inline]
 kasan_save_track+0x30/0x60 mm/kasan/common.c:68
 poison_kmalloc_redzone mm/kasan/common.c:370 [inline]
 __kasan_kmalloc+0x98/0xb0 mm/kasan/common.c:387
 kasan_kmalloc include/linux/kasan.h:211 [inline]
 kmalloc_trace+0x1e6/0x400 mm/slub.c:4012
 kmalloc include/linux/slab.h:590 [inline]
 kzalloc include/linux/slab.h:711 [inline]
 em28xx_v4l2_init+0x107/0x2dc0 drivers/media/usb/em28xx/em28xx-video.c:2539
 em28xx_init_extension+0x11f/0x1c0 drivers/media/usb/em28xx/em28xx-core.c:1116
 process_scheduled_works+0x96f/0x1490 kernel/workqueue.c:2633
 worker_thread+0xa5f/0xff0 kernel/workqueue.c:2787
 kthread+0x2cd/0x360 kernel/kthread.c:388
 ret_from_fork+0x48/0x80 arch/x86/kernel/process.c:147
 ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:243

Freed by task 8:
 kasan_save_stack mm/kasan/common.c:47 [inline]
 kasan_save_track+0x30/0x60 mm/kasan/common.c:68
 kasan_save_free_info+0x40/0x50 mm/kasan/generic.c:589
 poison_slab_object+0xa6/0xe0 mm/kasan/common.c:240
 __kasan_slab_free+0x37/0x60 mm/kasan/common.c:256
 kasan_slab_free include/linux/kasan.h:184 [inline]
 slab_free_hook mm/slub.c:2121 [inline]
 slab_free mm/slub.c:4299 [inline]
 kfree+0x14a/0x370 mm/slub.c:4409
 em28xx_free_v4l2 drivers/media/usb/em28xx/em28xx-video.c:2120 [inline]
 kref_put include/linux/kref.h:65 [inline]
 em28xx_v4l2_init+0x1608/0x2dc0 drivers/media/usb/em28xx/em28xx-video.c:2908
 em28xx_init_extension+0x11f/0x1c0 drivers/media/usb/em28xx/em28xx-core.c:1116
 process_scheduled_works+0x96f/0x1490 kernel/workqueue.c:2633
 worker_thread+0xa5f/0xff0 kernel/workqueue.c:2787
 kthread+0x2cd/0x360 kernel/kthread.c:388
 ret_from_fork+0x48/0x80 arch/x86/kernel/process.c:147
 ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:243

The buggy address belongs to the object at ffff888024454000
 which belongs to the cache kmalloc-8k of size 8192
The buggy address is located 2048 bytes inside of
 freed 8192-byte region [ffff888024454000, ffff888024456000)

The buggy address belongs to the physical page:
page:ffffea0000911400 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x24450
head:ffffea0000911400 order:3 entire_mapcount:0 nr_pages_mapped:0 pincount:0
anon flags: 0xfff00000000840(slab|head|node=0|zone=1|lastcpupid=0x7ff)
page_type: 0xffffffff()
raw: 00fff00000000840 ffff888011442280 ffffea0001ede600 0000000000000005
raw: 0000000000000000 0000000080020002 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 3, migratetype Unmovable, gfp_mask 0xd2040(__GFP_IO|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 4658, tgid 4658 (S41dhcpcd), ts 32416679882, free_ts 32403418572
 prep_new_page mm/page_alloc.c:1540 [inline]
 get_page_from_freelist+0x3355/0x34e0 mm/page_alloc.c:3311
 __alloc_pages+0x255/0x670 mm/page_alloc.c:4567
 alloc_slab_page+0x5f/0x150 include/linux/gfp.h:238
 new_slab+0x84/0x2f0 mm/slub.c:2354
 ___slab_alloc+0xc77/0x1310 mm/slub.c:3540
 kmalloc_trace+0x276/0x400 mm/slub.c:3625
 kmalloc include/linux/slab.h:590 [inline]
 kzalloc include/linux/slab.h:711 [inline]
 tomoyo_print_bprm security/tomoyo/audit.c:26 [inline]
 tomoyo_init_log+0x1228/0x2130 security/tomoyo/audit.c:264
 tomoyo_supervisor+0x37a/0x1370 security/tomoyo/common.c:2089
 tomoyo_audit_env_log security/tomoyo/environ.c:36 [inline]
 tomoyo_env_perm+0x157/0x1f0 security/tomoyo/environ.c:63
 tomoyo_find_next_domain+0x139a/0x1d40 security/tomoyo/domain.c:672
 tomoyo_bprm_check_security+0x114/0x170 security/tomoyo/tomoyo.c:102
 security_bprm_check+0x63/0xa0 security/security.c:1188
 bprm_execve+0xa45/0x1840 fs/exec.c:1771
 do_execveat_common+0x552/0x6f0 fs/exec.c:1984
 do_execve fs/exec.c:2058 [inline]
 __do_sys_execve fs/exec.c:2134 [inline]
 __se_sys_execve fs/exec.c:2129 [inline]
 __x64_sys_execve+0x92/0xa0 fs/exec.c:2129
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0x85/0x160 arch/x86/entry/common.c:83
page last free pid 4657 tgid 4657 stack trace:
 free_unref_page_prepare+0x94d/0xa60 include/linux/page_owner.h:24
 free_unref_page+0x37/0x3f0 mm/page_alloc.c:2486
 __put_partials+0xeb/0x130 mm/slub.c:2453
 put_cpu_partial+0x169/0x240 mm/slub.c:2997
 __slab_free+0x2c3/0x400 mm/slub.c:4166
 qlist_free_all+0x5e/0xc0 mm/kasan/quarantine.c:163
 kasan_quarantine_reduce+0x14b/0x160 mm/kasan/quarantine.c:286
 __kasan_slab_alloc+0x23/0x70 mm/kasan/common.c:322
 kasan_slab_alloc include/linux/kasan.h:201 [inline]
 slab_post_alloc_hook mm/slub.c:3813 [inline]
 slab_alloc_node mm/slub.c:3860 [inline]
 __do_kmalloc_node mm/slub.c:3980 [inline]
 __kmalloc+0x1dd/0x540 mm/slub.c:3994
 kmalloc include/linux/slab.h:594 [inline]
 tomoyo_realpath_from_path+0xcf/0x5e0 security/tomoyo/realpath.c:251
 tomoyo_path_perm+0x24d/0x5b0 security/tomoyo/file.c:151
 security_inode_getattr+0xd3/0x120 security/security.c:2238
 vfs_fstatat+0xca/0x1b0 fs/stat.c:173
 __se_sys_newfstatat fs/stat.c:468 [inline]
 __x64_sys_newfstatat+0xff/0x170 fs/stat.c:462
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0x85/0x160 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x63/0x6b

Memory state around the buggy address:
 ffff888024454700: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff888024454780: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff888024454800: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                   ^
 ffff888024454880: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff888024454900: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================


Tested on:

commit:         5ad3cb0e Merge tag 'for-v6.8-rc2' of git://git.kernel...
git tree:       https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
console output: https://syzkaller.appspot.com/x/log.txt?x=163afbac180000
kernel config:  https://syzkaller.appspot.com/x/.config?x=fa01a41dc74de670
dashboard link: https://syzkaller.appspot.com/bug?extid=b2391895514ed9ef4a8e
compiler:       Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch:          https://syzkaller.appspot.com/x/patch.diff?x=15d84096180000


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: KASAN: use-after-free Read in v4l2_fh_open
  2021-02-15 15:18 KASAN: use-after-free Read in v4l2_fh_open syzbot
  2021-05-04 21:28 ` SyzScope
  2024-03-02 10:56 ` Hillf Danton
@ 2024-03-02 23:07 ` Hillf Danton
  2024-03-02 23:39   ` [syzbot] [usb?] [media?] " syzbot
  2024-03-03  1:43 ` Hillf Danton
  3 siblings, 1 reply; 9+ messages in thread
From: Hillf Danton @ 2024-03-02 23:07 UTC (permalink / raw)
  To: syzbot; +Cc: linux-kernel, syzkaller-bugs

On Mon, 15 Feb 2021 07:18:22 -0800
> syzbot found the following issue on:
> 
> HEAD commit:    291009f6 Merge tag 'pm-5.11-rc8' of git://git.kernel.org/p..
> git tree:       upstream
> C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=17179dd4d00000

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git  master

--- x/drivers/media/usb/em28xx/em28xx-video.c
+++ y/drivers/media/usb/em28xx/em28xx-video.c
@@ -2152,6 +2152,10 @@ static int em28xx_v4l2_open(struct file
 	if (mutex_lock_interruptible(&dev->lock))
 		return -ERESTARTSYS;
 
+	if (!dev->v4l2) {
+		mutex_unlock(&dev->lock);
+		return -ENODEV;
+	}
 	ret = v4l2_fh_open(filp);
 	if (ret) {
 		dev_err(&dev->intf->dev,
@@ -2161,6 +2165,7 @@ static int em28xx_v4l2_open(struct file
 		return ret;
 	}
 
+	v4l2 = dev->v4l2;
 	if (v4l2->users == 0) {
 		em28xx_set_mode(dev, EM28XX_ANALOG_MODE);
 
@@ -2899,6 +2904,7 @@ unregister_dev:
 	v4l2_ctrl_handler_free(&v4l2->ctrl_handler);
 	v4l2_device_unregister(&v4l2->v4l2_dev);
 err:
+	video_unregister_device(&v4l2->vdev);
 	dev->v4l2 = NULL;
 	kref_put(&v4l2->ref, em28xx_free_v4l2);
 	mutex_unlock(&dev->lock);
--

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [syzbot] [usb?] [media?] KASAN: use-after-free Read in v4l2_fh_open
  2024-03-02 23:07 ` Hillf Danton
@ 2024-03-02 23:39   ` syzbot
  0 siblings, 0 replies; 9+ messages in thread
From: syzbot @ 2024-03-02 23:39 UTC (permalink / raw)
  To: hdanton, linux-kernel, syzkaller-bugs

Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KASAN: slab-use-after-free Read in v4l2_open

==================================================================
BUG: KASAN: slab-use-after-free in v4l2_open+0x342/0x360 drivers/media/v4l2-core/v4l2-dev.c:432
Read of size 4 at addr ffff8880257b8800 by task v4l_id/5638

CPU: 1 PID: 5638 Comm: v4l_id Not tainted 6.8.0-rc6-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/25/2024
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x1b5/0x2a0 lib/dump_stack.c:106
 print_address_description mm/kasan/report.c:377 [inline]
 print_report+0x163/0x510 mm/kasan/report.c:488
 kasan_report+0xcd/0x100 mm/kasan/report.c:601
 v4l2_open+0x342/0x360 drivers/media/v4l2-core/v4l2-dev.c:432
 chrdev_open+0x50f/0x5d0 fs/char_dev.c:414
 do_dentry_open+0x8fd/0x1590 fs/open.c:953
 path_openat+0x280d/0x31d0 fs/namei.c:3645
 do_filp_open+0x26d/0x500 fs/namei.c:3829
 do_sys_openat2+0x12f/0x1c0 fs/open.c:1404
 do_sys_open fs/open.c:1419 [inline]
 __do_sys_openat fs/open.c:1435 [inline]
 __se_sys_openat fs/open.c:1430 [inline]
 __x64_sys_openat+0x247/0x290 fs/open.c:1430
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0x85/0x160 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x63/0x6b
RIP: 0033:0x7fd0c998f9a4
Code: 24 20 48 8d 44 24 30 48 89 44 24 28 64 8b 04 25 18 00 00 00 85 c0 75 2c 44 89 e2 48 89 ee bf 9c ff ff ff b8 01 01 00 00 0f 05 <48> 3d 00 f0 ff ff 76 60 48 8b 15 55 a4 0d 00 f7 d8 64 89 02 48 83
RSP: 002b:00007ffe99c37580 EFLAGS: 00000246 ORIG_RAX: 0000000000000101
RAX: ffffffffffffffda RBX: 00007ffe99c37798 RCX: 00007fd0c998f9a4
RDX: 0000000000000000 RSI: 00007ffe99c38f1e RDI: 00000000ffffff9c
RBP: 00007ffe99c38f1e R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007ffe99c377b0 R14: 000056109fa30670 R15: 00007fd0c9b4aa80
 </TASK>

Allocated by task 5003:
 kasan_save_stack mm/kasan/common.c:47 [inline]
 kasan_save_track+0x30/0x60 mm/kasan/common.c:68
 poison_kmalloc_redzone mm/kasan/common.c:370 [inline]
 __kasan_kmalloc+0x98/0xb0 mm/kasan/common.c:387
 kasan_kmalloc include/linux/kasan.h:211 [inline]
 kmalloc_trace+0x1e6/0x400 mm/slub.c:4012
 kmalloc include/linux/slab.h:590 [inline]
 kzalloc include/linux/slab.h:711 [inline]
 em28xx_v4l2_init+0x107/0x2dd0 drivers/media/usb/em28xx/em28xx-video.c:2539
 em28xx_init_extension+0x11f/0x1c0 drivers/media/usb/em28xx/em28xx-core.c:1116
 process_scheduled_works+0x96f/0x1490 kernel/workqueue.c:2633
 worker_thread+0xa5f/0xff0 kernel/workqueue.c:2787
 kthread+0x2cd/0x360 kernel/kthread.c:388
 ret_from_fork+0x48/0x80 arch/x86/kernel/process.c:147
 ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:243

Freed by task 5003:
 kasan_save_stack mm/kasan/common.c:47 [inline]
 kasan_save_track+0x30/0x60 mm/kasan/common.c:68
 kasan_save_free_info+0x40/0x50 mm/kasan/generic.c:589
 poison_slab_object+0xa6/0xe0 mm/kasan/common.c:240
 __kasan_slab_free+0x37/0x60 mm/kasan/common.c:256
 kasan_slab_free include/linux/kasan.h:184 [inline]
 slab_free_hook mm/slub.c:2121 [inline]
 slab_free mm/slub.c:4299 [inline]
 kfree+0x14a/0x370 mm/slub.c:4409
 em28xx_free_v4l2 drivers/media/usb/em28xx/em28xx-video.c:2120 [inline]
 kref_put include/linux/kref.h:65 [inline]
 em28xx_v4l2_init+0x1618/0x2dd0 drivers/media/usb/em28xx/em28xx-video.c:2909
 em28xx_init_extension+0x11f/0x1c0 drivers/media/usb/em28xx/em28xx-core.c:1116
 process_scheduled_works+0x96f/0x1490 kernel/workqueue.c:2633
 worker_thread+0xa5f/0xff0 kernel/workqueue.c:2787
 kthread+0x2cd/0x360 kernel/kthread.c:388
 ret_from_fork+0x48/0x80 arch/x86/kernel/process.c:147
 ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:243

The buggy address belongs to the object at ffff8880257b8000
 which belongs to the cache kmalloc-8k of size 8192
The buggy address is located 2048 bytes inside of
 freed 8192-byte region [ffff8880257b8000, ffff8880257ba000)

The buggy address belongs to the physical page:
page:ffffea000095ee00 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x257b8
head:ffffea000095ee00 order:3 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0xfff00000000840(slab|head|node=0|zone=1|lastcpupid=0x7ff)
page_type: 0xffffffff()
raw: 00fff00000000840 ffff888011442280 ffffea00007c9c00 0000000000000006
raw: 0000000000000000 0000000080020002 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 3, migratetype Unmovable, gfp_mask 0xd28c0(GFP_NOWAIT|__GFP_IO|__GFP_FS|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 4662, tgid 4662 (dhcpcd), ts 31219348806, free_ts 31206911230
 prep_new_page mm/page_alloc.c:1540 [inline]
 get_page_from_freelist+0x3355/0x34e0 mm/page_alloc.c:3311
 __alloc_pages+0x255/0x670 mm/page_alloc.c:4567
 alloc_slab_page+0x5f/0x150 include/linux/gfp.h:238
 new_slab+0x84/0x2f0 mm/slub.c:2354
 ___slab_alloc+0xc77/0x1310 mm/slub.c:3540
 __kmalloc_node_track_caller+0x2e9/0x570 mm/slub.c:3625
 kmalloc_reserve+0xf3/0x260 net/core/skbuff.c:582
 __alloc_skb+0x19f/0x3d0 net/core/skbuff.c:651
 alloc_skb include/linux/skbuff.h:1296 [inline]
 netlink_dump+0x204/0xc70 net/netlink/af_netlink.c:2231
 netlink_recvmsg+0x671/0x10f0 net/netlink/af_netlink.c:1990
 ____sys_recvmsg+0x28b/0x570 net/socket.c:1046
 __sys_recvmsg+0x280/0x360 net/socket.c:2845
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0x85/0x160 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x63/0x6b
page last free pid 4662 tgid 4662 stack trace:
 free_unref_page_prepare+0x94d/0xa60 include/linux/page_owner.h:24
 free_unref_page+0x37/0x3f0 mm/page_alloc.c:2486
 __put_partials+0xeb/0x130 mm/slub.c:2453
 put_cpu_partial+0x169/0x240 mm/slub.c:2997
 __slab_free+0x2c3/0x400 mm/slub.c:4166
 qlist_free_all+0x5e/0xc0 mm/kasan/quarantine.c:163
 kasan_quarantine_reduce+0x14b/0x160 mm/kasan/quarantine.c:286
 __kasan_slab_alloc+0x23/0x70 mm/kasan/common.c:322
 kasan_slab_alloc include/linux/kasan.h:201 [inline]
 slab_post_alloc_hook mm/slub.c:3813 [inline]
 slab_alloc_node mm/slub.c:3860 [inline]
 __do_kmalloc_node mm/slub.c:3980 [inline]
 __kmalloc+0x1dd/0x540 mm/slub.c:3994
 kmalloc include/linux/slab.h:594 [inline]
 tomoyo_add_entry security/tomoyo/common.c:2023 [inline]
 tomoyo_supervisor+0xdf1/0x1370 security/tomoyo/common.c:2095
 tomoyo_path_permission+0x243/0x360 security/tomoyo/file.c:168
 tomoyo_path_perm+0x442/0x5b0 security/tomoyo/file.c:838
 security_inode_getattr+0xd3/0x120 security/security.c:2238
 vfs_fstatat+0xca/0x1b0 fs/stat.c:173
 __se_sys_newfstatat fs/stat.c:468 [inline]
 __x64_sys_newfstatat+0xff/0x170 fs/stat.c:462
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0x85/0x160 arch/x86/entry/common.c:83

Memory state around the buggy address:
 ffff8880257b8700: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff8880257b8780: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff8880257b8800: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                   ^
 ffff8880257b8880: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff8880257b8900: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================


Tested on:

commit:         04b8076d Merge tag 'firewire-fixes-6.8-rc7' of git://g..
git tree:       https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
console output: https://syzkaller.appspot.com/x/log.txt?x=10309dca180000
kernel config:  https://syzkaller.appspot.com/x/.config?x=fa01a41dc74de670
dashboard link: https://syzkaller.appspot.com/bug?extid=b2391895514ed9ef4a8e
compiler:       Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch:          https://syzkaller.appspot.com/x/patch.diff?x=112b2732180000


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: KASAN: use-after-free Read in v4l2_fh_open
  2021-02-15 15:18 KASAN: use-after-free Read in v4l2_fh_open syzbot
                   ` (2 preceding siblings ...)
  2024-03-02 23:07 ` Hillf Danton
@ 2024-03-03  1:43 ` Hillf Danton
  2024-03-03  2:55   ` [syzbot] [usb?] [media?] " syzbot
  3 siblings, 1 reply; 9+ messages in thread
From: Hillf Danton @ 2024-03-03  1:43 UTC (permalink / raw)
  To: syzbot; +Cc: linux-kernel, syzkaller-bugs

On Mon, 15 Feb 2021 07:18:22 -0800
> syzbot found the following issue on:
> 
> HEAD commit:    291009f6 Merge tag 'pm-5.11-rc8' of git://git.kernel.org/p..
> git tree:       upstream
> C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=17179dd4d00000

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git  master

--- x/drivers/media/usb/em28xx/em28xx-video.c
+++ y/drivers/media/usb/em28xx/em28xx-video.c
@@ -2152,6 +2152,10 @@ static int em28xx_v4l2_open(struct file
 	if (mutex_lock_interruptible(&dev->lock))
 		return -ERESTARTSYS;
 
+	if (!dev->v4l2) {
+		mutex_unlock(&dev->lock);
+		return -ENODEV;
+	}
 	ret = v4l2_fh_open(filp);
 	if (ret) {
 		dev_err(&dev->intf->dev,
@@ -2161,6 +2165,7 @@ static int em28xx_v4l2_open(struct file
 		return ret;
 	}
 
+	v4l2 = dev->v4l2;
 	if (v4l2->users == 0) {
 		em28xx_set_mode(dev, EM28XX_ANALOG_MODE);
 
@@ -2376,10 +2381,17 @@ static const struct v4l2_ioctl_ops video
 #endif
 };
 
+static void em28xx_video_device_release(struct video_device *vd)
+{
+	struct em28xx_v4l2 *v4l2 = container_of(vd, struct em28xx_v4l2, vdev);
+
+	kref_put(&v4l2->ref, em28xx_free_v4l2);
+}
+
 static const struct video_device em28xx_video_template = {
 	.fops		= &em28xx_v4l_fops,
 	.ioctl_ops	= &video_ioctl_ops,
-	.release	= video_device_release_empty,
+	.release	= em28xx_video_device_release,
 	.tvnorms	= V4L2_STD_ALL,
 };
 
@@ -2788,6 +2800,7 @@ static int em28xx_v4l2_init(struct em28x
 			"unable to register video device (error=%i).\n", ret);
 		goto unregister_dev;
 	}
+	kref_get(&v4l2->ref); /* put by video_unregister_device() */
 
 	/* Allocate and fill vbi video_device struct */
 	if (em28xx_vbi_supported(dev) == 1) {
--

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [syzbot] [usb?] [media?] KASAN: use-after-free Read in v4l2_fh_open
  2024-03-03  1:43 ` Hillf Danton
@ 2024-03-03  2:55   ` syzbot
  0 siblings, 0 replies; 9+ messages in thread
From: syzbot @ 2024-03-03  2:55 UTC (permalink / raw)
  To: hdanton, linux-kernel, syzkaller-bugs

Hello,

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

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

Tested on:

commit:         04b8076d Merge tag 'firewire-fixes-6.8-rc7' of git://g..
git tree:       https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
console output: https://syzkaller.appspot.com/x/log.txt?x=12012abc180000
kernel config:  https://syzkaller.appspot.com/x/.config?x=fa01a41dc74de670
dashboard link: https://syzkaller.appspot.com/bug?extid=b2391895514ed9ef4a8e
compiler:       Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch:          https://syzkaller.appspot.com/x/patch.diff?x=1709bcf2180000

Note: testing is done by a robot and is best-effort only.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: KASAN: use-after-free Read in v4l2_fh_open
@ 2024-03-02  8:08 xingwei lee
  0 siblings, 0 replies; 9+ messages in thread
From: xingwei lee @ 2024-03-02  8:08 UTC (permalink / raw)
  To: linux-media, mchehab, syzkaller-bugs; +Cc: linux-kernel

Hello I found a bug in latest upstream tree titled "KASAN:
slab-use-after-free Read in v4l2_fh_open" and aslo titled "KASAN:
slab-use-after-free Read in em28xx_release_resources”.
I believe both of them are the same bug, and I found the bugs with the
same name reported by syzbot:
https://syzkaller.appspot.com/bug?extid=b2391895514ed9ef4a8e and
https://syzkaller.appspot.com/bug?extid=99d6c66dbbc484f50e1c, and I
believe this not the same bug.

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

kernel: lastest 5ad3cb0ed525b80c7f66c32b49a68c1f3510bec9
kernel config: https://syzkaller.appspot.com/text?tag=KernelConfig&x=4a65fa9f077ead01
with KMSAN enabled
compiler: gcc (GCC) 12.2.0

==================================================================
BUG: KASAN: slab-use-after-free in v4l2_fh_init+0x278/0x2c0
drivers/media/v4l2-core/v4l2-fh.c:25
Read of size 8 at addr ffff888053f9a738 by task v4l_id/21260
CPU: 0 PID: 21260 Comm: v4l_id Not tainted 6.8.0-rc6-00238-g5ad3cb0ed525 #17
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
1.16.2-1.fc38 04/01/2014
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0x5c/0xb0 lib/dump_stack.c:106
print_address_description mm/kasan/report.c:377 [inline]
print_report+0xc4/0x620 mm/kasan/report.c:488
kasan_report+0xda/0x110 mm/kasan/report.c:601
v4l2_fh_init+0x278/0x2c0 drivers/media/v4l2-core/v4l2-fh.c:25
v4l2_fh_open+0x7c/0xb0 drivers/media/v4l2-core/v4l2-fh.c:63
em28xx_v4l2_open+0x1ea/0x6a0 drivers/media/usb/em28xx/em28xx-video.c:2155
v4l2_open+0x1ed/0x400 drivers/media/v4l2-core/v4l2-dev.c:427
chrdev_open+0x215/0x610 fs/char_dev.c:414
do_dentry_open+0x5da/0x14f0 fs/open.c:953
do_open fs/namei.c:3645 [inline]
path_openat+0x1983/0x2740 fs/namei.c:3802
do_filp_open+0x1bc/0x400 fs/namei.c:3829
do_sys_openat2+0x12c/0x170 fs/open.c:1404
do_sys_open fs/open.c:1419 [inline]
__do_sys_openat fs/open.c:1435 [inline]
__se_sys_openat fs/open.c:1430 [inline]
__x64_sys_openat+0x134/0x1d0 fs/open.c:1430
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0x78/0x1c0 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x63/0x6b
RIP: 0033:0x7f30564a0e01
Code: 75 57 89 f0 25 00 00 41 00 3d 00 00 41 00 74 49 80 3d ea 27 0e
00 00 74 6d 89 da 48 89 ee bf 9c ff ff ff b5
RSP: 002b:00007ffffe493a00 EFLAGS: 00000202 ORIG_RAX: 0000000000000101
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f30564a0e01
RDX: 0000000000000000 RSI: 00007ffffe493f05 RDI: 00000000ffffff9c
RBP: 00007ffffe493f05 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000000000
R13: 00007ffffe493c30 R14: 0000560ca266fbf8 R15: 00007f30565c1020
</TASK>
Allocated by task 15533:
kasan_save_stack+0x33/0x50 mm/kasan/common.c:47
kasan_save_track+0x14/0x30 mm/kasan/common.c:68
poison_kmalloc_redzone mm/kasan/common.c:370 [inline]
__kasan_kmalloc+0xa2/0xb0 mm/kasan/common.c:387
kmalloc include/linux/slab.h:590 [inline]
kzalloc include/linux/slab.h:711 [inline]
em28xx_v4l2_init+0xe6/0x3b00 drivers/media/usb/em28xx/em28xx-video.c:2534
em28xx_init_extension+0x10a/0x1c0 drivers/media/usb/em28xx/em28xx-core.c:1116
process_one_work+0x789/0x12a0 kernel/workqueue.c:2633
process_scheduled_works kernel/workqueue.c:2706 [inline]
worker_thread+0x6fb/0x1170 kernel/workqueue.c:2787
kthread+0x2ed/0x3d0 kernel/kthread.c:388
ret_from_fork+0x2c/0x70 arch/x86/kernel/process.c:147
ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:243
Freed by task 15533:
kasan_save_stack+0x33/0x50 mm/kasan/common.c:47
kasan_save_track+0x14/0x30 mm/kasan/common.c:68
kasan_save_free_info+0x3b/0x60 mm/kasan/generic.c:589
poison_slab_object mm/kasan/common.c:240 [inline]
__kasan_slab_free+0x11d/0x1a0 mm/kasan/common.c:256
kasan_slab_free include/linux/kasan.h:184 [inline]
slab_free_hook mm/slub.c:2121 [inline]
slab_free mm/slub.c:4299 [inline]
kfree+0x124/0x360 mm/slub.c:4409
em28xx_free_v4l2 drivers/media/usb/em28xx/em28xx-video.c:2120 [inline]
kref_put include/linux/kref.h:65 [inline]
em28xx_v4l2_init+0x1d6c/0x3b00 drivers/media/usb/em28xx/em28xx-video.c:2903
em28xx_init_extension+0x10a/0x1c0 drivers/media/usb/em28xx/em28xx-core.c:1116
process_one_work+0x789/0x12a0 kernel/workqueue.c:2633
process_scheduled_works kernel/workqueue.c:2706 [inline]
worker_thread+0x6fb/0x1170 kernel/workqueue.c:2787
kthread+0x2ed/0x3d0 kernel/kthread.c:388
ret_from_fork+0x2c/0x70 arch/x86/kernel/process.c:147
ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:243



=* repro.c =*
#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 <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mount.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>

#include <linux/usb/ch9.h>

static unsigned long long procid;

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

#define MAX_FDS 30

#define USB_MAX_IFACE_NUM 4
#define USB_MAX_EP_NUM 32
#define USB_MAX_FDS 6

struct usb_endpoint_index {
 struct usb_endpoint_descriptor desc;
 int handle;
};

struct usb_iface_index {
 struct usb_interface_descriptor* iface;
 uint8_t bInterfaceNumber;
 uint8_t bAlternateSetting;
 uint8_t bInterfaceClass;
 struct usb_endpoint_index eps[USB_MAX_EP_NUM];
 int eps_num;
};

struct usb_device_index {
 struct usb_device_descriptor* dev;
 struct usb_config_descriptor* config;
 uint8_t bDeviceClass;
 uint8_t bMaxPower;
 int config_length;
 struct usb_iface_index ifaces[USB_MAX_IFACE_NUM];
 int ifaces_num;
 int iface_cur;
};

struct usb_info {
 int fd;
 struct usb_device_index index;
};

static struct usb_info usb_devices[USB_MAX_FDS];

static struct usb_device_index* lookup_usb_index(int fd) {
 for (int i = 0; i < USB_MAX_FDS; i++) {
   if (__atomic_load_n(&usb_devices[i].fd, __ATOMIC_ACQUIRE) == fd)
     return &usb_devices[i].index;
 }
 return NULL;
}

static int usb_devices_num;

static bool parse_usb_descriptor(const char* buffer,
                                size_t length,
                                struct usb_device_index* index) {
 if (length < sizeof(*index->dev) + sizeof(*index->config))
   return false;
 memset(index, 0, sizeof(*index));
 index->dev = (struct usb_device_descriptor*)buffer;
 index->config = (struct usb_config_descriptor*)(buffer + sizeof(*index->dev));
 index->bDeviceClass = index->dev->bDeviceClass;
 index->bMaxPower = index->config->bMaxPower;
 index->config_length = length - sizeof(*index->dev);
 index->iface_cur = -1;
 size_t offset = 0;
 while (true) {
   if (offset + 1 >= length)
     break;
   uint8_t desc_length = buffer[offset];
   uint8_t desc_type = buffer[offset + 1];
   if (desc_length <= 2)
     break;
   if (offset + desc_length > length)
     break;
   if (desc_type == USB_DT_INTERFACE &&
       index->ifaces_num < USB_MAX_IFACE_NUM) {
     struct usb_interface_descriptor* iface =
         (struct usb_interface_descriptor*)(buffer + offset);
     index->ifaces[index->ifaces_num].iface = iface;
     index->ifaces[index->ifaces_num].bInterfaceNumber =
         iface->bInterfaceNumber;
     index->ifaces[index->ifaces_num].bAlternateSetting =
         iface->bAlternateSetting;
     index->ifaces[index->ifaces_num].bInterfaceClass = iface->bInterfaceClass;
     index->ifaces_num++;
   }
   if (desc_type == USB_DT_ENDPOINT && index->ifaces_num > 0) {
     struct usb_iface_index* iface = &index->ifaces[index->ifaces_num - 1];
     if (iface->eps_num < USB_MAX_EP_NUM) {
       memcpy(&iface->eps[iface->eps_num].desc, buffer + offset,
              sizeof(iface->eps[iface->eps_num].desc));
       iface->eps_num++;
     }
   }
   offset += desc_length;
 }
 return true;
}

static struct usb_device_index* add_usb_index(int fd,
                                             const char* dev,
                                             size_t dev_len) {
 int i = __atomic_fetch_add(&usb_devices_num, 1, __ATOMIC_RELAXED);
 if (i >= USB_MAX_FDS)
   return NULL;
 if (!parse_usb_descriptor(dev, dev_len, &usb_devices[i].index))
   return NULL;
 __atomic_store_n(&usb_devices[i].fd, fd, __ATOMIC_RELEASE);
 return &usb_devices[i].index;
}

struct vusb_connect_string_descriptor {
 uint32_t len;
 char* str;
} __attribute__((packed));

struct vusb_connect_descriptors {
 uint32_t qual_len;
 char* qual;
 uint32_t bos_len;
 char* bos;
 uint32_t strs_len;
 struct vusb_connect_string_descriptor strs[0];
} __attribute__((packed));

static const char default_string[] = {8, USB_DT_STRING, 's', 0, 'y', 0, 'z', 0};

static const char default_lang_id[] = {4, USB_DT_STRING, 0x09, 0x04};

static bool lookup_connect_response_in(
   int fd,
   const struct vusb_connect_descriptors* descs,
   const struct usb_ctrlrequest* ctrl,
   struct usb_qualifier_descriptor* qual,
   char** response_data,
   uint32_t* response_length) {
 struct usb_device_index* index = lookup_usb_index(fd);
 uint8_t str_idx;
 if (!index)
   return false;
 switch (ctrl->bRequestType & USB_TYPE_MASK) {
   case USB_TYPE_STANDARD:
     switch (ctrl->bRequest) {
       case USB_REQ_GET_DESCRIPTOR:
         switch (ctrl->wValue >> 8) {
           case USB_DT_DEVICE:
             *response_data = (char*)index->dev;
             *response_length = sizeof(*index->dev);
             return true;
           case USB_DT_CONFIG:
             *response_data = (char*)index->config;
             *response_length = index->config_length;
             return true;
           case USB_DT_STRING:
             str_idx = (uint8_t)ctrl->wValue;
             if (descs && str_idx < descs->strs_len) {
               *response_data = descs->strs[str_idx].str;
               *response_length = descs->strs[str_idx].len;
               return true;
             }
             if (str_idx == 0) {
               *response_data = (char*)&default_lang_id[0];
               *response_length = default_lang_id[0];
               return true;
             }
             *response_data = (char*)&default_string[0];
             *response_length = default_string[0];
             return true;
           case USB_DT_BOS:
             *response_data = descs->bos;
             *response_length = descs->bos_len;
             return true;
           case USB_DT_DEVICE_QUALIFIER:
             if (!descs->qual) {
               qual->bLength = sizeof(*qual);
               qual->bDescriptorType = USB_DT_DEVICE_QUALIFIER;
               qual->bcdUSB = index->dev->bcdUSB;
               qual->bDeviceClass = index->dev->bDeviceClass;
               qual->bDeviceSubClass = index->dev->bDeviceSubClass;
               qual->bDeviceProtocol = index->dev->bDeviceProtocol;
               qual->bMaxPacketSize0 = index->dev->bMaxPacketSize0;
               qual->bNumConfigurations = index->dev->bNumConfigurations;
               qual->bRESERVED = 0;
               *response_data = (char*)qual;
               *response_length = sizeof(*qual);
               return true;
             }
             *response_data = descs->qual;
             *response_length = descs->qual_len;
             return true;
           default:
             break;
         }
         break;
       default:
         break;
     }
     break;
   default:
     break;
 }
 return false;
}

typedef bool (*lookup_connect_out_response_t)(
   int fd,
   const struct vusb_connect_descriptors* descs,
   const struct usb_ctrlrequest* ctrl,
   bool* done);

static bool lookup_connect_response_out_generic(
   int fd,
   const struct vusb_connect_descriptors* descs,
   const struct usb_ctrlrequest* ctrl,
   bool* done) {
 switch (ctrl->bRequestType & USB_TYPE_MASK) {
   case USB_TYPE_STANDARD:
     switch (ctrl->bRequest) {
       case USB_REQ_SET_CONFIGURATION:
         *done = true;
         return true;
       default:
         break;
     }
     break;
 }
 return false;
}

#define UDC_NAME_LENGTH_MAX 128

struct usb_raw_init {
 __u8 driver_name[UDC_NAME_LENGTH_MAX];
 __u8 device_name[UDC_NAME_LENGTH_MAX];
 __u8 speed;
};

enum usb_raw_event_type {
 USB_RAW_EVENT_INVALID = 0,
 USB_RAW_EVENT_CONNECT = 1,
 USB_RAW_EVENT_CONTROL = 2,
};

struct usb_raw_event {
 __u32 type;
 __u32 length;
 __u8 data[0];
};

struct usb_raw_ep_io {
 __u16 ep;
 __u16 flags;
 __u32 length;
 __u8 data[0];
};

#define USB_RAW_EPS_NUM_MAX 30
#define USB_RAW_EP_NAME_MAX 16
#define USB_RAW_EP_ADDR_ANY 0xff

struct usb_raw_ep_caps {
 __u32 type_control : 1;
 __u32 type_iso : 1;
 __u32 type_bulk : 1;
 __u32 type_int : 1;
 __u32 dir_in : 1;
 __u32 dir_out : 1;
};

struct usb_raw_ep_limits {
 __u16 maxpacket_limit;
 __u16 max_streams;
 __u32 reserved;
};

struct usb_raw_ep_info {
 __u8 name[USB_RAW_EP_NAME_MAX];
 __u32 addr;
 struct usb_raw_ep_caps caps;
 struct usb_raw_ep_limits limits;
};

struct usb_raw_eps_info {
 struct usb_raw_ep_info eps[USB_RAW_EPS_NUM_MAX];
};

#define USB_RAW_IOCTL_INIT _IOW('U', 0, struct usb_raw_init)
#define USB_RAW_IOCTL_RUN _IO('U', 1)
#define USB_RAW_IOCTL_EVENT_FETCH _IOR('U', 2, struct usb_raw_event)
#define USB_RAW_IOCTL_EP0_WRITE _IOW('U', 3, struct usb_raw_ep_io)
#define USB_RAW_IOCTL_EP0_READ _IOWR('U', 4, struct usb_raw_ep_io)
#define USB_RAW_IOCTL_EP_ENABLE _IOW('U', 5, struct usb_endpoint_descriptor)
#define USB_RAW_IOCTL_EP_DISABLE _IOW('U', 6, __u32)
#define USB_RAW_IOCTL_EP_WRITE _IOW('U', 7, struct usb_raw_ep_io)
#define USB_RAW_IOCTL_EP_READ _IOWR('U', 8, struct usb_raw_ep_io)
#define USB_RAW_IOCTL_CONFIGURE _IO('U', 9)
#define USB_RAW_IOCTL_VBUS_DRAW _IOW('U', 10, __u32)
#define USB_RAW_IOCTL_EPS_INFO _IOR('U', 11, struct usb_raw_eps_info)
#define USB_RAW_IOCTL_EP0_STALL _IO('U', 12)
#define USB_RAW_IOCTL_EP_SET_HALT _IOW('U', 13, __u32)
#define USB_RAW_IOCTL_EP_CLEAR_HALT _IOW('U', 14, __u32)
#define USB_RAW_IOCTL_EP_SET_WEDGE _IOW('U', 15, __u32)

static int usb_raw_open() {
 return open("/dev/raw-gadget", O_RDWR);
}

static int usb_raw_init(int fd,
                       uint32_t speed,
                       const char* driver,
                       const char* device) {
 struct usb_raw_init arg;
 strncpy((char*)&arg.driver_name[0], driver, sizeof(arg.driver_name));
 strncpy((char*)&arg.device_name[0], device, sizeof(arg.device_name));
 arg.speed = speed;
 return ioctl(fd, USB_RAW_IOCTL_INIT, &arg);
}

static int usb_raw_run(int fd) {
 return ioctl(fd, USB_RAW_IOCTL_RUN, 0);
}

static int usb_raw_configure(int fd) {
 return ioctl(fd, USB_RAW_IOCTL_CONFIGURE, 0);
}

static int usb_raw_vbus_draw(int fd, uint32_t power) {
 return ioctl(fd, USB_RAW_IOCTL_VBUS_DRAW, power);
}

static int usb_raw_ep0_write(int fd, struct usb_raw_ep_io* io) {
 return ioctl(fd, USB_RAW_IOCTL_EP0_WRITE, io);
}

static int usb_raw_ep0_read(int fd, struct usb_raw_ep_io* io) {
 return ioctl(fd, USB_RAW_IOCTL_EP0_READ, io);
}

static int usb_raw_event_fetch(int fd, struct usb_raw_event* event) {
 return ioctl(fd, USB_RAW_IOCTL_EVENT_FETCH, event);
}

static int usb_raw_ep_enable(int fd, struct usb_endpoint_descriptor* desc) {
 return ioctl(fd, USB_RAW_IOCTL_EP_ENABLE, desc);
}

static int usb_raw_ep_disable(int fd, int ep) {
 return ioctl(fd, USB_RAW_IOCTL_EP_DISABLE, ep);
}

static int usb_raw_ep0_stall(int fd) {
 return ioctl(fd, USB_RAW_IOCTL_EP0_STALL, 0);
}

#define USB_MAX_PACKET_SIZE 4096

struct usb_raw_control_event {
 struct usb_raw_event inner;
 struct usb_ctrlrequest ctrl;
 char data[USB_MAX_PACKET_SIZE];
};

struct usb_raw_ep_io_data {
 struct usb_raw_ep_io inner;
 char data[USB_MAX_PACKET_SIZE];
};

static void set_interface(int fd, int n) {
 struct usb_device_index* index = lookup_usb_index(fd);
 if (!index)
   return;
 if (index->iface_cur >= 0 && index->iface_cur < index->ifaces_num) {
   for (int ep = 0; ep < index->ifaces[index->iface_cur].eps_num; ep++) {
     int rv = usb_raw_ep_disable(
         fd, index->ifaces[index->iface_cur].eps[ep].handle);
     if (rv < 0) {
     } else {
     }
   }
 }
 if (n >= 0 && n < index->ifaces_num) {
   for (int ep = 0; ep < index->ifaces[n].eps_num; ep++) {
     int rv = usb_raw_ep_enable(fd, &index->ifaces[n].eps[ep].desc);
     if (rv < 0) {
     } else {
       index->ifaces[n].eps[ep].handle = rv;
     }
   }
   index->iface_cur = n;
 }
}

static int configure_device(int fd) {
 struct usb_device_index* index = lookup_usb_index(fd);
 if (!index)
   return -1;
 int rv = usb_raw_vbus_draw(fd, index->bMaxPower);
 if (rv < 0) {
   return rv;
 }
 rv = usb_raw_configure(fd);
 if (rv < 0) {
   return rv;
 }
 set_interface(fd, 0);
 return 0;
}

static volatile long syz_usb_connect_impl(
   uint64_t speed,
   uint64_t dev_len,
   const char* dev,
   const struct vusb_connect_descriptors* descs,
   lookup_connect_out_response_t lookup_connect_response_out) {
 if (!dev) {
   return -1;
 }
 int fd = usb_raw_open();
 if (fd < 0) {
   return fd;
 }
 if (fd >= MAX_FDS) {
   close(fd);
   return -1;
 }
 struct usb_device_index* index = add_usb_index(fd, dev, dev_len);
 if (!index) {
   return -1;
 }
 char device[32];
 sprintf(&device[0], "dummy_udc.%llu", procid);
 int rv = usb_raw_init(fd, speed, "dummy_udc", &device[0]);
 if (rv < 0) {
   return rv;
 }
 rv = usb_raw_run(fd);
 if (rv < 0) {
   return rv;
 }
 bool done = false;
 while (!done) {
   struct usb_raw_control_event event;
   event.inner.type = 0;
   event.inner.length = sizeof(event.ctrl);
   rv = usb_raw_event_fetch(fd, (struct usb_raw_event*)&event);
   if (rv < 0) {
     return rv;
   }
   if (event.inner.type != USB_RAW_EVENT_CONTROL)
     continue;
   char* response_data = NULL;
   uint32_t response_length = 0;
   struct usb_qualifier_descriptor qual;
   if (event.ctrl.bRequestType & USB_DIR_IN) {
     if (!lookup_connect_response_in(fd, descs, &event.ctrl, &qual,
                                     &response_data, &response_length)) {
       usb_raw_ep0_stall(fd);
       continue;
     }
   } else {
     if (!lookup_connect_response_out(fd, descs, &event.ctrl, &done)) {
       usb_raw_ep0_stall(fd);
       continue;
     }
     response_data = NULL;
     response_length = event.ctrl.wLength;
   }
   if ((event.ctrl.bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD &&
       event.ctrl.bRequest == USB_REQ_SET_CONFIGURATION) {
     rv = configure_device(fd);
     if (rv < 0) {
       return rv;
     }
   }
   struct usb_raw_ep_io_data response;
   response.inner.ep = 0;
   response.inner.flags = 0;
   if (response_length > sizeof(response.data))
     response_length = 0;
   if (event.ctrl.wLength < response_length)
     response_length = event.ctrl.wLength;
   response.inner.length = response_length;
   if (response_data)
     memcpy(&response.data[0], response_data, response_length);
   else
     memset(&response.data[0], 0, response_length);
   if (event.ctrl.bRequestType & USB_DIR_IN) {
     rv = usb_raw_ep0_write(fd, (struct usb_raw_ep_io*)&response);
   } else {
     rv = usb_raw_ep0_read(fd, (struct usb_raw_ep_io*)&response);
   }
   if (rv < 0) {
     return rv;
   }
 }
 sleep_ms(200);
 return fd;
}

static volatile long syz_usb_connect(volatile long a0,
                                    volatile long a1,
                                    volatile long a2,
                                    volatile long a3) {
 uint64_t speed = a0;
 uint64_t dev_len = a1;
 const char* dev = (const char*)a2;
 const struct vusb_connect_descriptors* descs =
     (const struct vusb_connect_descriptors*)a3;
 return syz_usb_connect_impl(speed, dev_len, dev, descs,
                             &lookup_connect_response_out_generic);
}

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 (;;) {
     if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
       break;
     sleep_ms(1);
     if (current_time_ms() - start < 5000)
       continue;
     kill_and_wait(pid, &status);
     break;
   }
 }
}

void execute_one(void) {
 *(uint8_t*)0x20000040 = 0x12;
 *(uint8_t*)0x20000041 = 1;
 *(uint16_t*)0x20000042 = 0;
 *(uint8_t*)0x20000044 = 0x42;
 *(uint8_t*)0x20000045 = 0x21;
 *(uint8_t*)0x20000046 = 0x7a;
 *(uint8_t*)0x20000047 = 0x40;
 *(uint16_t*)0x20000048 = 0x413;
 *(uint16_t*)0x2000004a = 0x6023;
 *(uint16_t*)0x2000004c = 0xc128;
 *(uint8_t*)0x2000004e = 0;
 *(uint8_t*)0x2000004f = 0;
 *(uint8_t*)0x20000050 = 0;
 *(uint8_t*)0x20000051 = 1;
 *(uint8_t*)0x20000052 = 9;
 *(uint8_t*)0x20000053 = 2;
 *(uint16_t*)0x20000054 = 0xdb;
 *(uint8_t*)0x20000056 = 1;
 *(uint8_t*)0x20000057 = 0;
 *(uint8_t*)0x20000058 = 0;
 *(uint8_t*)0x20000059 = 0;
 *(uint8_t*)0x2000005a = 0;
 *(uint8_t*)0x2000005b = 9;
 *(uint8_t*)0x2000005c = 4;
 *(uint8_t*)0x2000005d = 0x44;
 *(uint8_t*)0x2000005e = 0;
 *(uint8_t*)0x2000005f = 0xf;
 *(uint8_t*)0x20000060 = 0x2b;
 *(uint8_t*)0x20000061 = 0xb6;
 *(uint8_t*)0x20000062 = 0x34;
 *(uint8_t*)0x20000063 = 0;
 *(uint8_t*)0x20000064 = 9;
 *(uint8_t*)0x20000065 = 5;
 *(uint8_t*)0x20000066 = 0x40;
 *(uint8_t*)0x20000067 = 8;
 *(uint16_t*)0x20000068 = 0x10;
 *(uint8_t*)0x2000006a = 0x7f;
 *(uint8_t*)0x2000006b = 0x80;
 *(uint8_t*)0x2000006c = 0xdb;
 *(uint8_t*)0x2000006d = 2;
 *(uint8_t*)0x2000006e = 0x22;
 *(uint8_t*)0x2000006f = 7;
 *(uint8_t*)0x20000070 = 0x25;
 *(uint8_t*)0x20000071 = 1;
 *(uint8_t*)0x20000072 = 0x80;
 *(uint8_t*)0x20000073 = 7;
 *(uint16_t*)0x20000074 = 9;
 *(uint8_t*)0x20000076 = 9;
 *(uint8_t*)0x20000077 = 5;
 *(uint8_t*)0x20000078 = 0x82;
 *(uint8_t*)0x20000079 = 4;
 *(uint16_t*)0x2000007a = 0x200;
 *(uint8_t*)0x2000007c = 0x2c;
 *(uint8_t*)0x2000007d = 0x33;
 *(uint8_t*)0x2000007e = 9;
 *(uint8_t*)0x2000007f = 7;
 *(uint8_t*)0x20000080 = 0x25;
 *(uint8_t*)0x20000081 = 1;
 *(uint8_t*)0x20000082 = 3;
 *(uint8_t*)0x20000083 = 0x3f;
 *(uint16_t*)0x20000084 = 0xf49;
 *(uint8_t*)0x20000086 = 7;
 *(uint8_t*)0x20000087 = 0x25;
 *(uint8_t*)0x20000088 = 1;
 *(uint8_t*)0x20000089 = 2;
 *(uint8_t*)0x2000008a = 7;
 *(uint16_t*)0x2000008b = 0x400;
 *(uint8_t*)0x2000008d = 9;
 *(uint8_t*)0x2000008e = 5;
 *(uint8_t*)0x2000008f = 0xa;
 *(uint8_t*)0x20000090 = 4;
 *(uint16_t*)0x20000091 = 0x20;
 *(uint8_t*)0x20000093 = 4;
 *(uint8_t*)0x20000094 = 3;
 *(uint8_t*)0x20000095 = 0x80;
 *(uint8_t*)0x20000096 = 9;
 *(uint8_t*)0x20000097 = 5;
 *(uint8_t*)0x20000098 = 0xf;
 *(uint8_t*)0x20000099 = 0;
 *(uint16_t*)0x2000009a = 0x200;
 *(uint8_t*)0x2000009c = 0xbb;
 *(uint8_t*)0x2000009d = 0x17;
 *(uint8_t*)0x2000009e = 1;
 *(uint8_t*)0x2000009f = 9;
 *(uint8_t*)0x200000a0 = 5;
 *(uint8_t*)0x200000a1 = 0xb;
 *(uint8_t*)0x200000a2 = 0x10;
 *(uint16_t*)0x200000a3 = 8;
 *(uint8_t*)0x200000a5 = 5;
 *(uint8_t*)0x200000a6 = 0x3f;
 *(uint8_t*)0x200000a7 = 0;
 *(uint8_t*)0x200000a8 = 7;
 *(uint8_t*)0x200000a9 = 0x25;
 *(uint8_t*)0x200000aa = 1;
 *(uint8_t*)0x200000ab = 0x80;
 *(uint8_t*)0x200000ac = 0x81;
 *(uint16_t*)0x200000ad = 0xa62b;
 *(uint8_t*)0x200000af = 9;
 *(uint8_t*)0x200000b0 = 5;
 *(uint8_t*)0x200000b1 = 4;
 *(uint8_t*)0x200000b2 = 0;
 *(uint16_t*)0x200000b3 = 0x200;
 *(uint8_t*)0x200000b5 = 1;
 *(uint8_t*)0x200000b6 = 4;
 *(uint8_t*)0x200000b7 = 0x1f;
 *(uint8_t*)0x200000b8 = 9;
 *(uint8_t*)0x200000b9 = 5;
 *(uint8_t*)0x200000ba = 0xb;
 *(uint8_t*)0x200000bb = 4;
 *(uint16_t*)0x200000bc = 0x10;
 *(uint8_t*)0x200000be = 0x12;
 *(uint8_t*)0x200000bf = 0xea;
 *(uint8_t*)0x200000c0 = 0xc;
 *(uint8_t*)0x200000c1 = 2;
 *(uint8_t*)0x200000c2 = 0x21;
 *(uint8_t*)0x200000c3 = 2;
 *(uint8_t*)0x200000c4 = 0xb;
 *(uint8_t*)0x200000c5 = 9;
 *(uint8_t*)0x200000c6 = 5;
 *(uint8_t*)0x200000c7 = 0xc;
 *(uint8_t*)0x200000c8 = 0xc;
 *(uint16_t*)0x200000c9 = 0x40;
 *(uint8_t*)0x200000cb = 6;
 *(uint8_t*)0x200000cc = 0xa4;
 *(uint8_t*)0x200000cd = 8;
 *(uint8_t*)0x200000ce = 9;
 *(uint8_t*)0x200000cf = 5;
 *(uint8_t*)0x200000d0 = 0xb;
 *(uint8_t*)0x200000d1 = 0x10;
 *(uint16_t*)0x200000d2 = 0x10;
 *(uint8_t*)0x200000d4 = 4;
 *(uint8_t*)0x200000d5 = 0x20;
 *(uint8_t*)0x200000d6 = 7;
 *(uint8_t*)0x200000d7 = 7;
 *(uint8_t*)0x200000d8 = 0x25;
 *(uint8_t*)0x200000d9 = 1;
 *(uint8_t*)0x200000da = 3;
 *(uint8_t*)0x200000db = 3;
 *(uint16_t*)0x200000dc = 0xff34;
 *(uint8_t*)0x200000de = 9;
 *(uint8_t*)0x200000df = 5;
 *(uint8_t*)0x200000e0 = 2;
 *(uint8_t*)0x200000e1 = 0xc;
 *(uint16_t*)0x200000e2 = 0x10;
 *(uint8_t*)0x200000e4 = 2;
 *(uint8_t*)0x200000e5 = 1;
 *(uint8_t*)0x200000e6 = -1;
 *(uint8_t*)0x200000e7 = 7;
 *(uint8_t*)0x200000e8 = 0x25;
 *(uint8_t*)0x200000e9 = 1;
 *(uint8_t*)0x200000ea = 0x80;
 *(uint8_t*)0x200000eb = 4;
 *(uint16_t*)0x200000ec = 6;
 *(uint8_t*)0x200000ee = 7;
 *(uint8_t*)0x200000ef = 0x25;
 *(uint8_t*)0x200000f0 = 1;
 *(uint8_t*)0x200000f1 = 0x82;
 *(uint8_t*)0x200000f2 = 1;
 *(uint16_t*)0x200000f3 = 9;
 *(uint8_t*)0x200000f5 = 9;
 *(uint8_t*)0x200000f6 = 5;
 *(uint8_t*)0x200000f7 = 0xa;
 *(uint8_t*)0x200000f8 = 0;
 *(uint16_t*)0x200000f9 = 0x40;
 *(uint8_t*)0x200000fb = 0x80;
 *(uint8_t*)0x200000fc = 0x7f;
 *(uint8_t*)0x200000fd = 0xf9;
 *(uint8_t*)0x200000fe = 7;
 *(uint8_t*)0x200000ff = 0x25;
 *(uint8_t*)0x20000100 = 1;
 *(uint8_t*)0x20000101 = 0x80;
 *(uint8_t*)0x20000102 = 0x40;
 *(uint16_t*)0x20000103 = 0x800;
 *(uint8_t*)0x20000105 = 9;
 *(uint8_t*)0x20000106 = 5;
 *(uint8_t*)0x20000107 = 5;
 *(uint8_t*)0x20000108 = 0xc;
 *(uint16_t*)0x20000109 = 0x20;
 *(uint8_t*)0x2000010b = 6;
 *(uint8_t*)0x2000010c = 0;
 *(uint8_t*)0x2000010d = 5;
 *(uint8_t*)0x2000010e = 2;
 *(uint8_t*)0x2000010f = 5;
 *(uint8_t*)0x20000110 = 2;
 *(uint8_t*)0x20000111 = 7;
 *(uint8_t*)0x20000112 = 9;
 *(uint8_t*)0x20000113 = 5;
 *(uint8_t*)0x20000114 = 7;
 *(uint8_t*)0x20000115 = 3;
 *(uint16_t*)0x20000116 = 0x10;
 *(uint8_t*)0x20000118 = 0xfd;
 *(uint8_t*)0x20000119 = 4;
 *(uint8_t*)0x2000011a = 0x40;
 *(uint8_t*)0x2000011b = 9;
 *(uint8_t*)0x2000011c = 5;
 *(uint8_t*)0x2000011d = 7;
 *(uint8_t*)0x2000011e = 7;
 *(uint16_t*)0x2000011f = 8;
 *(uint8_t*)0x20000121 = 0;
 *(uint8_t*)0x20000122 = 9;
 *(uint8_t*)0x20000123 = 0x81;
 *(uint8_t*)0x20000124 = 9;
 *(uint8_t*)0x20000125 = 5;
 *(uint8_t*)0x20000126 = 0xe;
 *(uint8_t*)0x20000127 = 0x10;
 *(uint16_t*)0x20000128 = 0x400;
 *(uint8_t*)0x2000012a = 1;
 *(uint8_t*)0x2000012b = 8;
 *(uint8_t*)0x2000012c = 0x20;
 syz_usb_connect(/*speed=*/0, /*dev_len=*/0xed, /*dev=*/0x20000040,
                 /*conn_descs=*/0);
}
int main(void) {
 syscall(__NR_mmap, /*addr=*/0x1ffff000ul, /*len=*/0x1000ul, /*prot=*/0ul,
         /*flags=*/0x32ul, /*fd=*/-1, /*offset=*/0ul);
 syscall(__NR_mmap, /*addr=*/0x20000000ul, /*len=*/0x1000000ul, /*prot=*/7ul,
         /*flags=*/0x32ul, /*fd=*/-1, /*offset=*/0ul);
 syscall(__NR_mmap, /*addr=*/0x21000000ul, /*len=*/0x1000ul, /*prot=*/0ul,
         /*flags=*/0x32ul, /*fd=*/-1, /*offset=*/0ul);
 loop();
 return 0;
}


=* repro.txt =*
syz_usb_connect(0x0, 0x432, &(0x7f0000000040)={{0x12, 0x1, 0x0, 0x42,
0x21, 0x7a, 0x40, 0x413, 0x6023, 0xc128, 0x0, 0x0, 0x0, 0x1,
[{{0x9,0x2, 0x420, 0x1, 0x0, 0x0, 0x0, 0x0, [{{0x9, 0x4, 0x44, 0x0,
0xf, 0x2b, 0xb6, 0x34, 0x0, [], [{{0x9, 0x5, 0x65268aa22f44d640, 0x8,
0x10, 0x7f, 0x80, 0xdb, [@generic={0x57, 0x22,
"6842ca7bf31d0143618a52cac09b83bff3f60fa0736b77c6eccaf7eb500c0ec59af07a8ce80cef3c2c0d57a13d8171c83cddcf772e53cdd9c1c10b732a821410d572c5528ac48f055a3844538aada94f2d8702fab1"},
@uac_iso={0x7, 0x25, 0x1, 0x80, 0x7, 0x9}]}}, {{0x9, 0x5, 0x82, 0x4,
0x200, 0x2c, 0x33, 0x9, [@uac_iso={0x7, 0x25, 0x1, 0x3, 0x3f, 0xf49},
@uac_iso={0x7, 0x25, 0x1, 0x2, 0x7, 0x400}]}}, {{0x9, 0x5, 0xa, 0x4,
0x20, 0x4, 0x3, 0x80}}, {{0x9, 0x5, 0xf, 0x0, 0x200, 0xbb, 0x17,
0x1}}, {{0x9, 0x5, 0xb, 0x10, 0x8, 0x5, 0x3f, 0x0, [@uac_iso={0x7,
0x25, 0x1, 0x80, 0x81, 0xa62b}]}}, {{0x9, 0x5, 0x4, 0x0, 0x200, 0x1,
0x4, 0x1f}}, {{0x9, 0x5, 0xb, 0x4, 0x10, 0x12, 0xea, 0xc,
[@generic={0xed, 0x21,
"08127f0f4f83fec83e08741a32c7e58422f72562136cd7b9d82db0c264c2fc37abfca1db646e6be411deadb2b650255eac8917df8f3f36c97efef0d23c90c281df73c0c07a5f3cdd23b1249a7465827a62acb89f43161251f496e961b2bada6e06551dafd2a52c93cc8685180dc1eca124e289ba9f1deddbb6ad0cf34b8a36d61937c472ae928155ca9943bc2b6eb3c3a8169951a8e8c6e9bc1b4eaa236e90b9694fc42b1a0712581cfd2ad60c63017370e0cc354856748351a049eb031b63d4539aa4cea7e62b4ab706d01ed6947263c2453a87e4d288df723b76f2481ef425dc2799ff3816d5095a9835"},
@generic={0xf9, 0xb,
"dce59870ed7c15d59e2f62353374609704da54e4b507d263b09deb7c3c01236058718d919238a938221dc97681d20c639a5ebcd2dfe08c2c20672e3afd1121783144061974eb7d818536515d97db0cc1983cfa4de27b9ac3f8363a7da644886592f39a00d799c8887bc3300bb508a62afd0fc9a5f366b06fd04ede53b62cec94845eab41b138fffb86e04ed868592e463119faf7453c77b4b1f12c01d94c187279a5e3f673105824531de3cc89b127a03843e874f051ab35af668d61efc294cfe8c8726fc1d0ec4754fea52c35b61682af3d6c722edb819128cb95320e6e72a74073fcb14bfada62a389d25d0cce2fdaa4922b8d167f89"}]}},
{{0x9, 0x5, 0xc, 0xc, 0x40, 0x6, 0xa4, 0x8}}, {{0x9, 0x5, 0xb, 0x10,
0x10, 0x4, 0x20, 0x7, [@uac_iso={0x7, 0x25, 0x1, 0x3, 0x3, 0xff34}]}},
{{0x9, 0x5, 0x2, 0xc, 0x10, 0x2, 0x1, 0xff, [@uac_iso={0x7, 0x25, 0x1,
0x80, 0x4, 0x6}, @uac_iso={0x7, 0x25, 0x1, 0x82, 0x1, 0x9}]}}, {{0x9,
0x5, 0xa, 0x0, 0x40, 0x80, 0x7f, 0xf9, [@uac_iso={0x7, 0x25, 0x1,
0x80, 0x40, 0x800}]}}, {{0x9, 0x5, 0x5, 0xc, 0x20, 0x6, 0x0, 0x5,
[@generic={0x7a, 0x5,
"e39ae978b524cf1a138e7d85bbb05621f8bb638e46c34283cbd6133b287a2d0fdca0a81b5bf5844913d5b648914f94cc9c7fafb04471e90e5aab900141c5ba31a10afefa666446c570700e0a324ab93f48eb9c2ea15970f19ecec27fa412f8c549bad2cd378512dbd4820973d7fd56ec1f0ef6003187ca18"},
@generic={0x98, 0x7,
"1d595e30b5dd2d17a99443dba7bd307a99e0018050c69bbdaa0917291dd754ef39acd49ecbe36f9e8086f0d7ec384ba81f18056b4f4cb4c08189589e63a0e7366681d16d77837b9961f34c5e1e162c51d51f848edda2c9a81d696383e11cc7ee3bca076aeadf60b158cf17084872b168377c928b5dd80c2612de496483e06076cf4d456e8d26dca9b1dbc42d89ef8518e4f6457ae8d7"}]}},
{{0x9, 0x5, 0x7, 0x3, 0x10, 0xfd, 0x4, 0x40}}, {{0x9, 0x5, 0x7, 0x7,
0x8, 0x0, 0x9, 0x81}}, {{0x9, 0x5, 0xe, 0x10, 0x400, 0x1, 0x8,
0x20}}]}}]}}]}}, 0x0)

and the bug titled "KASAN: slab-use-after-free Read in
em28xx_release_resources” also have a repro.prog

=* repro1.txt =*
executing program 0:
syz_usb_connect(0x0, 0xed, &(0x7f0000000040)={{0x12, 0x1, 0x0, 0x42,
0x21, 0x7a, 0x40, 0x413, 0x6023, 0xc128, 0x0, 0x0, 0x0, 0x1, [{{0x9,
0x2, 0xdb, 0x1, 0x0, 0x0, 0x0, 0x0, [{{0x9, 0x4, 0x44, 0x0, 0xf, 0x2b,
0xb6, 0x34, 0x0, [], [{{0x9, 0x5, 0x65268aa22f44d640, 0x8, 0x10, 0x7f,
0x80, 0xdb, [@generic={0x2, 0x22}, @uac_iso={0x7, 0x25, 0x1, 0x80,
0x7, 0x9}]}}, {{0x9, 0x5, 0x82, 0x4, 0x200, 0x2c, 0x33, 0x9,
[@uac_iso={0x7, 0x25, 0x1, 0x3, 0x3f, 0xf49}, @uac_iso={0x7, 0x25,
0x1, 0x2, 0x7, 0x400}]}}, {{0x9, 0x5, 0xa, 0x4, 0x20, 0x4, 0x3,
0x80}}, {{0x9, 0x5, 0xf, 0x0, 0x200, 0xbb, 0x17, 0x1}}, {{0x9, 0x5,
0xb, 0x10, 0x8, 0x5, 0x3f, 0x0, [@uac_iso={0x7, 0x25, 0x1, 0x80, 0x81,
0xa62b}]}}, {{0x9, 0x5, 0x4, 0x0, 0x200, 0x1, 0x4, 0x1f}}, {{0x9, 0x5,
0xb, 0x4, 0x10, 0x12, 0xea, 0xc, [@generic={0x2, 0x21}, @generic={0x2,
0xb}]}}, {{0x9, 0x5, 0xc, 0xc, 0x40, 0x6, 0xa4, 0x8}}, {{0x9, 0x5,
0xb, 0x10, 0x10, 0x4, 0x20, 0x7, [@uac_iso={0x7, 0x25, 0x1, 0x3, 0x3,
0xff34}]}}, {{0x9, 0x5, 0x2, 0xc, 0x10, 0x2, 0x1, 0xff,
[@uac_iso={0x7, 0x25, 0x1, 0x80, 0x4, 0x6}, @uac_iso={0x7, 0x25, 0x1,
0x82, 0x1, 0x9}]}}, {{0x9, 0x5, 0xa, 0x0, 0x40, 0x80, 0x7f, 0xf9,
[@uac_iso={0x7, 0x25, 0x1, 0x80, 0x40, 0x800}]}}, {{0x9, 0x5, 0x5,
0xc, 0x20, 0x6, 0x0, 0x5, [@generic={0x2, 0x5}, @generic={0x2,
0x7}]}}, {{0x9, 0x5, 0x7, 0x3, 0x10, 0xfd, 0x4, 0x40}}, {{0x9, 0x5,
0x7, 0x7, 0x8, 0x0, 0x9, 0x81}}, {{0x9, 0x5, 0xe, 0x10, 0x400, 0x1,
0x8, 0x20}}]}}]}}]}}, 0x0)

please run it with syz-execprog -repeat 0 ./repro.txt, it will trigger the bug.

See aslo https://gist.github.com/xrivendell7/65437409377f91fc28a04867956fa9e0.
I hope it helps.

Best regards.
xingwei Lee

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-03-03  2:55 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-15 15:18 KASAN: use-after-free Read in v4l2_fh_open syzbot
2021-05-04 21:28 ` SyzScope
2024-03-02 10:56 ` Hillf Danton
2024-03-02 13:02   ` [syzbot] [usb?] [media?] " syzbot
2024-03-02 23:07 ` Hillf Danton
2024-03-02 23:39   ` [syzbot] [usb?] [media?] " syzbot
2024-03-03  1:43 ` Hillf Danton
2024-03-03  2:55   ` [syzbot] [usb?] [media?] " syzbot
2024-03-02  8:08 xingwei lee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).