Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp574365iob; Wed, 18 May 2022 08:19:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMlgmxFOIZiXRDLP6yYDWSkYfjKIO5Tcg7x3m70ns+MoyJe/iI6YdzoHXmeMfJ8zblq1Ma X-Received: by 2002:a17:902:d510:b0:15e:afc4:85a0 with SMTP id b16-20020a170902d51000b0015eafc485a0mr130680plg.64.1652887194270; Wed, 18 May 2022 08:19:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652887194; cv=none; d=google.com; s=arc-20160816; b=iXqwD748eNd4aXSlIXybF9DS5/YlNwMuWhgvNhGCAKpgm6Dw2VZ9TtgDwlQ/Dh2dUU rPtnNE/c8aeO0+uM5e9nAnKCd1guzEN4Hsfdhj0H8AQA+Tpaw3puIG/LLhJc7sWvotyi WVRv6xzneWxLyj5jcJvkQPCQ/pxhbPJHyBmtS1Sck7Wja76sQPl5NANVeRtJtzNGF8qF 68WSFTL91f5vJt+0YFNoyprae147sUzJT4YbKkFZ+2gatv5YSiTbTRb79u42SrmEhNxU 427Acs+Dr3rSBHuZavXvtHsdaLyTeqyAV4h8QX7gt1OXU92IiHZvcMpUurdgsptaxxAb f0cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=+LQogaNeLDAS97QlCWLMJmUyFddvKMyNGiPi+yDq2F0=; b=lAGPNci7nqExtlEcjlabuP67MkTjwX1QOC2nNV/ZGDs5K/knIZZkQcrGxoed1YPD9q 0MOgtVCj5cQARnnLBkCwW7kjT44UrkflJwkflDhXjkXb0zNkBhDHrmjQTwfr9okzkIz+ IJp6JoOhtVlI/HMqDF00of5ua2AwPi2LqCQC/0/M9Lo3Qx8kp52uBpNGU4UJ6zmlqt9b rkU/5B8LUOKHnk5PejGwyekAXaCyqS4fEAAiotVk+pG/sJdnqEBFqdm1OMvB1O4ptcID KIJv2pocV3xsnSDE+8juUrjmWfQCMnTk0TnmeschdeJijU4H54bDARcOz59rTaNSflU6 KL8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=n5xi3tHd; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id c18-20020a17090a8d1200b001bd14e01f27si5920837pjo.21.2022.05.18.08.19.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 08:19:54 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=n5xi3tHd; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 336AB205DF; Wed, 18 May 2022 08:16:15 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239219AbiERPQH (ORCPT + 99 others); Wed, 18 May 2022 11:16:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239241AbiERPOP (ORCPT ); Wed, 18 May 2022 11:14:15 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 319B11E0102 for ; Wed, 18 May 2022 08:14:14 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id e28so2565043wra.10 for ; Wed, 18 May 2022 08:14:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=+LQogaNeLDAS97QlCWLMJmUyFddvKMyNGiPi+yDq2F0=; b=n5xi3tHdutaDh9rrQj2apRUFkB6OjbZliJwoJ7XQIWlnrUW5F05sPh42Hwf1rzAIuW DrAS9zX6HFAMvX6Iy2qQj8RQx9k5H32X8iai7ZKcAcuWhfLvCaYYxA0g9D4o9/mtRHub 6DsUvK8S7vdORqiMsNa/FGE1H6kw9smloxYwFWsCd2WC8dwdmD8UZAmRJtlnvLjX6hLd U5fn3xRN5vF0bf39UvDCNgWWAE6WGFRVrsmLd+ClR1EFvgI1x5rta1xjKDpuWSB+GXHE nRmsIj+MddXNS9FoJs3cMF39J982LzjbOixh+vpd1ckXvAVBjBY6c/02qwpkoX2VpOvg /q3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=+LQogaNeLDAS97QlCWLMJmUyFddvKMyNGiPi+yDq2F0=; b=Sf7iTjSsWlX5kYbpgSlagErFpJZGWROoswScN6BuPpGVmsty/mlq3nWM0Yl++EnJw6 0MSbyMEoQHJO9tLOr/uUpq4+h/5DLZoJNP/q9fKtHe2Oww6eUJflxaW+7CT5BjeNRa1X 7lxEatSGQKbOtn2JnYjwTgyu8lK6EdG1DTa+Z6FnMI4C0oouXGiDJ22Q/lrdifvPrLYk kFyBqhFtqYYHPqCafqDy9NkgkcRxsicx22nShKxNP3gIn5yigwkLDahPQ4pYYNzNWUZM OKOILIamW9ttRStDgURk55CIbH7ueJtspY20RavgMUAGFP04lTfJD13pTEnO6qzDEpm1 26KQ== X-Gm-Message-State: AOAM530zz1xI/V3hCU4A8okZF9fnms5AdJ48GbrSRBGalKBplEHBZooa 6yLnpeewuBtqCkVx7L+TswF/Bg== X-Received: by 2002:a5d:620f:0:b0:20c:c1ba:cf8e with SMTP id y15-20020a5d620f000000b0020cc1bacf8emr163475wru.426.1652886852771; Wed, 18 May 2022 08:14:12 -0700 (PDT) Received: from google.com (cpc155339-bagu17-2-0-cust87.1-3.cable.virginm.net. [86.27.177.88]) by smtp.gmail.com with ESMTPSA id p11-20020a5d59ab000000b0020e615bab7bsm2127288wrr.7.2022.05.18.08.14.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 08:14:12 -0700 (PDT) Date: Wed, 18 May 2022 16:14:10 +0100 From: Lee Jones To: Jens Axboe Cc: Pavel Begunkov , io-uring@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [REPORT] Use-after-free Read in __fdget_raw in v5.10.y Message-ID: References: <3d271554-9ddc-07ad-3ff8-30aba31f8bf2@kernel.dk> <06710b30-fec8-b593-3af4-1318515b41d8@kernel.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <06710b30-fec8-b593-3af4-1318515b41d8@kernel.dk> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 18 May 2022, Jens Axboe wrote: > On 5/18/22 6:54 AM, Jens Axboe wrote: > > On 5/18/22 6:52 AM, Jens Axboe wrote: > >> On 5/18/22 6:50 AM, Lee Jones wrote: > >>> On Tue, 17 May 2022, Jens Axboe wrote: > >>> > >>>> On 5/17/22 7:00 AM, Lee Jones wrote: > >>>>> On Tue, 17 May 2022, Jens Axboe wrote: > >>>>> > >>>>>> On 5/17/22 6:36 AM, Lee Jones wrote: > >>>>>>> On Tue, 17 May 2022, Jens Axboe wrote: > >>>>>>> > >>>>>>>> On 5/17/22 6:24 AM, Lee Jones wrote: > >>>>>>>>> On Tue, 17 May 2022, Jens Axboe wrote: > >>>>>>>>> > >>>>>>>>>> On 5/17/22 5:41 AM, Lee Jones wrote: > >>>>>>>>>>> Good afternoon Jens, Pavel, et al., > >>>>>>>>>>> > >>>>>>>>>>> Not sure if you are presently aware, but there appears to be a > >>>>>>>>>>> use-after-free issue affecting the io_uring worker driver (fs/io-wq.c) > >>>>>>>>>>> in Stable v5.10.y. > >>>>>>>>>>> > >>>>>>>>>>> The full sysbot report can be seen below [0]. > >>>>>>>>>>> > >>>>>>>>>>> The C-reproducer has been placed below that [1]. > >>>>>>>>>>> > >>>>>>>>>>> I had great success running this reproducer in an infinite loop. > >>>>>>>>>>> > >>>>>>>>>>> My colleague reverse-bisected the fixing commit to: > >>>>>>>>>>> > >>>>>>>>>>> commit fb3a1f6c745ccd896afadf6e2d6f073e871d38ba > >>>>>>>>>>> Author: Jens Axboe > >>>>>>>>>>> Date: Fri Feb 26 09:47:20 2021 -0700 > >>>>>>>>>>> > >>>>>>>>>>> io-wq: have manager wait for all workers to exit > >>>>>>>>>>> > >>>>>>>>>>> Instead of having to wait separately on workers and manager, just have > >>>>>>>>>>> the manager wait on the workers. We use an atomic_t for the reference > >>>>>>>>>>> here, as we need to start at 0 and allow increment from that. Since the > >>>>>>>>>>> number of workers is naturally capped by the allowed nr of processes, > >>>>>>>>>>> and that uses an int, there is no risk of overflow. > >>>>>>>>>>> > >>>>>>>>>>> Signed-off-by: Jens Axboe > >>>>>>>>>>> > >>>>>>>>>>> fs/io-wq.c | 30 ++++++++++++++++++++++-------- > >>>>>>>>>>> 1 file changed, 22 insertions(+), 8 deletions(-) > >>>>>>>>>> > >>>>>>>>>> Does this fix it: > >>>>>>>>>> > >>>>>>>>>> commit 886d0137f104a440d9dfa1d16efc1db06c9a2c02 > >>>>>>>>>> Author: Jens Axboe > >>>>>>>>>> Date: Fri Mar 5 12:59:30 2021 -0700 > >>>>>>>>>> > >>>>>>>>>> io-wq: fix race in freeing 'wq' and worker access > >>>>>>>>>> > >>>>>>>>>> Looks like it didn't make it into 5.10-stable, but we can certainly > >>>>>>>>>> rectify that. > >>>>>>>>> > >>>>>>>>> Thanks for your quick response Jens. > >>>>>>>>> > >>>>>>>>> This patch doesn't apply cleanly to v5.10.y. > >>>>>>>> > >>>>>>>> This is probably why it never made it into 5.10-stable :-/ > >>>>>>> > >>>>>>> Right. It doesn't apply at all unfortunately. > >>>>>>> > >>>>>>>>> I'll have a go at back-porting it. Please bear with me. > >>>>>>>> > >>>>>>>> Let me know if you into issues with that and I can help out. > >>>>>>> > >>>>>>> I think the dependency list is too big. > >>>>>>> > >>>>>>> Too much has changed that was never back-ported. > >>>>>>> > >>>>>>> Actually the list of patches pertaining to fs/io-wq.c alone isn't so > >>>>>>> bad, I did start to back-port them all but some of the big ones have > >>>>>>> fs/io_uring.c changes incorporated and that list is huge (256 patches > >>>>>>> from v5.10 to the fixing patch mentioned above). > >>>>>> > >>>>>> The problem is that 5.12 went to the new worker setup, and this patch > >>>>>> landed after that even though it also applies to the pre-native workers. > >>>>>> Hence the dependency chain isn't really as long as it seems, probably > >>>>>> just a few patches backporting the change references and completions. > >>>>>> > >>>>>> I'll take a look this afternoon. > >>>>> > >>>>> Thanks Jens. I really appreciate it. > >>>> > >>>> Can you see if this helps? Untested... > >>> > >>> What base does this apply against please? > >>> > >>> I tried Mainline and v5.10.116 and both failed. > >> > >> It's against 5.10.116, so that's puzzling. Let me double check I sent > >> the right one... > > > > Looks like I sent the one from the wrong directory, sorry about that. > > This one should be better: > > Nope, both are the right one. Maybe your mailer is mangling the patch? > I'll attach it gzip'ed here in case that helps. Okay, that applied, thanks. Unfortunately, I am still able to crash the kernel in the same way. -- Lee Jones [李琼斯] Principal Technical Lead - Developer Services Linaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog