Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1773447imm; Thu, 27 Sep 2018 02:13:11 -0700 (PDT) X-Google-Smtp-Source: ACcGV61ONx3IZuVaGjy4hTk0MiV4AetWJF9+jTBoW7ldoDWEC93uaKhUVFNdw722rJ8uJEp5P/xU X-Received: by 2002:a63:334c:: with SMTP id z73-v6mr9128320pgz.220.1538039591081; Thu, 27 Sep 2018 02:13:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538039591; cv=none; d=google.com; s=arc-20160816; b=DufDHzdfz5BUv4n4eoiM1Cw5r/NiYwXqD42VKD1c3U+njoAO9JFXLHAt9adgO69E8L 7meV3jpwf2iHAFQxYM+Y+bKzNvhJS1WgOcylGUa1IPeZ+QEIipY2M7/N9MoJCYUBmUtg PxbpY9hc0D2jnzj/bGBunDy4WJ9nDDMv2fOk9xxzj9SWJ89go4WmFE7IgRNVPU8a+aNi wpJ3iM83tiH4SKhWD7pXPoNyloC1j6GMLkuII5yEI3xWNUdIBToTKZ2FcoCDXxWALLnJ 1xvRdnT876xOnNPDa1ykd2lN7bX1rXRM40cCdN1Muh75bj6c7XsoK4+AIR7jHevs3Y/e +5Dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=Zc+fJ5WOBVtp8olvxKipK9e4rHkBJSFznl07wHlxhL4=; b=lMYUwlDeFEBXUXM4BntDkMlVKkjZjYNAVG1ojmc3Wvq7Ur0bBmyRyjMsA8+04z8ZOE Ddv30c3v20tWC9qdTMi4bjZUOB/e6LmuXn+J7yr7XYyZRkf7Z3YOTa7G7p/47jsZI4DG 4GNcy8WnP/UmGtESaTMVR3mxndX2F4mtTPl2OMA3/yT3FAd5zHtFTb2MobEhp8D/VrX8 rHb+rbBa4vyKrJTBRLYb3jRm/ZlPWT157AQklFrHAsgQU+9iOcm55QLnEB6DFpY3BVX3 uC20YBuGJaFqIMWD+AE0JkkfVB0Vmi98X132bEUA//Njq0SXyK8Ne0bx1JvY6DHawRTx 6ZbA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z17-v6si1534930pgc.653.2018.09.27.02.12.55; Thu, 27 Sep 2018 02:13:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728568AbeI0P3O (ORCPT + 99 others); Thu, 27 Sep 2018 11:29:14 -0400 Received: from a.mx.secunet.com ([62.96.220.36]:35902 "EHLO a.mx.secunet.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727032AbeI0P3O (ORCPT ); Thu, 27 Sep 2018 11:29:14 -0400 Received: from localhost (localhost [127.0.0.1]) by a.mx.secunet.com (Postfix) with ESMTP id 469FD201A1; Thu, 27 Sep 2018 13:11:41 +0200 (CEST) X-Virus-Scanned: by secunet Received: from a.mx.secunet.com ([127.0.0.1]) by localhost (a.mx.secunet.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id A9SaN_kJ_dLF; Thu, 27 Sep 2018 13:11:40 +0200 (CEST) Received: from mail-essen-01.secunet.de (mail-essen-01.secunet.de [10.53.40.204]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by a.mx.secunet.com (Postfix) with ESMTPS id 8E31520184; Thu, 27 Sep 2018 13:11:40 +0200 (CEST) Received: from gauss2.secunet.de (10.182.7.193) by mail-essen-01.secunet.de (10.53.40.204) with Microsoft SMTP Server id 14.3.408.0; Thu, 27 Sep 2018 11:11:57 +0200 Received: by gauss2.secunet.de (Postfix, from userid 1000) id 29B173182A36; Thu, 27 Sep 2018 11:11:57 +0200 (CEST) Date: Thu, 27 Sep 2018 11:11:57 +0200 From: Steffen Klassert To: Ard Biesheuvel CC: , "David S. Miller" , Herbert Xu , "H. Peter Anvin" , "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , Linux Kernel Mailing List , Ingo Molnar , syzkaller-bugs , Thomas Gleixner , the arch/x86 maintainers Subject: Re: KASAN: use-after-free Read in generic_gcmaes_encrypt Message-ID: <20180927091157.GF3823@gauss3.secunet.de> References: <000000000000d014010576cc00f4@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) X-G-Data-MailSecurity-for-Exchange-State: 0 X-G-Data-MailSecurity-for-Exchange-Error: 0 X-G-Data-MailSecurity-for-Exchange-Sender: 23 X-G-Data-MailSecurity-for-Exchange-Server: d65e63f7-5c15-413f-8f63-c0d707471c93 X-EXCLAIMER-MD-CONFIG: 2c86f778-e09b-4440-8b15-867914633a10 X-G-Data-MailSecurity-for-Exchange-Guid: 8F12404B-EC3F-40B7-AC63-5ED101DE2E9F Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 27, 2018 at 10:35:48AM +0200, Ard Biesheuvel wrote: > (+ Stefan) > > On Wed, 26 Sep 2018 at 22:24, syzbot > wrote: > > > > Hello, > > > > syzbot found the following crash on: > > > > HEAD commit: 739d0def85ca Merge branch 'hv_netvsc-Support-LRO-RSC-in-th.. > > git tree: net-next > > console output: https://syzkaller.appspot.com/x/log.txt?x=1146ffae400000 > > kernel config: https://syzkaller.appspot.com/x/.config?x=e79b9299baeb2298 > > dashboard link: https://syzkaller.appspot.com/bug?extid=6d3612ba5e254e387153 > > compiler: gcc (GCC) 8.0.1 20180413 (experimental) > > syz repro: https://syzkaller.appspot.com/x/repro.syz?x=16200b9e400000 > > C reproducer: https://syzkaller.appspot.com/x/repro.c?x=102311c6400000 > > > > IMPORTANT: if you fix the bug, please add the following tag to the commit: > > Reported-by: syzbot+6d3612ba5e254e387153@syzkaller.appspotmail.com > > > > random: sshd: uninitialized urandom read (32 bytes read) > > ================================================================== > > BUG: KASAN: use-after-free in memcpy include/linux/string.h:345 [inline] > > BUG: KASAN: use-after-free in generic_gcmaes_encrypt+0xc6/0x186 > > arch/x86/crypto/aesni-intel_glue.c:1291 > > Read of size 12 at addr ffff8801d7ad0900 by task kworker/0:1/14 > > > > CPU: 0 PID: 14 Comm: kworker/0:1 Not tainted 4.19.0-rc4+ #228 > > Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS > > Google 01/01/2011 > > Workqueue: pencrypt padata_parallel_worker > > 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 > > check_memory_region_inline mm/kasan/kasan.c:260 [inline] > > check_memory_region+0x13e/0x1b0 mm/kasan/kasan.c:267 > > memcpy+0x23/0x50 mm/kasan/kasan.c:302 > > memcpy include/linux/string.h:345 [inline] > > generic_gcmaes_encrypt+0xc6/0x186 arch/x86/crypto/aesni-intel_glue.c:1291 > > crypto_aead_encrypt include/crypto/aead.h:335 [inline] > > gcmaes_wrapper_encrypt+0x162/0x200 arch/x86/crypto/aesni-intel_glue.c:1127 > > crypto_aead_encrypt include/crypto/aead.h:335 [inline] > > pcrypt_aead_enc+0xcb/0x190 crypto/pcrypt.c:143 > > padata_parallel_worker+0x49d/0x760 kernel/padata.c:86 > > process_one_work+0xc90/0x1b90 kernel/workqueue.c:2153 > > worker_thread+0x17f/0x1390 kernel/workqueue.c:2296 > > kthread+0x35a/0x420 kernel/kthread.c:246 > > ret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:413 > > > > Allocated by task 5474: > > 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 > > kmem_cache_alloc_trace+0x152/0x750 mm/slab.c:3620 > > kmalloc include/linux/slab.h:513 [inline] > > tls_set_sw_offload+0xcc4/0x14b0 net/tls/tls_sw.c:1741 > > do_tls_setsockopt_conf net/tls/tls_main.c:467 [inline] > > do_tls_setsockopt net/tls/tls_main.c:514 [inline] > > tls_setsockopt+0x689/0x770 net/tls/tls_main.c:533 > > sock_common_setsockopt+0x9a/0xe0 net/core/sock.c:3038 > > __sys_setsockopt+0x1ba/0x3c0 net/socket.c:1902 > > __do_sys_setsockopt net/socket.c:1913 [inline] > > __se_sys_setsockopt net/socket.c:1910 [inline] > > __x64_sys_setsockopt+0xbe/0x150 net/socket.c:1910 > > do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290 > > entry_SYSCALL_64_after_hwframe+0x49/0xbe > > > > Freed by task 5472: > > 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 > > tls_sk_proto_close+0x5fd/0x750 net/tls/tls_main.c:277 I'd say tls_sk_proto_close does not handle asynchronous crypto properly. The pcrypt template is used here, so all crypto requests are processed asynchronously. tls_sk_proto_close frees the needed recources before the remaining crypto requests are finalized.