Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp638736iob; Wed, 18 May 2022 09:37:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycnRcTPKlBZ1yUjgutKcd+bEdbTPvXdRVMCvG8/LVufScPOyNuc2WdhcfLr+43drbQ5etk X-Received: by 2002:a05:6a00:ad0:b0:4e1:2d96:2ab0 with SMTP id c16-20020a056a000ad000b004e12d962ab0mr432816pfl.3.1652891829695; Wed, 18 May 2022 09:37:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652891829; cv=none; d=google.com; s=arc-20160816; b=vW9r5+RsJo6APvrUqqLXngMxm5na9ZLketjxfWmYloJf6X96f1UMe/B/74qRIQ8qnT qD/3MR42PGaJfzNlSXsrPyuYfYo81GTVntu4D9jEC9izmscGuM5zlFzC7CSOVvQk5kgA INlio5+t1T/QVXrXNBYk0v6WHHyrfPlDefI+MYRKnoCVD20E+XWCyLcxMpGWa4DIBITk eu1jsfCJ4y+wfn6MQbEIzdSQWgMmPfBWrDV8ko6S0lfVJIqsIPph5n8+TID6REzKTDwW Gh9PLQG8QO0cJe98rUCFexKcOSYP8/cldO1oR8y1EJXwDsEJsgP7E3wIg87syK2eBXVU yxzw== 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=xAOohEZien8Q5pI9ff0to291LHxkqtD9uRCi4y7JwVU=; b=vOSguWApJ9cWS6c45RrQO25tZUT2wuOd9eNWwRqV1f499VeSCoMDRggSjp4o3A02ex dcFNTiOLcz0MPt8F2+oPgkp/jR8d7gg27I/1UfsAiDNTwA9tfoDR8TaeYYZcDobh3f9Q s+itZ13cxCShGDb4h85lSonejvDrthGpILufSMDQDPOb7SN6MlefikGJfHG1GmS94eiG eWIwB+f2rmsG8oLTBz/bArSh6ngY2DXcTsAnDYst21KKYx77ZcYsGlKWeV1Mk/0uWGED kNUXcYIYYXSdUGAePqryx7Q0QNgqJFIGyBkP2NfNcpmFy8wa2+uhwrvs/xItSSpJPcwq jIaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vNYoWpUD; 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 b131-20020a633489000000b0039908cd4e78si3193542pga.263.2022.05.18.09.37.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 09:37:09 -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=vNYoWpUD; 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 45F281F90FA; Wed, 18 May 2022 09:34:52 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240324AbiERQeq (ORCPT + 99 others); Wed, 18 May 2022 12:34:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240208AbiERQen (ORCPT ); Wed, 18 May 2022 12:34:43 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 458631B776D for ; Wed, 18 May 2022 09:34:42 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id j24so3495224wrb.1 for ; Wed, 18 May 2022 09:34:42 -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=xAOohEZien8Q5pI9ff0to291LHxkqtD9uRCi4y7JwVU=; b=vNYoWpUDGiiAOtTCwXgIZEAeloWS0FuvvM/74rLIV0eQuZm/F9YQXomV2qYCiDxnho AMG5/iE4kmp/Z9zWoud0T0tuvVmkJE31v6zDIe9t/ANQ1tsYoCV1Rgc3Yo+lC4nqfagt GU/GAhbGxtVCpYvk4EzSCyir6wPpqhznqLM3etWq96wDvoO/EngdC2E0VoEBp0WuWrCN qUbq3fyVSDnTLd3NWws/taceGgDr05YNQy7UXlo3N7bALFHJSZTv++QBgF003akgUVug ciWUNkjMlubZh1YX6+dnvFhwP08Q8X/QAM5nv8aq2xt9VhKCv1cicqQYFWGCBjgQpalK EDCg== 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=xAOohEZien8Q5pI9ff0to291LHxkqtD9uRCi4y7JwVU=; b=e1NX282C9NNxOEe1TCwo2Js6F2aW7HKHkLpTbqaaYn+oxWkhSHC2luHrKGu7WZ6brB ANnjl51o5hw53exPXV0j9sMl5s3g5DI/yDa0jb4g9C027U7hcRnmxO/EFs1JpIrBR/yl UReEtF5J6TN73KDQ4Vngnq1yfK1KXS9YRuB7Q38bE+lRIpk50cqwgFHNF8hYUjPTk8a6 m42GV1VK1/nAjZnO3s4ZCTIrJEnwPaYPHivh6rOD7PmXzc5DyhIL/gPG3Pru7ywFvujF Up3ahi60CBVB5890WqdQMeyH0vUybE1gd9h9tqfAbKx2Bg73iN54V1ld3/CwE+qZDXdU iyBA== X-Gm-Message-State: AOAM533s+yF0v0g+2jsqYmmWlQxZqbpF23r3G3Lj6W2u2ShJs1fd2VRg 8IqdDU9npRIAmIJgPTP7J8f7mg== X-Received: by 2002:a05:6000:1866:b0:20d:2834:5155 with SMTP id d6-20020a056000186600b0020d28345155mr459637wri.101.1652891680807; Wed, 18 May 2022 09:34:40 -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 j10-20020adfa78a000000b0020c5253d8fcsm2836584wrc.72.2022.05.18.09.34.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 09:34:40 -0700 (PDT) Date: Wed, 18 May 2022 17:34:38 +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: <06710b30-fec8-b593-3af4-1318515b41d8@kernel.dk> <49609b89-f2f0-44b3-d732-dfcb4f73cee1@kernel.dk> <1e64d20a-42cc-31cd-0fd8-2718dd8b1f31@kernel.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1e64d20a-42cc-31cd-0fd8-2718dd8b1f31@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 09:39, Lee Jones wrote: > > On Wed, 18 May 2022, Jens Axboe wrote: > > > >> On 5/18/22 9:14 AM, Lee Jones wrote: > >>> 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. > >> > >> Alright, maybe it's not enough. I can't get your reproducer to crash, > >> unfortunately. I'll try on a different box. > > > > You need to have fuzzing and kasan enabled. > > I do have kasan enabled. What's fuzzing? CONFIG_KCOV -- Lee Jones [李琼斯] Principal Technical Lead - Developer Services Linaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog