linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* KASAN: slab-out-of-bounds Read in string (2)
@ 2018-09-28 14:45 syzbot
  2018-09-28 14:55 ` Dmitry Vyukov
  0 siblings, 1 reply; 9+ messages in thread
From: syzbot @ 2018-09-28 14:45 UTC (permalink / raw)
  To: linux-kernel, pmladek, rostedt, sergey.senozhatsky, syzkaller-bugs

Hello,

syzbot found the following crash on:

HEAD commit:    c127e59bee3e Merge tag 'for_v4.19-rc6' of git://git.kernel..
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=13b2f32a400000
kernel config:  https://syzkaller.appspot.com/x/.config?x=dfb440e26f0a6f6f
dashboard link: https://syzkaller.appspot.com/bug?extid=376cea2b0ef340db3dd4
compiler:       gcc (GCC) 8.0.1 20180413 (experimental)

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+376cea2b0ef340db3dd4@syzkaller.appspotmail.com

RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000020000140
RBP: 000000000072bf00 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00007f0e714a76d4
R13: 00000000004c32cb R14: 00000000004d4ef0 R15: 0000000000000004
==================================================================
BUG: KASAN: slab-out-of-bounds in string+0x298/0x2d0 lib/vsprintf.c:604
Read of size 1 at addr ffff8801c36c66ba by task syz-executor2/27811

CPU: 0 PID: 27811 Comm: syz-executor2 Not tainted 4.19.0-rc5+ #36
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+0x1c4/0x2b4 lib/dump_stack.c:113
  print_address_description.cold.8+0x9/0x1ff mm/kasan/report.c:256
  kasan_report_error mm/kasan/report.c:354 [inline]
  kasan_report.cold.9+0x242/0x309 mm/kasan/report.c:412
  __asan_report_load1_noabort+0x14/0x20 mm/kasan/report.c:430
  string+0x298/0x2d0 lib/vsprintf.c:604
  vsnprintf+0x48e/0x1b60 lib/vsprintf.c:2293
  vscnprintf+0x2d/0x80 lib/vsprintf.c:2396
  vprintk_store+0x43/0x510 kernel/printk/printk.c:1847
  vprintk_emit+0x1c1/0x930 kernel/printk/printk.c:1905
  vprintk_default+0x28/0x30 kernel/printk/printk.c:1963
  vprintk_func+0x7e/0x181 kernel/printk/printk_safe.c:398
  printk+0xa7/0xcf kernel/printk/printk.c:1996
  ovl_lookup_index.cold.15+0xe8/0x1f8 fs/overlayfs/namei.c:689
  ovl_lookup+0x9f2/0x29c0 fs/overlayfs/namei.c:1022
  __lookup_hash+0x12e/0x190 fs/namei.c:1546
  do_rmdir+0x3b3/0x630 fs/namei.c:3930
  __do_sys_rmdir fs/namei.c:3959 [inline]
  __se_sys_rmdir fs/namei.c:3957 [inline]
  __x64_sys_rmdir+0x36/0x40 fs/namei.c:3957
  do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290
  entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x457579
Code: 1d b4 fb ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 48 89 f8 48 89 f7  
48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff  
ff 0f 83 eb b3 fb ff c3 66 2e 0f 1f 84 00 00 00 00
RSP: 002b:00007f0e714a6c78 EFLAGS: 00000246 ORIG_RAX: 0000000000000054
RAX: ffffffffffffffda RBX: 00007f0e714a6c90 RCX: 0000000000457579
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000020000140
RBP: 000000000072bf00 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00007f0e714a76d4
R13: 00000000004c32cb R14: 00000000004d4ef0 R15: 0000000000000004

Allocated by task 27811:
  save_stack+0x43/0xd0 mm/kasan/kasan.c:448
  set_track mm/kasan/kasan.c:460 [inline]
  kasan_kmalloc+0xc7/0xe0 mm/kasan/kasan.c:553
  __do_kmalloc mm/slab.c:3718 [inline]
  __kmalloc+0x14e/0x760 mm/slab.c:3727
  kmalloc_array include/linux/slab.h:635 [inline]
  kcalloc include/linux/slab.h:646 [inline]
  ovl_get_index_name_fh+0x57/0x180 fs/overlayfs/namei.c:596
  ovl_get_index_name+0x5c/0x80 fs/overlayfs/namei.c:631
  ovl_lookup_index+0xe4/0x700 fs/overlayfs/namei.c:678
  ovl_lookup+0x9f2/0x29c0 fs/overlayfs/namei.c:1022
  __lookup_hash+0x12e/0x190 fs/namei.c:1546
  do_rmdir+0x3b3/0x630 fs/namei.c:3930
  __do_sys_rmdir fs/namei.c:3959 [inline]
  __se_sys_rmdir fs/namei.c:3957 [inline]
  __x64_sys_rmdir+0x36/0x40 fs/namei.c:3957
  do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290
  entry_SYSCALL_64_after_hwframe+0x49/0xbe

Freed by task 5441:
  save_stack+0x43/0xd0 mm/kasan/kasan.c:448
  set_track mm/kasan/kasan.c:460 [inline]
  __kasan_slab_free+0x102/0x150 mm/kasan/kasan.c:521
  kasan_slab_free+0xe/0x10 mm/kasan/kasan.c:528
  __cache_free mm/slab.c:3498 [inline]
  kfree+0xcf/0x230 mm/slab.c:3813
  __vunmap+0x335/0x460 mm/vmalloc.c:1532
  vfree+0x68/0x100 mm/vmalloc.c:1593
  copy_entries_to_user net/ipv4/netfilter/ip_tables.c:870 [inline]
  get_entries net/ipv4/netfilter/ip_tables.c:1027 [inline]
  do_ipt_get_ctl+0x9eb/0xbc0 net/ipv4/netfilter/ip_tables.c:1703
  nf_sockopt net/netfilter/nf_sockopt.c:104 [inline]
  nf_getsockopt+0x80/0xe0 net/netfilter/nf_sockopt.c:122
  ip_getsockopt+0x1af/0x240 net/ipv4/ip_sockglue.c:1577
  tcp_getsockopt+0x93/0xe0 net/ipv4/tcp.c:3583
  sock_common_getsockopt+0x9a/0xe0 net/core/sock.c:2997
  __sys_getsockopt+0x1ad/0x390 net/socket.c:1939
  __do_sys_getsockopt net/socket.c:1950 [inline]
  __se_sys_getsockopt net/socket.c:1947 [inline]
  __x64_sys_getsockopt+0xbe/0x150 net/socket.c:1947
  do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290
  entry_SYSCALL_64_after_hwframe+0x49/0xbe

The buggy address belongs to the object at ffff8801c36c6680
  which belongs to the cache kmalloc-64 of size 64
The buggy address is located 58 bytes inside of
  64-byte region [ffff8801c36c6680, ffff8801c36c66c0)
The buggy address belongs to the page:
page:ffffea00070db180 count:1 mapcount:0 mapping:ffff8801da800340  
index:0xffff8801c36c6380
flags: 0x2fffc0000000100(slab)
raw: 02fffc0000000100 ffffea0006d16508 ffffea000638a588 ffff8801da800340
raw: ffff8801c36c6380 ffff8801c36c6000 000000010000001b 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
  ffff8801c36c6580: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
  ffff8801c36c6600: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
> ffff8801c36c6680: 00 00 00 00 00 00 00 02 fc fc fc fc fc fc fc fc
                                         ^
  ffff8801c36c6700: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
  ffff8801c36c6780: fb fb fb fb fb fb fb fb fc fc fc 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#bug-status-tracking for how to communicate with  
syzbot.

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

* Re: KASAN: slab-out-of-bounds Read in string (2)
  2018-09-28 14:45 KASAN: slab-out-of-bounds Read in string (2) syzbot
@ 2018-09-28 14:55 ` Dmitry Vyukov
  2018-09-28 17:39   ` Amir Goldstein
  0 siblings, 1 reply; 9+ messages in thread
From: Dmitry Vyukov @ 2018-09-28 14:55 UTC (permalink / raw)
  To: syzbot, Miklos Szeredi, linux-unionfs
  Cc: LKML, Petr Mladek, Steven Rostedt, Sergey Senozhatsky, syzkaller-bugs

On Fri, Sep 28, 2018 at 4:45 PM, syzbot
<syzbot+376cea2b0ef340db3dd4@syzkaller.appspotmail.com> wrote:
> Hello,
>
> syzbot found the following crash on:
>
> HEAD commit:    c127e59bee3e Merge tag 'for_v4.19-rc6' of git://git.kernel..
> git tree:       upstream
> console output: https://syzkaller.appspot.com/x/log.txt?x=13b2f32a400000
> kernel config:  https://syzkaller.appspot.com/x/.config?x=dfb440e26f0a6f6f
> dashboard link: https://syzkaller.appspot.com/bug?extid=376cea2b0ef340db3dd4
> compiler:       gcc (GCC) 8.0.1 20180413 (experimental)
>
> 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+376cea2b0ef340db3dd4@syzkaller.appspotmail.com

I guess this is overlayfs rather than printk. +overlayfs maintainers
In future syzbot will avoid attributing crashes to printk, because I
think it's not the first time crashes are mis-attributed to printk:
https://github.com/google/syzkaller/commit/41e4b32952f4590341ae872db0abf819b4004713


> RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000020000140
> RBP: 000000000072bf00 R08: 0000000000000000 R09: 0000000000000000
> R10: 0000000000000000 R11: 0000000000000246 R12: 00007f0e714a76d4
> R13: 00000000004c32cb R14: 00000000004d4ef0 R15: 0000000000000004
> ==================================================================
> BUG: KASAN: slab-out-of-bounds in string+0x298/0x2d0 lib/vsprintf.c:604
> Read of size 1 at addr ffff8801c36c66ba by task syz-executor2/27811
>
> CPU: 0 PID: 27811 Comm: syz-executor2 Not tainted 4.19.0-rc5+ #36
> 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+0x1c4/0x2b4 lib/dump_stack.c:113
>  print_address_description.cold.8+0x9/0x1ff mm/kasan/report.c:256
>  kasan_report_error mm/kasan/report.c:354 [inline]
>  kasan_report.cold.9+0x242/0x309 mm/kasan/report.c:412
>  __asan_report_load1_noabort+0x14/0x20 mm/kasan/report.c:430
>  string+0x298/0x2d0 lib/vsprintf.c:604
>  vsnprintf+0x48e/0x1b60 lib/vsprintf.c:2293
>  vscnprintf+0x2d/0x80 lib/vsprintf.c:2396
>  vprintk_store+0x43/0x510 kernel/printk/printk.c:1847
>  vprintk_emit+0x1c1/0x930 kernel/printk/printk.c:1905
>  vprintk_default+0x28/0x30 kernel/printk/printk.c:1963
>  vprintk_func+0x7e/0x181 kernel/printk/printk_safe.c:398
>  printk+0xa7/0xcf kernel/printk/printk.c:1996
>  ovl_lookup_index.cold.15+0xe8/0x1f8 fs/overlayfs/namei.c:689
>  ovl_lookup+0x9f2/0x29c0 fs/overlayfs/namei.c:1022
>  __lookup_hash+0x12e/0x190 fs/namei.c:1546
>  do_rmdir+0x3b3/0x630 fs/namei.c:3930
>  __do_sys_rmdir fs/namei.c:3959 [inline]
>  __se_sys_rmdir fs/namei.c:3957 [inline]
>  __x64_sys_rmdir+0x36/0x40 fs/namei.c:3957
>  do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290
>  entry_SYSCALL_64_after_hwframe+0x49/0xbe
> RIP: 0033:0x457579
> Code: 1d b4 fb ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 48 89 f8 48 89 f7
> 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff
> 0f 83 eb b3 fb ff c3 66 2e 0f 1f 84 00 00 00 00
> RSP: 002b:00007f0e714a6c78 EFLAGS: 00000246 ORIG_RAX: 0000000000000054
> RAX: ffffffffffffffda RBX: 00007f0e714a6c90 RCX: 0000000000457579
> RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000020000140
> RBP: 000000000072bf00 R08: 0000000000000000 R09: 0000000000000000
> R10: 0000000000000000 R11: 0000000000000246 R12: 00007f0e714a76d4
> R13: 00000000004c32cb R14: 00000000004d4ef0 R15: 0000000000000004
>
> Allocated by task 27811:
>  save_stack+0x43/0xd0 mm/kasan/kasan.c:448
>  set_track mm/kasan/kasan.c:460 [inline]
>  kasan_kmalloc+0xc7/0xe0 mm/kasan/kasan.c:553
>  __do_kmalloc mm/slab.c:3718 [inline]
>  __kmalloc+0x14e/0x760 mm/slab.c:3727
>  kmalloc_array include/linux/slab.h:635 [inline]
>  kcalloc include/linux/slab.h:646 [inline]
>  ovl_get_index_name_fh+0x57/0x180 fs/overlayfs/namei.c:596
>  ovl_get_index_name+0x5c/0x80 fs/overlayfs/namei.c:631
>  ovl_lookup_index+0xe4/0x700 fs/overlayfs/namei.c:678
>  ovl_lookup+0x9f2/0x29c0 fs/overlayfs/namei.c:1022
>  __lookup_hash+0x12e/0x190 fs/namei.c:1546
>  do_rmdir+0x3b3/0x630 fs/namei.c:3930
>  __do_sys_rmdir fs/namei.c:3959 [inline]
>  __se_sys_rmdir fs/namei.c:3957 [inline]
>  __x64_sys_rmdir+0x36/0x40 fs/namei.c:3957
>  do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290
>  entry_SYSCALL_64_after_hwframe+0x49/0xbe
>
> Freed by task 5441:
>  save_stack+0x43/0xd0 mm/kasan/kasan.c:448
>  set_track mm/kasan/kasan.c:460 [inline]
>  __kasan_slab_free+0x102/0x150 mm/kasan/kasan.c:521
>  kasan_slab_free+0xe/0x10 mm/kasan/kasan.c:528
>  __cache_free mm/slab.c:3498 [inline]
>  kfree+0xcf/0x230 mm/slab.c:3813
>  __vunmap+0x335/0x460 mm/vmalloc.c:1532
>  vfree+0x68/0x100 mm/vmalloc.c:1593
>  copy_entries_to_user net/ipv4/netfilter/ip_tables.c:870 [inline]
>  get_entries net/ipv4/netfilter/ip_tables.c:1027 [inline]
>  do_ipt_get_ctl+0x9eb/0xbc0 net/ipv4/netfilter/ip_tables.c:1703
>  nf_sockopt net/netfilter/nf_sockopt.c:104 [inline]
>  nf_getsockopt+0x80/0xe0 net/netfilter/nf_sockopt.c:122
>  ip_getsockopt+0x1af/0x240 net/ipv4/ip_sockglue.c:1577
>  tcp_getsockopt+0x93/0xe0 net/ipv4/tcp.c:3583
>  sock_common_getsockopt+0x9a/0xe0 net/core/sock.c:2997
>  __sys_getsockopt+0x1ad/0x390 net/socket.c:1939
>  __do_sys_getsockopt net/socket.c:1950 [inline]
>  __se_sys_getsockopt net/socket.c:1947 [inline]
>  __x64_sys_getsockopt+0xbe/0x150 net/socket.c:1947
>  do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290
>  entry_SYSCALL_64_after_hwframe+0x49/0xbe
>
> The buggy address belongs to the object at ffff8801c36c6680
>  which belongs to the cache kmalloc-64 of size 64
> The buggy address is located 58 bytes inside of
>  64-byte region [ffff8801c36c6680, ffff8801c36c66c0)
> The buggy address belongs to the page:
> page:ffffea00070db180 count:1 mapcount:0 mapping:ffff8801da800340
> index:0xffff8801c36c6380
> flags: 0x2fffc0000000100(slab)
> raw: 02fffc0000000100 ffffea0006d16508 ffffea000638a588 ffff8801da800340
> raw: ffff8801c36c6380 ffff8801c36c6000 000000010000001b 0000000000000000
> page dumped because: kasan: bad access detected
>
> Memory state around the buggy address:
>  ffff8801c36c6580: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
>  ffff8801c36c6600: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
>>
>> ffff8801c36c6680: 00 00 00 00 00 00 00 02 fc fc fc fc fc fc fc fc
>
>                                         ^
>  ffff8801c36c6700: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
>  ffff8801c36c6780: fb fb fb fb fb fb fb fb fc fc fc 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#bug-status-tracking for how to communicate with
> syzbot.
>
> --
> You received this message because you are subscribed to the Google Groups
> "syzkaller-bugs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to syzkaller-bugs+unsubscribe@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/syzkaller-bugs/0000000000003852440576ef80b2%40google.com.
> For more options, visit https://groups.google.com/d/optout.

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

* Re: KASAN: slab-out-of-bounds Read in string (2)
  2018-09-28 14:55 ` Dmitry Vyukov
