Netdev Archive on lore.kernel.org
 help / color / Atom feed
* KASAN: slab-out-of-bounds Read in qrtr_endpoint_post
@ 2020-06-27  8:50 syzbot
  2020-06-27 20:57 ` syzbot
  0 siblings, 1 reply; 5+ messages in thread
From: syzbot @ 2020-06-27  8:50 UTC (permalink / raw)
  To: bjorn.andersson, davem, kuba, linux-kernel,
	manivannan.sadhasivam, netdev, syzkaller-bugs

Hello,

syzbot found the following crash on:

HEAD commit:    1590a2e1 Merge tag 'acpi-5.8-rc3' of git://git.kernel.org/..
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=1142febb100000
kernel config:  https://syzkaller.appspot.com/x/.config?x=bf3aec367b9ab569
dashboard link: https://syzkaller.appspot.com/bug?extid=b8fe393f999a291a9ea6
compiler:       gcc (GCC) 10.1.0-syz 20200507

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

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

==================================================================
BUG: KASAN: slab-out-of-bounds in qrtr_endpoint_post+0xf9b/0x1010 net/qrtr/qrtr.c:447
Read of size 4 at addr ffff88809df0ce44 by task syz-executor.2/29604

CPU: 1 PID: 29604 Comm: syz-executor.2 Not tainted 5.8.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+0x18f/0x20d lib/dump_stack.c:118
 print_address_description.constprop.0.cold+0xae/0x436 mm/kasan/report.c:383
 __kasan_report mm/kasan/report.c:513 [inline]
 kasan_report.cold+0x1f/0x37 mm/kasan/report.c:530
 qrtr_endpoint_post+0xf9b/0x1010 net/qrtr/qrtr.c:447
 qrtr_tun_write_iter+0xf5/0x180 net/qrtr/tun.c:92
 call_write_iter include/linux/fs.h:1907 [inline]
 new_sync_write+0x422/0x650 fs/read_write.c:484
 __vfs_write+0xc9/0x100 fs/read_write.c:497
 vfs_write+0x268/0x5d0 fs/read_write.c:559
 ksys_write+0x12d/0x250 fs/read_write.c:612
 do_syscall_64+0x60/0xe0 arch/x86/entry/common.c:359
 entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x45cb19
Code: Bad RIP value.
RSP: 002b:00007ff63f2a7c78 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 000000000050dd80 RCX: 000000000045cb19
RDX: 0000000000000004 RSI: 0000000020000140 RDI: 0000000000000005
RBP: 000000000078bf00 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00000000ffffffff
R13: 0000000000000d1e R14: 00000000004cf76d R15: 00007ff63f2a86d4

Allocated by task 29604:
 save_stack+0x1b/0x40 mm/kasan/common.c:48
 set_track mm/kasan/common.c:56 [inline]
 __kasan_kmalloc.constprop.0+0xc2/0xd0 mm/kasan/common.c:494
 __do_kmalloc mm/slab.c:3656 [inline]
 __kmalloc+0x17a/0x340 mm/slab.c:3665
 kmalloc include/linux/slab.h:560 [inline]
 kzalloc include/linux/slab.h:669 [inline]
 qrtr_tun_write_iter+0x8a/0x180 net/qrtr/tun.c:83
 call_write_iter include/linux/fs.h:1907 [inline]
 new_sync_write+0x422/0x650 fs/read_write.c:484
 __vfs_write+0xc9/0x100 fs/read_write.c:497
 vfs_write+0x268/0x5d0 fs/read_write.c:559
 ksys_write+0x12d/0x250 fs/read_write.c:612
 do_syscall_64+0x60/0xe0 arch/x86/entry/common.c:359
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

Freed by task 24714:
 save_stack+0x1b/0x40 mm/kasan/common.c:48
 set_track mm/kasan/common.c:56 [inline]
 kasan_set_free_info mm/kasan/common.c:316 [inline]
 __kasan_slab_free+0xf5/0x140 mm/kasan/common.c:455
 __cache_free mm/slab.c:3426 [inline]
 kfree+0x103/0x2c0 mm/slab.c:3757
 kvm_destroy_vm_debugfs arch/x86/kvm/../../../virt/kvm/kvm_main.c:628 [inline]
 kvm_destroy_vm+0x158/0xbe0 arch/x86/kvm/../../../virt/kvm/kvm_main.c:801
 kvm_put_kvm arch/x86/kvm/../../../virt/kvm/kvm_main.c:843 [inline]
 kvm_vcpu_release+0xc2/0x110 arch/x86/kvm/../../../virt/kvm/kvm_main.c:2979
 __fput+0x33c/0x880 fs/file_table.c:281
 task_work_run+0xdd/0x190 kernel/task_work.c:123
 tracehook_notify_resume include/linux/tracehook.h:188 [inline]
 exit_to_usermode_loop arch/x86/entry/common.c:216 [inline]
 __prepare_exit_to_usermode+0x1e9/0x1f0 arch/x86/entry/common.c:246
 do_syscall_64+0x6c/0xe0 arch/x86/entry/common.c:368
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

The buggy address belongs to the object at ffff88809df0ce40
 which belongs to the cache kmalloc-32 of size 32
The buggy address is located 4 bytes inside of
 32-byte region [ffff88809df0ce40, ffff88809df0ce60)
The buggy address belongs to the page:
page:ffffea000277c300 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff88809df0cfc1
flags: 0xfffe0000000200(slab)
raw: 00fffe0000000200 ffffea00027c0a88 ffffea00027b7c08 ffff8880aa0001c0
raw: ffff88809df0cfc1 ffff88809df0c000 000000010000003f 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
 ffff88809df0cd00: 00 01 fc fc fc fc fc fc 00 01 fc fc fc fc fc fc
 ffff88809df0cd80: 00 fc fc fc fc fc fc fc 06 fc fc fc fc fc fc fc
>ffff88809df0ce00: fb fb fb fb fc fc fc fc 04 fc fc fc fc fc fc fc
                                           ^
 ffff88809df0ce80: 00 01 fc fc fc fc fc fc fb fb fb fb fc fc fc fc
 ffff88809df0cf00: fb fb fb fb fc fc fc fc 00 00 00 fc fc fc fc fc
==================================================================


---
This bug 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 bug report. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.

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

* Re: KASAN: slab-out-of-bounds Read in qrtr_endpoint_post
  2020-06-27  8:50 KASAN: slab-out-of-bounds Read in qrtr_endpoint_post syzbot
@ 2020-06-27 20:57 ` syzbot
  2020-06-28 10:46   ` Manivannan Sadhasivam
  0 siblings, 1 reply; 5+ messages in thread
From: syzbot @ 2020-06-27 20:57 UTC (permalink / raw)
  To: bjorn.andersson, davem, kuba, linux-kernel,
	manivannan.sadhasivam, netdev, syzkaller-bugs

syzbot has found a reproducer for the following crash on:

HEAD commit:    1590a2e1 Merge tag 'acpi-5.8-rc3' of git://git.kernel.org/..
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=14b2b503100000
kernel config:  https://syzkaller.appspot.com/x/.config?x=bf3aec367b9ab569
dashboard link: https://syzkaller.appspot.com/bug?extid=b8fe393f999a291a9ea6
compiler:       gcc (GCC) 10.1.0-syz 20200507
userspace arch: i386
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=109e6b55100000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=13671a3d100000

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

==================================================================
BUG: KASAN: slab-out-of-bounds in qrtr_endpoint_post+0xeeb/0x1010 net/qrtr/qrtr.c:462
Read of size 2 at addr ffff88809de50c48 by task syz-executor531/6806

CPU: 0 PID: 6806 Comm: syz-executor531 Not tainted 5.8.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+0x18f/0x20d lib/dump_stack.c:118
 print_address_description.constprop.0.cold+0xae/0x436 mm/kasan/report.c:383
 __kasan_report mm/kasan/report.c:513 [inline]
 kasan_report.cold+0x1f/0x37 mm/kasan/report.c:530
 qrtr_endpoint_post+0xeeb/0x1010 net/qrtr/qrtr.c:462
 qrtr_tun_write_iter+0xf5/0x180 net/qrtr/tun.c:92
 call_write_iter include/linux/fs.h:1907 [inline]
 do_iter_readv_writev+0x567/0x780 fs/read_write.c:694
 do_iter_write+0x188/0x5f0 fs/read_write.c:999
 compat_writev+0x1ea/0x390 fs/read_write.c:1352
 do_compat_pwritev64+0x180/0x1b0 fs/read_write.c:1401
 do_syscall_32_irqs_on+0x3f/0x60 arch/x86/entry/common.c:403
 __do_fast_syscall_32 arch/x86/entry/common.c:448 [inline]
 do_fast_syscall_32+0x7f/0x120 arch/x86/entry/common.c:474
 entry_SYSENTER_compat+0x6d/0x7c arch/x86/entry/entry_64_compat.S:138
RIP: 0023:0xf7f8f569
Code: Bad RIP value.
RSP: 002b:00000000ffda5ffc EFLAGS: 00000292 ORIG_RAX: 000000000000014e
RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 0000000020000440
RDX: 0000000000000001 RSI: 0000000000000000 RDI: 00000000080bb528
RBP: 0000000000000012 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000

Allocated by task 6806:
 save_stack+0x1b/0x40 mm/kasan/common.c:48
 set_track mm/kasan/common.c:56 [inline]
 __kasan_kmalloc.constprop.0+0xc2/0xd0 mm/kasan/common.c:494
 __do_kmalloc mm/slab.c:3656 [inline]
 __kmalloc+0x17a/0x340 mm/slab.c:3665
 kmalloc include/linux/slab.h:560 [inline]
 kzalloc include/linux/slab.h:669 [inline]
 qrtr_tun_write_iter+0x8a/0x180 net/qrtr/tun.c:83
 call_write_iter include/linux/fs.h:1907 [inline]
 do_iter_readv_writev+0x567/0x780 fs/read_write.c:694
 do_iter_write+0x188/0x5f0 fs/read_write.c:999
 compat_writev+0x1ea/0x390 fs/read_write.c:1352
 do_compat_pwritev64+0x180/0x1b0 fs/read_write.c:1401
 do_syscall_32_irqs_on+0x3f/0x60 arch/x86/entry/common.c:403
 __do_fast_syscall_32 arch/x86/entry/common.c:448 [inline]
 do_fast_syscall_32+0x7f/0x120 arch/x86/entry/common.c:474
 entry_SYSENTER_compat+0x6d/0x7c arch/x86/entry/entry_64_compat.S:138

Freed by task 1:
 save_stack+0x1b/0x40 mm/kasan/common.c:48
 set_track mm/kasan/common.c:56 [inline]
 kasan_set_free_info mm/kasan/common.c:316 [inline]
 __kasan_slab_free+0xf5/0x140 mm/kasan/common.c:455
 __cache_free mm/slab.c:3426 [inline]
 kfree+0x103/0x2c0 mm/slab.c:3757
 tomoyo_path_perm+0x234/0x3f0 security/tomoyo/file.c:842
 security_inode_getattr+0xcf/0x140 security/security.c:1278
 vfs_getattr fs/stat.c:121 [inline]
 vfs_statx+0x170/0x390 fs/stat.c:206
 vfs_lstat include/linux/fs.h:3301 [inline]
 __do_sys_newlstat+0x91/0x110 fs/stat.c:374
 do_syscall_64+0x60/0xe0 arch/x86/entry/common.c:359
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

The buggy address belongs to the object at ffff88809de50c40
 which belongs to the cache kmalloc-32 of size 32
The buggy address is located 8 bytes inside of
 32-byte region [ffff88809de50c40, ffff88809de50c60)
The buggy address belongs to the page:
page:ffffea0002779400 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff88809de50fc1
flags: 0xfffe0000000200(slab)
raw: 00fffe0000000200 ffffea000277e008 ffffea0002761c88 ffff8880aa0001c0
raw: ffff88809de50fc1 ffff88809de50000 000000010000003f 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
 ffff88809de50b00: fb fb fb fb fc fc fc fc fb fb fb fb fc fc fc fc
 ffff88809de50b80: fb fb fb fb fc fc fc fc fb fb fb fb fc fc fc fc
>ffff88809de50c00: fb fb fb fb fc fc fc fc 04 fc fc fc fc fc fc fc
                                              ^
 ffff88809de50c80: fb fb fb fb fc fc fc fc fb fb fb fb fc fc fc fc
 ffff88809de50d00: fb fb fb fb fc fc fc fc 00 01 fc fc fc fc fc fc
==================================================================


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

* Re: KASAN: slab-out-of-bounds Read in qrtr_endpoint_post
  2020-06-27 20:57 ` syzbot
