Skip to content
  • YueHaibing's avatar
    net: nfc: Fix NULL dereference on nfc_llcp_build_tlv fails · 58bdd544
    YueHaibing authored
    
    
    KASAN report this:
    
    BUG: KASAN: null-ptr-deref in nfc_llcp_build_gb+0x37f/0x540 [nfc]
    Read of size 3 at addr 0000000000000000 by task syz-executor.0/5401
    
    CPU: 0 PID: 5401 Comm: syz-executor.0 Not tainted 5.0.0-rc7+ #45
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014
    Call Trace:
     __dump_stack lib/dump_stack.c:77 [inline]
     dump_stack+0xfa/0x1ce lib/dump_stack.c:113
     kasan_report+0x171/0x18d mm/kasan/report.c:321
     memcpy+0x1f/0x50 mm/kasan/common.c:130
     nfc_llcp_build_gb+0x37f/0x540 [nfc]
     nfc_llcp_register_device+0x6eb/0xb50 [nfc]
     nfc_register_device+0x50/0x1d0 [nfc]
     nfcsim_device_new+0x394/0x67d [nfcsim]
     ? 0xffffffffc1080000
     nfcsim_init+0x6b/0x1000 [nfcsim]
     do_one_initcall+0xfa/0x5ca init/main.c:887
     do_init_module+0x204/0x5f6 kernel/module.c:3460
     load_module+0x66b2/0x8570 kernel/module.c:3808
     __do_sys_finit_module+0x238/0x2a0 kernel/module.c:3902
     do_syscall_64+0x147/0x600 arch/x86/entry/common.c:290
     entry_SYSCALL_64_after_hwframe+0x49/0xbe
    RIP: 0033:0x462e99
    Code: f7 d8 64 89 02 b8 ff ff ff ff c3 66 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 bc ff ff ff f7 d8 64 89 01 48
    RSP: 002b:00007f9cb79dcc58 EFLAGS: 00000246 ORIG_RAX: 0000000000000139
    RAX: ffffffffffffffda RBX: 000000000073bf00 RCX: 0000000000462e99
    RDX: 0000000000000000 RSI: 0000000020000280 RDI: 0000000000000003
    RBP: 00007f9cb79dcc70 R08: 0000000000000000 R09: 0000000000000000
    R10: 0000000000000000 R11: 0000000000000246 R12: 00007f9cb79dd6bc
    R13: 00000000004bcefb R14: 00000000006f7030 R15: 0000000000000004
    
    nfc_llcp_build_tlv will return NULL on fails, caller should check it,
    otherwise will trigger a NULL dereference.
    
    Reported-by: default avatarHulk Robot <hulkci@huawei.com>
    Fixes: eda21f16 ("NFC: Set MIU and RW values from CONNECT and CC LLCP frames")
    Fixes: d646960f
    
     ("NFC: Initial LLCP support")
    Signed-off-by: default avatarYueHaibing <yuehaibing@huawei.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    58bdd544