Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp2186290ybg; Thu, 30 Jul 2020 12:35:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4s+xfFaMmFmP8CZgDYXdq4ZsA2w7PU3MDQvTUhcUaRNFmXOjHXmZOyXT6PtuY19UHoMuj X-Received: by 2002:a17:906:3b83:: with SMTP id u3mr626998ejf.55.1596137745042; Thu, 30 Jul 2020 12:35:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596137745; cv=none; d=google.com; s=arc-20160816; b=cc6D/iEcmUrdlKOBaM/2ouDYf4hxsjLl8Slt1abI3rR3O5yj8sx37z5qbAxi20REYA NtOc1gBYyQFDlf3LPIMxz1yTAdgBeJgOs+/ehALuG5YLMhr6/BkCQLRdVjy6o8RImszt qQ/VvZzNwemljKyf6l9X3mGp9cFjzIuwnChZGi7A21NfRs8/3OCehopI4GYqGsPcjp+r oZE+DA4Upcz+jma4huFP9v+tTGnCptbkO7K4nDovM00Al0Gxtvsa8K9ZMi+6d10OFt6L SbRJ98zKzJbLaI8ySfk8DqxSm5FoBHRlw8QuuNM7Ro0qsuS5+ksgMIBBrYuLeUYN7MvC vsng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:dkim-signature; bh=S2cxBjoQxqxK4peClB1baOHSFoZL+Yj5o/jId09Ervw=; b=rOzDqR56e1+WHQHS+5eTkpbhuqnmxyPa2B44IFFUL1QJHiD8ayVheUz1tnUtWNgYj4 OYSxfdFMX1WJ+0yb0IdVPUStVdvTDgmwsRmk+Gc4OJm9Ncab2U5IsH4/vgODlISIRUGq HCDMJw4f8UPiKw1Pko1jozNzRxnisdriHWlaRPXDoLS843mj+rtFg1IPluO8MZdkgYQO ASTarJnSNCP94H3aqvUa6/iHfym+e3aE3StLPC0U3HQIwOdiboW2YqgoJXIGIVSK7h5F 5kIED8MO12tWSYSkvtPvIAPclXtiPdz+8+qXgrMM0v22Ychr3SVpUjVF43uoYmct2UkV aukw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=yV0lYXoR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j7si3812965ejm.538.2020.07.30.12.35.22; Thu, 30 Jul 2020 12:35:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=yV0lYXoR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730487AbgG3Tes (ORCPT + 99 others); Thu, 30 Jul 2020 15:34:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726853AbgG3Ter (ORCPT ); Thu, 30 Jul 2020 15:34:47 -0400 Received: from mail-io1-xd41.google.com (mail-io1-xd41.google.com [IPv6:2607:f8b0:4864:20::d41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8386CC061574 for ; Thu, 30 Jul 2020 12:34:47 -0700 (PDT) Received: by mail-io1-xd41.google.com with SMTP id d18so29445183ion.0 for ; Thu, 30 Jul 2020 12:34:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=S2cxBjoQxqxK4peClB1baOHSFoZL+Yj5o/jId09Ervw=; b=yV0lYXoR+mqd/SzhhBLEqFe2z/OHz5ZaPxBuVNBV2Bu2Yc+gK98PiKbSSaxOA8fZQJ xPaW6ZYdYndj0dCUQlYGJUyuWi+TkvwoN1//Rt8BUkiJ9Jh0BKYPI+oztdDLbnRz7YeD qsuA7hhHZWiGed5zySaE9JpdPjc6IqaicExOpvsR72LlQVc9PmhSQPavwo/BKSwyZjMi Y5hy8hDT1HknicHEl2VvsRA4nbliyB5Zyz8MdmfFd5guleqQE3myjmV5ZqkYA5V4NXuN zCYfIq2BgDRWoQQ5jgWzaonHRDR7zf0hO/Q/XnNuQqhOFd8s8j4WwK6uMdeq+LBz7cMy QtXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=S2cxBjoQxqxK4peClB1baOHSFoZL+Yj5o/jId09Ervw=; b=ind6N7pg/bj+gx1MkpsrUv0CiQZrjlok9feQHHxEE65IyrWz9GCNZnEJHjBoRtxNIH T680dU7CHrxyiW66kcvN+b0rCbXV3azpn5sXQhpgYgWC1sA7X4u9a/2s58vJZxmYidyC 2LNnuX+PFBDprKr16Ulp0Dj76zYMxTmSD2kN0Qqr5BN9mYHRCsoHd76lfbXu0V1WTzIj QnOl8wnoOKHCNWtDHQj/RzXCaNC5q14SCzIpsQHGxU/y0Avf4RsxwgRqgQXGBTIrX0p6 YAZiAtaHFKWR4G5aX3vdVJKlORrcDQFHEZo7zYM4J4xwk30TB94VA2mhWKIqxQiI1wqw eEpg== X-Gm-Message-State: AOAM53020QRuSwdIuJQm0x/XlpOagA887qHXaj1bioC75OGEHLM5pn2G /uu7VlKFG2aKKw3L6J/A0IGIUQ== X-Received: by 2002:a5e:980f:: with SMTP id s15mr132306ioj.5.1596137686835; Thu, 30 Jul 2020 12:34:46 -0700 (PDT) Received: from [192.168.1.58] ([65.144.74.34]) by smtp.gmail.com with ESMTPSA id 142sm3466284ilc.40.2020.07.30.12.34.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 30 Jul 2020 12:34:46 -0700 (PDT) Subject: Re: KASAN: use-after-free Read in io_uring_setup (2) To: syzbot , io-uring@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, viro@zeniv.linux.org.uk References: <000000000000a3709905abad9335@google.com> From: Jens Axboe Message-ID: Date: Thu, 30 Jul 2020 13:34:45 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <000000000000a3709905abad9335@google.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/30/20 1:21 PM, syzbot wrote: > Hello, > > syzbot found the following issue on: > > HEAD commit: 04b45717 Add linux-next specific files for 20200729 > git tree: linux-next > console output: https://syzkaller.appspot.com/x/log.txt?x=173774b8900000 > kernel config: https://syzkaller.appspot.com/x/.config?x=ec68f65b459f1ed > dashboard link: https://syzkaller.appspot.com/bug?extid=9d46305e76057f30c74e > compiler: gcc (GCC) 10.1.0-syz 20200507 > > Unfortunately, I don't have any reproducer for this issue yet. > > IMPORTANT: if you fix the issue, please add the following tag to the commit: > Reported-by: syzbot+9d46305e76057f30c74e@syzkaller.appspotmail.com > > ================================================================== > BUG: KASAN: use-after-free in io_account_mem fs/io_uring.c:7397 [inline] > BUG: KASAN: use-after-free in io_uring_create fs/io_uring.c:8369 [inline] > BUG: KASAN: use-after-free in io_uring_setup+0x2797/0x2910 fs/io_uring.c:8400 > Read of size 1 at addr ffff888087a41044 by task syz-executor.5/18145 Quick guess would be that the ring is closed in a race before we do the accounting. The below should fix that, by ensuring that we account the memory before we install the fd. diff --git a/fs/io_uring.c b/fs/io_uring.c index fabf0b692384..eb99994de5e2 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -8329,6 +8329,11 @@ static int io_uring_create(unsigned entries, struct io_uring_params *p, ret = -EFAULT; goto err; } + + io_account_mem(ctx, ring_pages(p->sq_entries, p->cq_entries), + ACCT_LOCKED); + ctx->limit_mem = limit_mem; + /* * Install ring fd as the very last thing, so we don't risk someone * having closed it before we finish setup @@ -8338,9 +8343,6 @@ static int io_uring_create(unsigned entries, struct io_uring_params *p, goto err; trace_io_uring_create(ret, ctx, p->sq_entries, p->cq_entries, p->flags); - io_account_mem(ctx, ring_pages(p->sq_entries, p->cq_entries), - ACCT_LOCKED); - ctx->limit_mem = limit_mem; return ret; err: io_ring_ctx_wait_and_kill(ctx); -- Jens Axboe