@ 2020-06-28 10:46   ` Manivannan Sadhasivam
  2020-06-30 11:46     ` [PATCH net] net: qrtr: Fix an out of bounds read qrtr_endpoint_post() Dan Carpenter
  0 siblings, 1 reply; 5+ messages in thread
From: Manivannan Sadhasivam @ 2020-06-28 10:46 UTC (permalink / raw)
  To: bjorn.andersson; +Cc: davem, kuba, linux-kernel, netdev, syzkaller-bugs

Hi Bjorn,

On Sat, Jun 27, 2020 at 01:57:13PM -0700, syzbot wrote:
> syzbot has found a reproducer for the following crash on:
> 
> HEAD commit:    1590a2e1 Merge tag 'acpi-5.8-rc3' of git://git.kernel.org/..
> git tree:       upstream
> console output: https://syzkaller.appspot.com/x/log.txt?x=14b2b503100000
> kernel config:  https://syzkaller.appspot.com/x/.config?x=bf3aec367b9ab569
> dashboard link: https://syzkaller.appspot.com/bug?extid=b8fe393f999a291a9ea6
> compiler:       gcc (GCC) 10.1.0-syz 20200507
> userspace arch: i386
> syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=109e6b55100000
> C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=13671a3d100000
> 
> IMPORTANT: if you fix the bug, please add the following tag to the commit:
> Reported-by: syzbot+b8fe393f999a291a9ea6@syzkaller.appspotmail.com
> 
> ==================================================================
> BUG: KASAN: slab-out-of-bounds in qrtr_endpoint_post+0xeeb/0x1010 net/qrtr/qrtr.c:462
> Read of size 2 at addr ffff88809de50c48 by task syz-executor531/6806
> 
> CPU: 0 PID: 6806 Comm: syz-executor531 Not tainted 5.8.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+0x18f/0x20d lib/dump_stack.c:118
>  print_address_description.constprop.0.cold+0xae/0x436 mm/kasan/report.c:383
>  __kasan_report mm/kasan/report.c:513 [inline]
>  kasan_report.cold+0x1f/0x37 mm/kasan/report.c:530
>  qrtr_endpoint_post+0xeeb/0x1010 net/qrtr/qrtr.c:462
>  qrtr_tun_write_iter+0xf5/0x180 net/qrtr/tun.c:92

