Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp455220ybb; Wed, 1 Apr 2020 03:24:59 -0700 (PDT) X-Google-Smtp-Source: APiQypLnyEAgKRo3iuOdm+Rt0Ga8uqItGIc1vuZGL2/02X1ypeR5TSBDrQS62Pyyrpndb+hs7wMk X-Received: by 2002:aca:5354:: with SMTP id h81mr2177415oib.164.1585736699591; Wed, 01 Apr 2020 03:24:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585736699; cv=none; d=google.com; s=arc-20160816; b=oA0wssxiZOcCGNQyIefUMEPVpKrRrfNsXbg9CDCmd1yi2uYrh7JOW9gbVCfLrL+qQo gbpUxYzDPCmu+T6WuxKdxX1VDakUU3hQZMsueBQBCXCezP5VvCHlRoQNFCKw28G1ko29 vXijaUyBR2IUa57fTkqPmI7rbCcm/jLS8aQmM6F17JQpn7hB3NMmnXL9G6hovzNC3UF8 U4r5ciOTUGr3nPOZx0i+VA3EJtsfLpbzPS9UiDM1p5S4+WEGU8ZTwIx6aCP650Q81NkH NdVILby5APi8jqIXkf91Qptj4hERXZ2nyqZl3agt9ILjGBMcMuFnis9x5I/PNZGqCTr+ wWuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=VSEkYXpnI5k7ve5WWVqCPGcBRbLwusRCarEKFYYH+lA=; b=xe3fr4xxKjUtisD4IR4eWTFXHXsW2Do+HZ+A1eUg126fTbWHOzrCBOL5i33LN+Xy4q lCeh78EG4nWIf8KFqivs0lVNB5ffqgTZ6ClIeKmN6SgaCvDRNaOl77feUJOeWgco9mHv xQnBqJr86XCOIMakzHCNFBxQFMHRYRbE8VHIV23MJNNPelmEcJqFHbwvFVdid3A93gHq hgd1yN6OJDfA86erHVhZoBMlIfedTqyHfP2kIpZkec3SZfCO3zmkOwpPYG7akHsiod9b ytrZ4ge83O/LCA0SpvJYs0ui/fFy5FOnPcD+e8I+Db/C663IeaSHRmVBkdOAL3N6ow2O 9s9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=D1kwTHk4; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p67si744469oig.41.2020.04.01.03.24.37; Wed, 01 Apr 2020 03:24:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=D1kwTHk4; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731541AbgDAKYO (ORCPT + 99 others); Wed, 1 Apr 2020 06:24:14 -0400 Received: from mail-oi1-f196.google.com ([209.85.167.196]:38334 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726115AbgDAKYO (ORCPT ); Wed, 1 Apr 2020 06:24:14 -0400 Received: by mail-oi1-f196.google.com with SMTP id w2so21755702oic.5 for ; Wed, 01 Apr 2020 03:24:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=VSEkYXpnI5k7ve5WWVqCPGcBRbLwusRCarEKFYYH+lA=; b=D1kwTHk4+1DwwFaRP7uRqnwWHCzN7NQoeqtqEOdcecwTZHim3cXSSslHK+2rmC4Ymw qYEfH139RzCVPDbOiZUb+gMvlRmHBwAAU9TVJSUDL4KrFFEbgQ5ZZdl8Ka6jwREv8WPP Dy1Yr9sm9is/bEG5Tw2B/bVs+3Jdm84o6LE0kdPMBjK8Npptpotrsi6jtp1vpqvjzOZs HroQixeeieijRln/kPea33dQj3gkgz9Qn6DOM2VmfYZx/LG0zKez0hVfKT7LkRX0srF7 j6GZ1SV5RD1Eyh4JKAC/PLY6u9A1emaClqKe6MU2LjVGYZ2L8BdLt+BTBcByHhNWkggP mQAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=VSEkYXpnI5k7ve5WWVqCPGcBRbLwusRCarEKFYYH+lA=; b=SA2NK+FOeIlNWVaBp0xdqKfxW2mOrIMNYd7lp4UaPkzgucqwpAP8qkN+G0MlrXYNJs kroA+6f+7UJrw1oXwUDBtOMh3xVsv9rRFE/AhkXFG1QgvcBXBWK2k3SJ8hTD0UIzJ3BX Fn+ffzfpiOJHetKKY2NuBmdsEIxrvwGtGLd+0nc+1f5iIp4oK/svIVqNNKRvxUafKnh1 lq6PwNNgV0L7/KvEk+jVkudF3syPqCbo57WwUK/IlM9981zRcqyD1CtHGeqADBm7i/Zh 1VkvI2Ee9O9bMPhU80pvW3quqU6wJsvvlY649awDLPekmJ0q6LpM8YbSgXqbpIMXdO4X 5kww== X-Gm-Message-State: AGi0PuZQs5jwYdv2fSt5qaARznMmRdlrAupsULeuhWJgiUj/WFbJRcLr ns2JWxquKpkGI2V2sntUGAnaTe/ejZ6gTgrw9+SVpA== X-Received: by 2002:aca:f541:: with SMTP id t62mr2285070oih.172.1585736652691; Wed, 01 Apr 2020 03:24:12 -0700 (PDT) MIME-Version: 1.0 References: <0000000000009d5cef05a22baa95@google.com> <20200331202706.GA127606@gmail.com> In-Reply-To: From: Marco Elver Date: Wed, 1 Apr 2020 12:24:01 +0200 Message-ID: Subject: Re: KCSAN: data-race in glue_cbc_decrypt_req_128bit / glue_cbc_decrypt_req_128bit To: Dmitry Vyukov Cc: Eric Biggers , syzbot , Borislav Petkov , David Miller , Herbert Xu , "H. Peter Anvin" , "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , LKML , Ingo Molnar , syzkaller-bugs , Thomas Gleixner , "the arch/x86 maintainers" Content-Type: text/plain; charset="UTF-8" Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Wed, 1 Apr 2020 at 09:04, Dmitry Vyukov wrote: > > On Tue, Mar 31, 2020 at 10:27 PM Eric Biggers wrote: > > > > On Tue, Mar 31, 2020 at 12:35:13PM -0700, syzbot wrote: > > > Hello, > > > > > > syzbot found the following crash on: > > > > > > HEAD commit: b12d66a6 mm, kcsan: Instrument SLAB free with ASSERT_EXCLU.. > > > git tree: https://github.com/google/ktsan.git kcsan > > > console output: https://syzkaller.appspot.com/x/log.txt?x=111f0865e00000 > > > kernel config: https://syzkaller.appspot.com/x/.config?x=10bc0131c4924ba9 > > > dashboard link: https://syzkaller.appspot.com/bug?extid=6a6bca8169ffda8ce77b > > > compiler: gcc (GCC) 9.0.0 20181231 (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+6a6bca8169ffda8ce77b@syzkaller.appspotmail.com > > > > > > ================================================================== > > > BUG: KCSAN: data-race in glue_cbc_decrypt_req_128bit / glue_cbc_decrypt_req_128bit > > > > > > write to 0xffff88809966e128 of 8 bytes by task 24119 on cpu 0: > > > u128_xor include/crypto/b128ops.h:67 [inline] > > > glue_cbc_decrypt_req_128bit+0x396/0x460 arch/x86/crypto/glue_helper.c:144 > > > cbc_decrypt+0x26/0x40 arch/x86/crypto/serpent_avx2_glue.c:152 > > > crypto_skcipher_decrypt+0x65/0x90 crypto/skcipher.c:652 > > > _skcipher_recvmsg crypto/algif_skcipher.c:142 [inline] > > > skcipher_recvmsg+0x7fa/0x8c0 crypto/algif_skcipher.c:161 > > > skcipher_recvmsg_nokey+0x5e/0x80 crypto/algif_skcipher.c:279 > > > sock_recvmsg_nosec net/socket.c:886 [inline] > > > sock_recvmsg net/socket.c:904 [inline] > > > sock_recvmsg+0x92/0xb0 net/socket.c:900 > > > ____sys_recvmsg+0x167/0x3a0 net/socket.c:2566 > > > ___sys_recvmsg+0xb2/0x100 net/socket.c:2608 > > > __sys_recvmsg+0x9d/0x160 net/socket.c:2642 > > > __do_sys_recvmsg net/socket.c:2652 [inline] > > > __se_sys_recvmsg net/socket.c:2649 [inline] > > > __x64_sys_recvmsg+0x51/0x70 net/socket.c:2649 > > > do_syscall_64+0xcc/0x3a0 arch/x86/entry/common.c:294 > > > entry_SYSCALL_64_after_hwframe+0x44/0xa9 > > > > > > read to 0xffff88809966e128 of 8 bytes by task 24118 on cpu 1: > > > u128_xor include/crypto/b128ops.h:67 [inline] > > > glue_cbc_decrypt_req_128bit+0x37c/0x460 arch/x86/crypto/glue_helper.c:144 > > > cbc_decrypt+0x26/0x40 arch/x86/crypto/serpent_avx2_glue.c:152 > > > crypto_skcipher_decrypt+0x65/0x90 crypto/skcipher.c:652 > > > _skcipher_recvmsg crypto/algif_skcipher.c:142 [inline] > > > skcipher_recvmsg+0x7fa/0x8c0 crypto/algif_skcipher.c:161 > > > skcipher_recvmsg_nokey+0x5e/0x80 crypto/algif_skcipher.c:279 > > > sock_recvmsg_nosec net/socket.c:886 [inline] > > > sock_recvmsg net/socket.c:904 [inline] > > > sock_recvmsg+0x92/0xb0 net/socket.c:900 > > > ____sys_recvmsg+0x167/0x3a0 net/socket.c:2566 > > > ___sys_recvmsg+0xb2/0x100 net/socket.c:2608 > > > __sys_recvmsg+0x9d/0x160 net/socket.c:2642 > > > __do_sys_recvmsg net/socket.c:2652 [inline] > > > __se_sys_recvmsg net/socket.c:2649 [inline] > > > __x64_sys_recvmsg+0x51/0x70 net/socket.c:2649 > > > do_syscall_64+0xcc/0x3a0 arch/x86/entry/common.c:294 > > > entry_SYSCALL_64_after_hwframe+0x44/0xa9 > > > > > > Reported by Kernel Concurrency Sanitizer on: > > > CPU: 1 PID: 24118 Comm: syz-executor.1 Not tainted 5.6.0-rc1-syzkaller #0 > > > Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 > > > ================================================================== > > > > > > > I think this is a problem for almost all the crypto code. Due to AF_ALG, both > > the source and destination buffers can be userspace pages that were gotten with > > get_user_pages(). Such pages can be concurrently modified, not just by the > > kernel but also by userspace. > > > > I'm not sure what can be done about this. > > Oh, I thought it's something more serious like a shared crypto object. > Thanks for debugging. > I think I've seen this before in another context (b/149818448): > > BUG: KCSAN: data-race in copyin / copyin > > write to 0xffff888103c8b000 of 4096 bytes by task 20917 on cpu 0: > instrument_copy_from_user include/linux/instrumented.h:106 [inline] > copyin+0xab/0xc0 lib/iov_iter.c:151 > copy_page_from_iter_iovec lib/iov_iter.c:296 [inline] > copy_page_from_iter+0x23f/0x5f0 lib/iov_iter.c:942 > process_vm_rw_pages mm/process_vm_access.c:46 [inline] > process_vm_rw_single_vec mm/process_vm_access.c:120 [inline] > process_vm_rw_core.isra.0+0x448/0x820 mm/process_vm_access.c:218 > process_vm_rw+0x1c4/0x1e0 mm/process_vm_access.c:286 > __do_sys_process_vm_writev mm/process_vm_access.c:308 [inline] > __se_sys_process_vm_writev mm/process_vm_access.c:303 [inline] > __x64_sys_process_vm_writev+0x8b/0xb0 mm/process_vm_access.c:303 > do_syscall_64+0xcc/0x3a0 arch/x86/entry/common.c:294 > entry_SYSCALL_64_after_hwframe+0x44/0xa9 > > write to 0xffff888103c8b000 of 4096 bytes by task 20918 on cpu 1: > instrument_copy_from_user include/linux/instrumented.h:106 [inline] > copyin+0xab/0xc0 lib/iov_iter.c:151 > copy_page_from_iter_iovec lib/iov_iter.c:296 [inline] > copy_page_from_iter+0x23f/0x5f0 lib/iov_iter.c:942 > process_vm_rw_pages mm/process_vm_access.c:46 [inline] > process_vm_rw_single_vec mm/process_vm_access.c:120 [inline] > process_vm_rw_core.isra.0+0x448/0x820 mm/process_vm_access.c:218 > process_vm_rw+0x1c4/0x1e0 mm/process_vm_access.c:286 > __do_sys_process_vm_writev mm/process_vm_access.c:308 [inline] > __se_sys_process_vm_writev mm/process_vm_access.c:303 [inline] > __x64_sys_process_vm_writev+0x8b/0xb0 mm/process_vm_access.c:303 > do_syscall_64+0xcc/0x3a0 arch/x86/entry/common.c:294 > entry_SYSCALL_64_after_hwframe+0x44/0xa9 > > > Marco, I think we need to ignore all memory that comes from > get_user_pages() somehow. Either not set watchpoints at all, or > perhaps filter them out later if the check is not totally free. Makes sense. We already have similar checks, and they're in the slow-path, so it shouldn't be a problem. Let me investigate. Thanks, -- Marco