syzbot


KASAN: slab-out-of-bounds Read in asn1_ber_decoder

Status: fixed on 2017/11/11 01:37
Subsystems: keyrings crypto
[Documentation on labels]
Fix commit: 2eb9eabf1e86 KEYS: fix out-of-bounds read during ASN.1 parsing
First crash: 2386d, last: 2380d

Sample crash report:
BUG: KASAN: slab-out-of-bounds in asn1_ber_decoder+0x1436/0x1c20 lib/asn1_decoder.c:233
Read of size 1 at addr ffff8801d20cf302 by task syzkaller682464/2998

CPU: 0 PID: 2998 Comm: syzkaller682464 Not tainted 4.14.0-rc5-mm1+ #20
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
 __dump_stack lib/dump_stack.c:16 [inline]
 dump_stack+0x194/0x257 lib/dump_stack.c:52
 print_address_description+0x73/0x250 mm/kasan/report.c:252
 kasan_report_error mm/kasan/report.c:351 [inline]
 kasan_report+0x25b/0x340 mm/kasan/report.c:409
 __asan_report_load1_noabort+0x14/0x20 mm/kasan/report.c:427
 asn1_ber_decoder+0x1436/0x1c20 lib/asn1_decoder.c:233
 x509_cert_parse+0x1dd/0x680 crypto/asymmetric_keys/x509_cert_parser.c:89
 x509_key_preparse+0x64/0x8b0 crypto/asymmetric_keys/x509_public_key.c:174
 asymmetric_key_preparse+0xa8/0x110 crypto/asymmetric_keys/asymmetric_type.c:386
 key_create_or_update+0x4c6/0xe20 security/keys/key.c:846
 SYSC_add_key security/keys/keyctl.c:122 [inline]
 SyS_add_key+0x18a/0x340 security/keys/keyctl.c:62
 entry_SYSCALL_64_fastpath+0x1f/0xbe
RIP: 0033:0x43fd89
RSP: 002b:00007fffa4c8bf38 EFLAGS: 00000286 ORIG_RAX: 00000000000000f8
RAX: ffffffffffffffda RBX: 00000000004002c8 RCX: 000000000043fd89
RDX: 00000000201d9000 RSI: 00000000205ceffb RDI: 0000000020825ff5
RBP: 0000000000000082 R08: ffffffffffffffff R09: 0000000000000000
R10: 0000000000000002 R11: 0000000000000286 R12: 00000000004016f0
R13: 0000000000401780 R14: 0000000000000000 R15: 0000000000000000

Allocated by task 2998:
 save_stack+0x43/0xd0 mm/kasan/kasan.c:447
 set_track mm/kasan/kasan.c:459 [inline]
 kasan_kmalloc+0xad/0xe0 mm/kasan/kasan.c:551
 __do_kmalloc_node mm/slab.c:3676 [inline]
 __kmalloc_node+0x47/0x70 mm/slab.c:3683
 kmalloc_node include/linux/slab.h:541 [inline]
 kvmalloc_node+0x99/0xd0 mm/util.c:397
 kvmalloc include/linux/mm.h:538 [inline]
 SYSC_add_key security/keys/keyctl.c:104 [inline]
 SyS_add_key+0x279/0x340 security/keys/keyctl.c:62
 entry_SYSCALL_64_fastpath+0x1f/0xbe

Freed by task 1532:
 save_stack+0x43/0xd0 mm/kasan/kasan.c:447
 set_track mm/kasan/kasan.c:459 [inline]
 kasan_slab_free+0x71/0xc0 mm/kasan/kasan.c:524
 __cache_free mm/slab.c:3492 [inline]
 kfree+0xca/0x250 mm/slab.c:3807
 load_elf_binary+0x2035/0x4d80 fs/binfmt_elf.c:1096
 search_binary_handler+0x142/0x6b0 fs/exec.c:1635
 exec_binprm fs/exec.c:1677 [inline]
 do_execveat_common.isra.31+0x1703/0x21c0 fs/exec.c:1799
 do_execve fs/exec.c:1843 [inline]
 SYSC_execve fs/exec.c:1924 [inline]
 SyS_execve+0x39/0x50 fs/exec.c:1919
 do_syscall_64+0x26c/0x8d0 arch/x86/entry/common.c:287
 return_from_SYSCALL_64+0x0/0x7a