Hmm. Is this due to the fact that we are not checking the length of the
kbuf allocated in qrtr_tun_write_iter()? The length derived from
'iov_iter_count(from)' gets used directly and that might be causing the
out of bound access error here.

Thanks,
Mani

>  call_write_iter include/linux/fs.h:1907 [inline]
>  do_iter_readv_writev+0x567/0x780 fs/read_write.c:694
>  do_iter_write+0x188/0x5f0 fs/read_write.c:999
>  compat_writev+0x1ea/0x390 fs/read_write.c:1352
>  do_compat_pwritev64+0x180/0x1b0 fs/read_write.c:1401
>  do_syscall_32_irqs_on+0x3f/0x60 arch/x86/entry/common.c:403
>  __do_fast_syscall_32 arch/x86/entry/common.c:448 [inline]
>  do_fast_syscall_32+0x7f/0x120 arch/x86/entry/common.c:474
>  entry_SYSENTER_compat+0x6d/0x7c arch/x86/entry/entry_64_compat.S:138
> RIP: 0023:0xf7f8f569
> Code: Bad RIP value.
> RSP: 002b:00000000ffda5ffc EFLAGS: 00000292 ORIG_RAX: 000000000000014e
> RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 0000000020000440
> RDX: 0000000000000001 RSI: 0000000000000000 RDI: 00000000080bb528
> RBP: 0000000000000012 R08: 0000000000000000 R09: 0000000000000000
> R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
> R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
> 
> Allocated by task 6806:
>  save_stack+0x1b/0x40 mm/kasan/common.c:48
>  set_track mm/kasan/common.c:56 [inline]
>  __kasan_kmalloc.constprop.0+0xc2/0xd0 mm/kasan/common.c:494
>  __do_kmalloc mm/slab.c:3656 [inline]
>  __kmalloc+0x17a/0x340 mm/slab.c:3665
>  kmalloc include/linux/slab.h:560 [inline]
>  kzalloc include/linux/slab.h:669 [inline]
>  qrtr_tun_write_iter+0x8a/0x180 net/qrtr/tun.c:83
>  call_write_iter include/linux/fs.h:1907 [inline]
>  do_iter_readv_writev+0x567/0x780 fs/read_write.c:694
>  do_iter_write+0x188/0x5f0 fs/read_write.c:999
>  compat_writev+0x1ea/0x390 fs/read_write.c:1352
>  do_compat_pwritev64+0x180/0x1b0 fs/read_write.c:1401
>  do_syscall_32_irqs_on+0x3f/0x60 arch/x86/entry/common.c:403
>  __do_fast_syscall_32 arch/x86/entry/common.c:448 [inline]
>  do_fast_syscall_32+0x7f/0x120 arch/x86/entry/common.c:474
>  entry_SYSENTER_compat+0x6d/0x7c arch/x86/entry/entry_64_compat.S:138
> 
> Freed by task 1:
>  save_stack+0x1b/0x40 mm/kasan/common.c:48
>  set_track mm/kasan/common.c:56 [inline]
>  kasan_set_free_info mm/kasan/common.c:316 [inline]
>  __kasan_slab_free+0xf5/0x140 mm/kasan/common.c:455
>  __cache_free mm/slab.c:3426 [inline]
>  kfree+0x103/0x2c0 mm/slab.c:3757
>  tomoyo_path_perm+0x234/0x3f0 security/tomoyo/file.c:842
>  security_inode_getattr+0xcf/0x140 security/security.c:1278
>  vfs_getattr fs/stat.c:121 [inline]
>  vfs_statx+0x170/0x390 fs/stat.c:206
>  vfs_lstat include/linux/fs.h:3301 [inline]
>  __do_sys_newlstat+0x91/0x110 fs/stat.c:374
>  do_syscall_64+0x60/0xe0 arch/x86/entry/common.c:359
>  entry_SYSCALL_64_after_hwframe+0x44/0xa9
> 
> The buggy address belongs to the object at ffff88809de50c40
>  which belongs to the cache kmalloc-32 of size 32
> The buggy address is located 8 bytes inside of
>  32-byte region [ffff88809de50c40, ffff88809de50c60)
> The buggy address belongs to the page:
> page:ffffea0002779400 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff88809de50fc1
> flags: 0xfffe0000000200(slab)
> raw: 00fffe0000000200 ffffea000277e008 ffffea0002761c88 ffff8880aa0001c0
> raw: ffff88809de50fc1 ffff88809de50000 000000010000003f 0000000000000000
> page dumped because: kasan: bad access detected
> 
> Memory state around the buggy address:
>  ffff88809de50b00: fb fb fb fb fc fc fc fc fb fb fb fb fc fc fc fc
>  ffff88809de50b80: fb fb fb fb fc fc fc fc fb fb fb fb fc fc fc fc
> >ffff88809de50c00: fb fb fb fb fc fc fc fc 04 fc fc fc fc fc fc fc
>                                               ^
>  ffff88809de50c80: fb fb fb fb fc fc fc fc fb fb fb fb fc fc fc fc
>  ffff88809de50d00: fb fb fb fb fc fc fc fc 00 01 fc fc fc fc fc fc
> ==================================================================
> 

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