@ 2018-09-28 17:39   ` Amir Goldstein
  2018-10-24  9:09     ` Dan Carpenter
  0 siblings, 1 reply; 9+ messages in thread
From: Amir Goldstein @ 2018-09-28 17:39 UTC (permalink / raw)
  To: dvyukov
  Cc: syzbot+376cea2b0ef340db3dd4, Miklos Szeredi, overlayfs,
	linux-kernel, pmladek, Steven Rostedt (VMware),
	sergey.senozhatsky, syzkaller-bugs, Dan Carpenter, Jan Harkes,
	Jeff Layton, Mark Fasheh

On Fri, Sep 28, 2018 at 5:55 PM Dmitry Vyukov <dvyukov@google.com> wrote:
>
> On Fri, Sep 28, 2018 at 4:45 PM, syzbot
> <syzbot+376cea2b0ef340db3dd4@syzkaller.appspotmail.com> wrote:
> > Hello,
> >
> > syzbot found the following crash on:
> >
> > HEAD commit:    c127e59bee3e Merge tag 'for_v4.19-rc6' of git://git.kernel..
> > git tree:       upstream
> > console output: https://syzkaller.appspot.com/x/log.txt?x=13b2f32a400000
> > kernel config:  https://syzkaller.appspot.com/x/.config?x=dfb440e26f0a6f6f
> > dashboard link: https://syzkaller.appspot.com/bug?extid=376cea2b0ef340db3dd4
> > compiler:       gcc (GCC) 8.0.1 20180413 (experimental)
> >
> > 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+376cea2b0ef340db3dd4@syzkaller.appspotmail.com
>
> I guess this is overlayfs rather than printk. +overlayfs maintainers
> In future syzbot will avoid attributing crashes to printk, because I
> think it's not the first time crashes are mis-attributed to printk:
> https://github.com/google/syzkaller/commit/41e4b32952f4590341ae872db0abf819b4004713
>
>
> > RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000020000140
> > RBP: 000000000072bf00 R08: 0000000000000000 R09: 0000000000000000
> > R10: 0000000000000000 R11: 0000000000000246 R12: 00007f0e714a76d4
> > R13: 00000000004c32cb R14: 00000000004d4ef0 R15: 0000000000000004
> > ==================================================================
> > BUG: KASAN: slab-out-of-bounds in string+0x298/0x2d0 lib/vsprintf.c:604
> > Read of size 1 at addr ffff8801c36c66ba by task syz-executor2/27811
> >
> > CPU: 0 PID: 27811 Comm: syz-executor2 Not tainted 4.19.0-rc5+ #36
> > 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+0x1c4/0x2b4 lib/dump_stack.c:113
> >  print_address_description.cold.8+0x9/0x1ff mm/kasan/report.c:256
> >  kasan_report_error mm/kasan/report.c:354 [inline]
> >  kasan_report.cold.9+0x242/0x309 mm/kasan/report.c:412
> >  __asan_report_load1_noabort+0x14/0x20 mm/kasan/report.c:430
> >  string+0x298/0x2d0 lib/vsprintf.c:604
> >  vsnprintf+0x48e/0x1b60 lib/vsprintf.c:2293
> >  vscnprintf+0x2d/0x80 lib/vsprintf.c:2396
> >  vprintk_store+0x43/0x510 kernel/printk/printk.c:1847
> >  vprintk_emit+0x1c1/0x930 kernel/printk/printk.c:1905
> >  vprintk_default+0x28/0x30 kernel/printk/printk.c:1963
> >  vprintk_func+0x7e/0x181 kernel/printk/printk_safe.c:398
> >  printk+0xa7/0xcf kernel/printk/printk.c:1996
> >  ovl_lookup_index.cold.15+0xe8/0x1f8 fs/overlayfs/namei.c:689