The buggy address belongs to the object at ffff8801d20cf300
 which belongs to the cache kmalloc-32 of size 32
The buggy address is located 2 bytes inside of
 32-byte region [ffff8801d20cf300, ffff8801d20cf320)
The buggy address belongs to the page:
page:ffffea00074833c0 count:1 mapcount:0 mapping:ffff8801d20cf000 index:0xffff8801d20cffc1
flags: 0x200000000000100(slab)
raw: 0200000000000100 ffff8801d20cf000 ffff8801d20cffc1 000000010000003f
raw: ffffea000749f960 ffffea0007473260 ffff8801dac001c0 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
 ffff8801d20cf200: 00 00 00 fc fc fc fc fc 00 00 00 fc fc fc fc fc
 ffff8801d20cf280: 00 00 00 fc fc fc fc fc 00 00 00 fc fc fc fc fc
>ffff8801d20cf300: 02 fc fc fc fc fc fc fc fb fb fb fb fc fc fc fc
                   ^
 ffff8801d20cf380: 00 00 00 fc fc fc fc fc 00 00 00 fc fc fc fc fc
 ffff8801d20cf400: 00 00 00 fc fc fc fc fc 00 00 00 fc fc fc fc fc
==================================================================

Crashes (17):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2017/11/03 18:07 mmots 0f611fb6dcc0 e0a2b195 .config console log report syz C ci-upstream-mmots-kasan-gce
2017/11/10 10:35 mmots 0f611fb6dcc0 e0a2b195 .config console log report ci-upstream-mmots-kasan-gce
2017/11/10 09:56 mmots 0f611fb6dcc0 e0a2b195 .config console log report ci-upstream-mmots-kasan-gce
2017/11/09 03:29 mmots 0f611fb6dcc0 e0a2b195 .config console log report ci-upstream-mmots-kasan-gce
2017/11/08 15:17 mmots 0f611fb6dcc0 e0a2b195 .config console log report ci-upstream-mmots-kasan-gce
2017/11/08 08:21 mmots 0f611fb6dcc0 e0a2b195 .config console log report ci-upstream-mmots-kasan-gce
2017/11/07 14:08 mmots 0f611fb6dcc0 e0a2b195 .config console log report ci-upstream-mmots-kasan-gce
2017/11/06 19:53 mmots 0f611fb6dcc0 e0a2b195 .config console log report ci-upstream-mmots-kasan-gce
2017/11/06 12:20 mmots 0f611fb6dcc0 e0a2b195 .config console log report ci-upstream-mmots-kasan-gce
2017/11/05 20:41 mmots 0f611fb6dcc0 e0a2b195 .config console log report ci-upstream-mmots-kasan-gce
2017/11/05 20:16 mmots 0f611fb6dcc0 e0a2b195 .config console log report ci-upstream-mmots-kasan-gce
2017/11/05 11:03 mmots 0f611fb6dcc0 e0a2b195 .config console log report ci-upstream-mmots-kasan-gce
2017/11/05 03:35 mmots 0f611fb6dcc0 e0a2b195 .config console log report ci-upstream-mmots-kasan-gce
2017/11/05 02:25 mmots 0f611fb6dcc0 e0a2b195 .config console log report ci-upstream-mmots-kasan-gce
2017/11/04 04:49 mmots 0f611fb6dcc0 e0a2b195 .config console log report ci-upstream-mmots-kasan-gce
2017/11/03 21:52 mmots 0f611fb6dcc0 e0a2b195 .config console log report ci-upstream-mmots-kasan-gce
2017/11/03 17:53 mmots 0f611fb6dcc0 e0a2b195 .config console log report ci-upstream-mmots-kasan-gce
* Struck through repros no longer work on HEAD.