* [PATCH net] net: qrtr: Fix an out of bounds read qrtr_endpoint_post()
  2020-06-28 10:46   ` Manivannan Sadhasivam
@ 2020-06-30 11:46     ` Dan Carpenter
  2020-07-01  1:36       ` David Miller
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2020-06-30 11:46 UTC (permalink / raw)
  To: David S. Miller, Bjorn Andersson, Manivannan Sadhasivam
  Cc: Jakub Kicinski, Wang Wenhu, Wen Gong, Carl Huang, netdev,
	linux-kernel, syzkaller-bugs

This code assumes that the user passed in enough data for a
qrtr_hdr_v1 or qrtr_hdr_v2 struct, but it's not necessarily true.  If
the buffer is too small then it will read beyond the end.

Reported-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Reported-by: syzbot+b8fe393f999a291a9ea6@syzkaller.appspotmail.com
Fixes: 194ccc88297a ("net: qrtr: Support decoding incoming v2 packets")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 net/qrtr/qrtr.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c
index 2d8d6131bc5f..7eccbbf6f8ad 100644
--- a/net/qrtr/qrtr.c
+++ b/net/qrtr/qrtr.c
@@ -427,7 +427,7 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
 	unsigned int ver;
 	size_t hdrlen;
 
-	if (len & 3)
+	if (len == 0 || len & 3)
 		return -EINVAL;
 
 	skb = netdev_alloc_skb(NULL, len);
@@ -441,6 +441,8 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
 
 	switch (ver) {
 	case QRTR_PROTO_VER_1:
+		if (len < sizeof(*v1))
+			goto err;
 		v1 = data;
 		hdrlen = sizeof(*v1);
 
@@ -454,6 +456,8 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
 		size = le32_to_cpu(v1->size);
 		break;
 	case QRTR_PROTO_VER_2:
+		if (len < sizeof(*v2))
+			goto err;
 		v2 = data;
 		hdrlen = sizeof(*v2) + v2->optlen;
 
-- 
2.27.0


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

* Re: [PATCH net] net: qrtr: Fix an out of bounds read qrtr_endpoint_post()
  2020-06-30 11:46     ` [PATCH net] net: qrtr: Fix an out of bounds read qrtr_endpoint_post() Dan Carpenter
