• E
    kcm: avoid potential race in kcm_tx_work · a4c35ce0
    Eric Dumazet 提交于
    mainline inclusion
    from mainline-v6.1-rc1
    commit ec7eede3
    category: bugfix
    bugzilla: 187823, https://gitee.com/src-openeuler/kernel/issues/I5VZ0N
    CVE: CVE-2022-3521
    
    --------------------------------
    
    syzbot found that kcm_tx_work() could crash [1] in:
    
    	/* Primarily for SOCK_SEQPACKET sockets */
    	if (likely(sk->sk_socket) &&
    	    test_bit(SOCK_NOSPACE, &sk->sk_socket->flags)) {
    <<*>>	clear_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
    		sk->sk_write_space(sk);
    	}
    
    I think the reason is that another thread might concurrently
    run in kcm_release() and call sock_orphan(sk) while sk is not
    locked. kcm_tx_work() find sk->sk_socket being NULL.
    
    [1]
    BUG: KASAN: null-ptr-deref in instrument_atomic_write include/linux/instrumented.h:86 [inline]
    BUG: KASAN: null-ptr-deref in clear_bit include/asm-generic/bitops/instrumented-atomic.h:41 [inline]
    BUG: KASAN: null-ptr-deref in kcm_tx_work+0xff/0x160 net/kcm/kcmsock.c:742
    Write of size 8 at addr 0000000000000008 by task kworker/u4:3/53
    
    CPU: 0 PID: 53 Comm: kworker/u4:3 Not tainted 5.19.0-rc3-next-20220621-syzkaller #0
    Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
    Workqueue: kkcmd kcm_tx_work
    Call Trace:
    <TASK>
    __dump_stack lib/dump_stack.c:88 [inline]
    dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106
    kasan_report+0xbe/0x1f0 mm/kasan/report.c:495
    check_region_inline mm/kasan/generic.c:183 [inline]
    kasan_check_range+0x13d/0x180 mm/kasan/generic.c:189
    instrument_atomic_write include/linux/instrumented.h:86 [inline]
    clear_bit include/asm-generic/bitops/instrumented-atomic.h:41 [inline]
    kcm_tx_work+0xff/0x160 net/kcm/kcmsock.c:742
    process_one_work+0x996/0x1610 kernel/workqueue.c:2289
    worker_thread+0x665/0x1080 kernel/workqueue.c:2436
    kthread+0x2e9/0x3a0 kernel/kthread.c:376
    ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:302
    </TASK>
    
    Fixes: ab7ac4eb ("kcm: Kernel Connection Multiplexor module")
    Reported-by: Nsyzbot <syzkaller@googlegroups.com>
    Signed-off-by: NEric Dumazet <edumazet@google.com>
    Cc: Tom Herbert <tom@herbertland.com>
    Link: https://lore.kernel.org/r/20221012133412.519394-1-edumazet@google.comSigned-off-by: NJakub Kicinski <kuba@kernel.org>
    Signed-off-by: NBaisong Zhong <zhongbaisong@huawei.com>
    Reviewed-by: NLiu Jian <liujian56@huawei.com>
    Reviewed-by: NXiu Jianfeng <xiujianfeng@huawei.com>
    Reviewed-by: NYue Haibing <yuehaibing@huawei.com>
    Signed-off-by: NYongqiang Liu <liuyongqiang13@huawei.com>
    a4c35ce0
kcmsock.c 45.1 KB