Doh!
I used %*s instead of %.s
Look how common this mistake is! and I only checked under fs/

[CC: Dan Carpenter and other fs maintainers]
Idea for static code analyzers:
A variable named *len* is probably not what someone wants to describe
the width of %*s field and in most cases I found were %*s is used correctly
the string value is a compiler constant (often "").

Thanks,
Amir.

---
diff --git a/fs/coda/dir.c b/fs/coda/dir.c
index 00876ddadb43..23ee5de8b4be 100644
--- a/fs/coda/dir.c
+++ b/fs/coda/dir.c
@@ -47,7 +47,7 @@ static struct dentry *coda_lookup(struct inode *dir,
struct dentry *entry, unsig
        int type = 0;

        if (length > CODA_MAXNAMLEN) {
-               pr_err("name too long: lookup, %s (%*s)\n",
+               pr_err("name too long: lookup, %s (%.*s)\n",
                       coda_i2s(dir), (int)length, name);
                return ERR_PTR(-ENAMETOOLONG);
        }
diff --git a/fs/lockd/host.c b/fs/lockd/host.c
index d35cd6be0675..93fb7cf0b92b 100644
--- a/fs/lockd/host.c
+++ b/fs/lockd/host.c
@@ -341,7 +341,7 @@ struct nlm_host *nlmsvc_lookup_host(const struct
svc_rqst *rqstp,
        };
        struct lockd_net *ln = net_generic(net, lockd_net_id);

-       dprintk("lockd: %s(host='%*s', vers=%u, proto=%s)\n", __func__,
+       dprintk("lockd: %s(host='%.*s', vers=%u, proto=%s)\n", __func__,
                        (int)hostname_len, hostname, rqstp->rq_vers,
                        (rqstp->rq_prot == IPPROTO_UDP ? "udp" : "tcp"));

diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
index 3415e0b09398..b74435dc85fd 100644
--- a/fs/ocfs2/super.c
+++ b/fs/ocfs2/super.c
@@ -259,7 +259,7 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb,
char *buf, int len)

        if (cconn) {
                out += snprintf(buf + out, len - out,
-                               "%10s => Stack: %s  Name: %*s  "
+                               "%10s => Stack: %s  Name: %.*s  "
                                "Version: %d.%d\n", "Cluster",
                                (*osb->osb_cluster_stack == '\0' ?
                                 "o2cb" : osb->osb_cluster_stack),
diff --git a/fs/overlayfs/namei.c b/fs/overlayfs/namei.c
index f28711846dd6..9c0ca6a7becf 100644
--- a/fs/overlayfs/namei.c
+++ b/fs/overlayfs/namei.c
@@ -686,7 +686,7 @@ struct dentry *ovl_lookup_index(struct ovl_fs
*ofs, struct dentry *upper,
                        index = NULL;
                        goto out;
                }
-               pr_warn_ratelimited("overlayfs: failed inode index
lookup (ino=%lu, key=%*s, err=%i);\n"
+               pr_warn_ratelimited("overlayfs: failed inode index
lookup (ino=%lu, key=%.*s, err=%i);\n"
                                    "overlayfs: mount with '-o
index=off' to disable inodes index.\n",
                                    d_inode(origin)->i_ino, name.len, name.name,
                                    err);
diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
index f61839e1054c..c096f12657cd 100644
--- a/fs/overlayfs/overlayfs.h
+++ b/fs/overlayfs/overlayfs.h
@@ -152,7 +152,7 @@ static inline int ovl_do_setxattr(struct dentry
*dentry, const char *name,
                                  const void *value, size_t size, int flags)
 {
        int err = vfs_setxattr(dentry, name, value, size, flags);
-       pr_debug("setxattr(%pd2, \"%s\", \"%*s\", 0x%x) = %i\n",
+       pr_debug("setxattr(%pd2, \"%s\", \"%.*s\", 0x%x) = %i\n",
                 dentry, name, (int) size, (char *) value, flags, err);
        return err;
 }

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

* Re: KASAN: slab-out-of-bounds Read in string (2)
  2018-09-28 17:39   ` Amir Goldstein
@ 2018-10-24  9:09     ` Dan Carpenter
  2018-10-24  9:35       ` Amir Goldstein
  0 siblings, 1 reply; 9+ messages in thread
From: Dan Carpenter @ 2018-10-24  9:09 UTC (permalink / raw)
  To: Amir Goldstein
  Cc: dvyukov, syzbot+376cea2b0ef340db3dd4, Miklos Szeredi, overlayfs,
	linux-kernel, pmladek, Steven Rostedt (VMware),
	sergey.senozhatsky, syzkaller-bugs, Jan Harkes, Jeff Layton,
	Mark Fasheh

Hi Amir,

Thanks so much for this idea.

On Fri, Sep 28, 2018 at 08:39:15PM +0300, Amir Goldstein wrote:
> On Fri, Sep 28, 2018 at 5:55 PM Dmitry Vyukov <dvyukov@google.com> wrote:
> >
> > On Fri, Sep 28, 2018 at 4:45 PM, syzbot
> > <syzbot+376cea2b0ef340db3dd4@syzkaller.appspotmail.com> wrote:
> > > Hello,
> > >
> > > syzbot found the following crash on:
> > >
> > > HEAD commit:    c127e59bee3e Merge tag 'for_v4.19-rc6' of git://git.kernel..
> > > git tree:       upstream
> > > console output: https://syzkaller.appspot.com/x/log.txt?x=13b2f32a400000
> > > kernel config:  https://syzkaller.appspot.com/x/.config?x=dfb440e26f0a6f6f
> > > dashboard link: https://syzkaller.appspot.com/bug?extid=376cea2b0ef340db3dd4
> > > compiler:       gcc (GCC) 8.0.1 20180413 (experimental)
> > >
> > > 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+376cea2b0ef340db3dd4@syzkaller.appspotmail.com
> >
> > I guess this is overlayfs rather than printk. +overlayfs maintainers
> > In future syzbot will avoid attributing crashes to printk, because I
> > think it's not the first time crashes are mis-attributed to printk:
> > https://github.com/google/syzkaller/commit/41e4b32952f4590341ae872db0abf819b4004713
> >
> >
> > > RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000020000140
> > > RBP: 000000000072bf00 R08: 0000000000000000 R09: 0000000000000000
> > > R10: 0000000000000000 R11: 0000000000000246 R12: 00007f0e714a76d4
> > > R13: 00000000004c32cb R14: 00000000004d4ef0 R15: 0000000000000004
> > > ==================================================================
> > > BUG: KASAN: slab-out-of-bounds in string+0x298/0x2d0 lib/vsprintf.c:604
> > > Read of size 1 at addr ffff8801c36c66ba by task syz-executor2/27811
> > >
> > > CPU: 0 PID: 27811 Comm: syz-executor2 Not tainted 4.19.0-rc5+ #36
> > > 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+0x1c4/0x2b4 lib/dump_stack.c:113
> > >  print_address_description.cold.8+0x9/0x1ff mm/kasan/report.c:256
> > >  kasan_report_error mm/kasan/report.c:354 [inline]
> > >  kasan_report.cold.9+0x242/0x309 mm/kasan/report.c:412
> > >  __asan_report_load1_noabort+0x14/0x20 mm/kasan/report.c:430
> > >  string+0x298/0x2d0 lib/vsprintf.c:604
> > >  vsnprintf+0x48e/0x1b60 lib/vsprintf.c:2293
> > >  vscnprintf+0x2d/0x80 lib/vsprintf.c:2396
> > >  vprintk_store+0x43/0x510 kernel/printk/printk.c:1847
> > >  vprintk_emit+0x1c1/0x930 kernel/printk/printk.c:1905
> > >  vprintk_default+0x28/0x30 kernel/printk/printk.c:1963
> > >  vprintk_func+0x7e/0x181 kernel/printk/printk_safe.c:398
> > >  printk+0xa7/0xcf kernel/printk/printk.c:1996
> > >  ovl_lookup_index.cold.15+0xe8/0x1f8 fs/overlayfs/namei.c:689
> 
> Doh!
> I used %*s instead of %.s
> Look how common this mistake is! and I only checked under fs/
> 
> [CC: Dan Carpenter and other fs maintainers]
> Idea for static code analyzers:
> A variable named *len* is probably not what someone wants to describe
> the width of %*s field and in most cases I found were %*s is used correctly
> the string value is a compiler constant (often "").
> 
> Thanks,
> Amir.
> 
> ---
> diff --git a/fs/coda/dir.c b/fs/coda/dir.c
> index 00876ddadb43..23ee5de8b4be 100644
> --- a/fs/coda/dir.c
> +++ b/fs/coda/dir.c
> @@ -47,7 +47,7 @@ static struct dentry *coda_lookup(struct inode *dir,
> struct dentry *entry, unsig
>         int type = 0;
> 
>         if (length > CODA_MAXNAMLEN) {
> -               pr_err("name too long: lookup, %s (%*s)\n",
> +               pr_err("name too long: lookup, %s (%.*s)\n",

This isn't the right fix because "length" is invalid.

>                        coda_i2s(dir), (int)length, name);
>                 return ERR_PTR(-ENAMETOOLONG);
>         }
> diff --git a/fs/lockd/host.c b/fs/lockd/host.c
> index d35cd6be0675..93fb7cf0b92b 100644
> --- a/fs/lockd/host.c
> +++ b/fs/lockd/host.c
> @@ -341,7 +341,7 @@ struct nlm_host *nlmsvc_lookup_host(const struct
> svc_rqst *rqstp,
>         };
>         struct lockd_net *ln = net_generic(net, lockd_net_id);
> 
> -       dprintk("lockd: %s(host='%*s', vers=%u, proto=%s)\n", __func__,
> +       dprintk("lockd: %s(host='%.*s', vers=%u, proto=%s)\n", __func__,
>                         (int)hostname_len, hostname, rqstp->rq_vers,
>                         (rqstp->rq_prot == IPPROTO_UDP ? "udp" : "tcp"));
> 

Why wasn't this one applied?  It looks correct to me.  The rest seem to
have been fixed already.

I did find one other bug in wireless and I CC'd you on that.  I'm going
to do a little bit more testing on the check and then push it soon.
Thanks again!

regards,
dan carpenter


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

* Re: KASAN: slab-out-of-bounds Read in string (2)
  2018-10-24  9:09     ` Dan Carpenter
@ 2018-10-24  9:35       ` Amir Goldstein
  2018-10-24 10:40         ` Jeff Layton
  0 siblings, 1 reply; 9+ messages in thread
From: Amir Goldstein @ 2018-10-24  9:35 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Dmitry Vyukov, syzbot+376cea2b0ef340db3dd4, Miklos Szeredi,
	overlayfs, linux-kernel, Petr Mladek, Steven Rostedt (VMware),
	Sergey Senozhatsky, syzkaller-bugs, Jan Harkes, Jeff Layton,
	Mark Fasheh

> > diff --git a/fs/lockd/host.c b/fs/lockd/host.c
> > index d35cd6be0675..93fb7cf0b92b 100644
> > --- a/fs/lockd/host.c
> > +++ b/fs/lockd/host.c
> > @@ -341,7 +341,7 @@ struct nlm_host *nlmsvc_lookup_host(const struct
> > svc_rqst *rqstp,
> >         };
> >         struct lockd_net *ln = net_generic(net, lockd_net_id);
> >
> > -       dprintk("lockd: %s(host='%*s', vers=%u, proto=%s)\n", __func__,
> > +       dprintk("lockd: %s(host='%.*s', vers=%u, proto=%s)\n", __func__,
> >                         (int)hostname_len, hostname, rqstp->rq_vers,
> >                         (rqstp->rq_prot == IPPROTO_UDP ? "udp" : "tcp"));
> >
>
> Why wasn't this one applied?  It looks correct to me.  The rest seem to
> have been fixed already.
>

I did not send this patch to Jeff.
Jeff was CC'ed on the patch I sent to Miklos
and Miklos decided to only take the overlayfs bits:
https://marc.info/?l=linux-unionfs&m=153847248625015&w=2

So I guess it has fallen between the cracks.
Feel free to send a patch to Jeff.

Thanks,
Amir.

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

* Re: KASAN: slab-out-of-bounds Read in string (2)
  2018-10-24  9:35       ` Amir Goldstein
@ 2018-10-24 10:40         ` Jeff Layton
  2018-10-25 15:02           ` Bruce Fields
  0 siblings, 1 reply; 9+ messages in thread
From: Jeff Layton @ 2018-10-24 10:40 UTC (permalink / raw)
  To: Amir Goldstein, Dan Carpenter, Bruce Fields
  Cc: Dmitry Vyukov, syzbot+376cea2b0ef340db3dd4, Miklos Szeredi,
	overlayfs, linux-kernel, Petr Mladek, Steven Rostedt (VMware),
	Sergey Senozhatsky, syzkaller-bugs, Jan Harkes, Mark Fasheh

On Wed, 2018-10-24 at 12:35 +0300, Amir Goldstein wrote:
> > > diff --git a/fs/lockd/host.c b/fs/lockd/host.c
> > > index d35cd6be0675..93fb7cf0b92b 100644
> > > --- a/fs/lockd/host.c
> > > +++ b/fs/lockd/host.c
> > > @@ -341,7 +341,7 @@ struct nlm_host *nlmsvc_lookup_host(const struct
> > > svc_rqst *rqstp,
> > >         };
> > >         struct lockd_net *ln = net_generic(net, lockd_net_id);
> > > 
> > > -       dprintk("lockd: %s(host='%*s', vers=%u, proto=%s)\n", __func__,
> > > +       dprintk("lockd: %s(host='%.*s', vers=%u, proto=%s)\n", __func__,
> > >                         (int)hostname_len, hostname, rqstp->rq_vers,
> > >                         (rqstp->rq_prot == IPPROTO_UDP ? "udp" : "tcp"));
> > > 
> > 
> > Why wasn't this one applied?  It looks correct to me.  The rest seem to
> > have been fixed already.
> > 
> 
> I did not send this patch to Jeff.
> Jeff was CC'ed on the patch I sent to Miklos
> and Miklos decided to only take the overlayfs bits:
> https://marc.info/?l=linux-unionfs&m=153847248625015&w=2
> 
> So I guess it has fallen between the cracks.
> Feel free to send a patch to Jeff.
> 
> Thanks,
> Amir.

Actually, this should probably go to Bruce, as he mostly takes care of
lockd. Patch looks correct though.

Thanks,
-- 
Jeff Layton <jlayton@kernel.org>


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

* Re: KASAN: slab-out-of-bounds Read in string (2)
  2018-10-24 10:40         ` Jeff Layton
@ 2018-10-25 15:02           ` Bruce Fields
  2018-10-25 15:17             ` Amir Goldstein
  0 siblings, 1 reply; 9+ messages in thread
From: Bruce Fields @ 2018-10-25 15:02 UTC (permalink / raw)
  To: Jeff Layton
  Cc: Amir Goldstein, Dan Carpenter, Dmitry Vyukov,
	syzbot+376cea2b0ef340db3dd4, Miklos Szeredi, overlayfs,
	linux-kernel, Petr Mladek, Steven Rostedt (VMware),
	Sergey Senozhatsky, syzkaller-bugs, Jan Harkes, Mark Fasheh

On Wed, Oct 24, 2018 at 06:40:35AM -0400, Jeff Layton wrote:
> On Wed, 2018-10-24 at 12:35 +0300, Amir Goldstein wrote:
> > > > diff --git a/fs/lockd/host.c b/fs/lockd/host.c
> > > > index d35cd6be0675..93fb7cf0b92b 100644
> > > > --- a/fs/lockd/host.c
> > > > +++ b/fs/lockd/host.c
> > > > @@ -341,7 +341,7 @@ struct nlm_host *nlmsvc_lookup_host(const struct
> > > > svc_rqst *rqstp,
> > > >         };
> > > >         struct lockd_net *ln = net_generic(net, lockd_net_id);
> > > > 
> > > > -       dprintk("lockd: %s(host='%*s', vers=%u, proto=%s)\n", __func__,
> > > > +       dprintk("lockd: %s(host='%.*s', vers=%u, proto=%s)\n", __func__,
> > > >                         (int)hostname_len, hostname, rqstp->rq_vers,
> > > >                         (rqstp->rq_prot == IPPROTO_UDP ? "udp" : "tcp"));
> > > > 
> > > 
> > > Why wasn't this one applied?  It looks correct to me.  The rest seem to
> > > have been fixed already.
> > > 
> > 
> > I did not send this patch to Jeff.
> > Jeff was CC'ed on the patch I sent to Miklos
> > and Miklos decided to only take the overlayfs bits:
> > https://marc.info/?l=linux-unionfs&m=153847248625015&w=2
> > 
> > So I guess it has fallen between the cracks.
> > Feel free to send a patch to Jeff.
> > 
> > Thanks,
> > Amir.
> 
> Actually, this should probably go to Bruce, as he mostly takes care of
> lockd. Patch looks correct though.

Yes, if you could resend I'd be happy to handle it.--b.

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

* Re: KASAN: slab-out-of-bounds Read in string (2)
  2018-10-25 15:02           ` Bruce Fields
@ 2018-10-25 15:17             ` Amir Goldstein
  2018-10-25 16:19               ` J. Bruce Fields
  0 siblings, 1 reply; 9+ messages in thread
From: Amir Goldstein @ 2018-10-25 15:17 UTC (permalink / raw)
  To: J. Bruce Fields
  Cc: Jeff Layton, Dan Carpenter, Dmitry Vyukov,
	syzbot+376cea2b0ef340db3dd4, Miklos Szeredi, overlayfs,
	linux-kernel, Petr Mladek, Steven Rostedt (VMware),
	Sergey Senozhatsky, syzkaller-bugs, Jan Harkes, Mark Fasheh

[-- Attachment #1: Type: text/plain, Size: 403 bytes --]

On Thu, Oct 25, 2018 at 6:02 PM Bruce Fields <bfields@fieldses.org> wrote:

> > > So I guess it has fallen between the cracks.
> > > Feel free to send a patch to Jeff.
> > >
> > > Thanks,
> > > Amir.
> >
> > Actually, this should probably go to Bruce, as he mostly takes care of
> > lockd. Patch looks correct though.
>
> Yes, if you could resend I'd be happy to handle it.--b.

Attached.
Thanks,
Amir.

[-- Attachment #2: 0001-lockd-fix-access-beyond-unterminated-strings-in-prin.patch --]
[-- Type: text/x-patch, Size: 999 bytes --]

From 40000f4dcbd5dd18a80efb6aef010f1164985583 Mon Sep 17 00:00:00 2001
From: Amir Goldstein <amir73il@gmail.com>
Date: Fri, 28 Sep 2018 20:41:48 +0300
Subject: [PATCH] lockd: fix access beyond unterminated strings in prints

printk format used %*s instead of %.*s, so hostname_len does not limit
the number of bytes accessed from hostname.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 fs/lockd/host.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/lockd/host.c b/fs/lockd/host.c
index d35cd6be0675..93fb7cf0b92b 100644
--- a/fs/lockd/host.c
+++ b/fs/lockd/host.c
@@ -341,7 +341,7 @@ struct nlm_host *nlmsvc_lookup_host(const struct svc_rqst *rqstp,
 	};
 	struct lockd_net *ln = net_generic(net, lockd_net_id);
 
-	dprintk("lockd: %s(host='%*s', vers=%u, proto=%s)\n", __func__,
+	dprintk("lockd: %s(host='%.*s', vers=%u, proto=%s)\n", __func__,
 			(int)hostname_len, hostname, rqstp->rq_vers,
 			(rqstp->rq_prot == IPPROTO_UDP ? "udp" : "tcp"));
 
-- 
2.17.1


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

* Re: KASAN: slab-out-of-bounds Read in string (2)
  2018-10-25 15:17             ` Amir Goldstein
@ 2018-10-25 16:19               ` J. Bruce Fields
  0 siblings, 0 replies; 9+ messages in thread
From: J. Bruce Fields @ 2018-10-25 16:19 UTC (permalink / raw)
  To: Amir Goldstein
  Cc: Jeff Layton, Dan Carpenter, Dmitry Vyukov,
	syzbot+376cea2b0ef340db3dd4, Miklos Szeredi, overlayfs,
	linux-kernel, Petr Mladek, Steven Rostedt (VMware),
	Sergey Senozhatsky, syzkaller-bugs, Jan Harkes, Mark Fasheh

On Thu, Oct 25, 2018 at 06:17:25PM +0300, Amir Goldstein wrote:
> On Thu, Oct 25, 2018 at 6:02 PM Bruce Fields <bfields@fieldses.org> wrote:
> 
> > > > So I guess it has fallen between the cracks.
> > > > Feel free to send a patch to Jeff.
> > > >
> > > > Thanks,
> > > > Amir.
> > >
> > > Actually, this should probably go to Bruce, as he mostly takes care of
> > > lockd. Patch looks correct though.
> >
> > Yes, if you could resend I'd be happy to handle it.--b.
> 
> Attached.

Thanks, queuing it up for 4.20 and stable.

--b.

> Thanks,
> Amir.

> From 40000f4dcbd5dd18a80efb6aef010f1164985583 Mon Sep 17 00:00:00 2001
> From: Amir Goldstein <amir73il@gmail.com>
> Date: Fri, 28 Sep 2018 20:41:48 +0300
> Subject: [PATCH] lockd: fix access beyond unterminated strings in prints
> 
> printk format used %*s instead of %.*s, so hostname_len does not limit
> the number of bytes accessed from hostname.
> 
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> ---
>  fs/lockd/host.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/lockd/host.c b/fs/lockd/host.c
> index d35cd6be0675..93fb7cf0b92b 100644
> --- a/fs/lockd/host.c
> +++ b/fs/lockd/host.c
> @@ -341,7 +341,7 @@ struct nlm_host *nlmsvc_lookup_host(const struct svc_rqst *rqstp,
>  	};
>  	struct lockd_net *ln = net_generic(net, lockd_net_id);
>  
> -	dprintk("lockd: %s(host='%*s', vers=%u, proto=%s)\n", __func__,
> +	dprintk("lockd: %s(host='%.*s', vers=%u, proto=%s)\n", __func__,
>  			(int)hostname_len, hostname, rqstp->rq_vers,
>  			(rqstp->rq_prot == IPPROTO_UDP ? "udp" : "tcp"));
>  
> -- 
> 2.17.1
> 


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

end of thread, other threads:[~2018-10-25 16:19 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-28 14:45 KASAN: slab-out-of-bounds Read in string (2) syzbot
2018-09-28 14:55 ` Dmitry Vyukov
2018-09-28 17:39   ` Amir Goldstein
2018-10-24  9:09     ` Dan Carpenter
2018-10-24  9:35       ` Amir Goldstein
2018-10-24 10:40         ` Jeff Layton
2018-10-25 15:02           ` Bruce Fields
2018-10-25 15:17             ` Amir Goldstein
2018-10-25 16:19               ` J. Bruce Fields

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