@ 2020-07-01  1:36       ` David Miller
  0 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2020-07-01  1:36 UTC (permalink / raw)
  To: dan.carpenter
  Cc: bjorn.andersson, manivannan.sadhasivam, kuba, wenhu.wang, wgong,
	cjhuang, netdev, linux-kernel, syzkaller-bugs

From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Tue, 30 Jun 2020 14:46:15 +0300

> This code assumes that the user passed in enough data for a
> qrtr_hdr_v1 or qrtr_hdr_v2 struct, but it's not necessarily true.  If
> the buffer is too small then it will read beyond the end.
> 
> Reported-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> Reported-by: syzbot+b8fe393f999a291a9ea6@syzkaller.appspotmail.com
> Fixes: 194ccc88297a ("net: qrtr: Support decoding incoming v2 packets")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Applied and queued up for -stable, thanks Dan.

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

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-27  8:50 KASAN: slab-out-of-bounds Read in qrtr_endpoint_post syzbot
2020-06-27 20:57 ` syzbot
2020-06-28 10:46   ` Manivannan Sadhasivam
2020-06-30 11:46     ` [PATCH net] net: qrtr: Fix an out of bounds read qrtr_endpoint_post() Dan Carpenter
2020-07-01  1:36       ` David Miller

Netdev Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/netdev/0 netdev/git/0.git
	git clone --mirror https://lore.kernel.org/netdev/1 netdev/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 netdev netdev/ https://lore.kernel.org/netdev \
		netdev@vger.kernel.org
	public-inbox-index netdev

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.netdev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git