Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp691828iob; Wed, 18 May 2022 10:43:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcR8Q4mygwv3uoVFdrR9KSrz+aYeDkd/dtW48kXL23c+IFGIMwA6drHWugTYwYpYfy8+Jf X-Received: by 2002:a17:902:830a:b0:161:b926:2c3d with SMTP id bd10-20020a170902830a00b00161b9262c3dmr681494plb.103.1652895830162; Wed, 18 May 2022 10:43:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652895830; cv=none; d=google.com; s=arc-20160816; b=zUzv0i8fMquuh55WR1MtfVB6QKwo+4d3Md+lG2CJ9oWR3DEIWFMg6FSMLMSOOp6h1X +28W+u2gJcAFIiNeT54r57+SS7ltYR8peDPq4f3QgC5D25cJwAjfr/bAt4zrLV/L98rN WyXPVTxv9Zc0rJOJzduoiy8daTWTalL3sUDfI8AdqQxzFpzF9JEd6JTWhiECggMLJKz7 9L99FFDHd59x6BjsKap5wV0KuiyKVxftVzOebk5HSOcQD+Q0ff321oJbLG4/Vm9hm/3W rrBt5/t9/1L0PtLnog7XeRaB/2SRYw2mLhiiMJJCyBt8ytHVi+5PBU+pEcuyIg9kXrFS wCLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=FCjAMF+t6xv+nOgAS8IDF6DMWgTC+Nhvzypvvbrh9wA=; b=yRqcT5vYqt8aHReD7XNwbcsIykbtXkBrPflqtck2WnhyZ3U4LzYRepMb0ahyFpdJ9h ZUhH2/h3wOymd0X+vu3kn6BL6OKa1dgFZMzbCTxoGyErodepbAY6PxM5RJGFfA+SmQWZ tR9ymly4yBeInfgExhUaHodhKyl6bw1iqrAirSX3VevXrulL+RptCdhWN8YimFHSsjlh E/Z4JQKQgIld9lE10MMeEAedt/F7gD84mC8JipfAzHbEk8NFTlkR+AHb9O6Be/NiA9Ji xL6M76bBAo/z0qB/voPwezYpmDDI26KK5Dn7/I4YIbKs9/BgPk8OwVeagV5mUJ0dfsPw 60OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20210112.gappssmtp.com header.s=20210112 header.b=hCjvSXLx; 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 Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id nl18-20020a17090b385200b001df53ffe159si4159090pjb.1.2022.05.18.10.43.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 10:43:50 -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=@kernel-dk.20210112.gappssmtp.com header.s=20210112 header.b=hCjvSXLx; 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 04B5E1F2C07; Wed, 18 May 2022 10:42:43 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241175AbiERRmg (ORCPT + 99 others); Wed, 18 May 2022 13:42:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241059AbiERRmc (ORCPT ); Wed, 18 May 2022 13:42:32 -0400 Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3879019C751 for ; Wed, 18 May 2022 10:42:31 -0700 (PDT) Received: by mail-io1-xd2a.google.com with SMTP id f4so3124197iov.2 for ; Wed, 18 May 2022 10:42:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=FCjAMF+t6xv+nOgAS8IDF6DMWgTC+Nhvzypvvbrh9wA=; b=hCjvSXLxmlAniS/CaWOF1M1d6LOv9BD0qdTUFahO8rcz4Ef3II2Xlw/8KoFY4FygDA aXYIcSQ0UKMl/m+vCwm9AVY6pw82AZ7bFPA4fV6AmYtFjaaFka9N/GjRdP7SS/Nzfz5r rq4Ye1iT2m3dXuSuqoHjQZU4MzMqkb/TigRDiC/Om6iq2ljPNQuRBJGyCgHI5vT+dBIF gwW+uzS0iUBDAABEStAdvjcFNrqqi0bCDFOtMf4XEw63dqi5YEbb9tkAStZkjn1WliRa 4IkPuZmaWy/jUNPU6ve2/l8zXZKn1qYsRjYXrMK5MX+6FlhmtZX2hfy09gKhOnKiL/KR sa+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=FCjAMF+t6xv+nOgAS8IDF6DMWgTC+Nhvzypvvbrh9wA=; b=S2zUrA9ldAXI9DfTN4S/uxEiFapagqEwg3loY3w5NfyWychxnDJIElwtLHlRe+9z0D IXXn1zGxVMbWHXXvs8mIIXs1wCU0QKlU73wnitFudFEhohhriz3ldF1SToHwUJ6y+HsP Iqk8FSd+/QDZwNRzxlZmEVeORe+JbylckRHL/8A1NLAeIB575af0jMZ/STQvL43kxRIc 30U2ro6isQspoedkcvHDB44C1TSZi22TEVATafvef8zzpodTyLn+hy90vBCdZMbz1kCf MiM447UGbMcCujZeKEgxRhM9sIa3gDrK9dXU8tpJfr3omN+pyzaAeJUaFtZxNBXpb9lU k8ZQ== X-Gm-Message-State: AOAM532n63Y2wUmSJm1GHv1A5AblBh44oLahGj+n6MOqEsPIBESRozA5 bt6nuP2rsAce6wt/OGclEnpX2g== X-Received: by 2002:a05:6638:34a4:b0:32b:b205:ca82 with SMTP id t36-20020a05663834a400b0032bb205ca82mr353129jal.165.1652895750485; Wed, 18 May 2022 10:42:30 -0700 (PDT) Received: from [192.168.1.172] ([207.135.234.126]) by smtp.gmail.com with ESMTPSA id r23-20020a6b5d17000000b006050cababc5sm54076iob.0.2022.05.18.10.42.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 May 2022 10:42:29 -0700 (PDT) Message-ID: <38f63cda-b208-0d83-6aec-25115bd1c021@kernel.dk> Date: Wed, 18 May 2022 11:42:28 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: Re: [REPORT] Use-after-free Read in __fdget_raw in v5.10.y Content-Language: en-US To: Lee Jones Cc: Pavel Begunkov , io-uring@vger.kernel.org, linux-kernel@vger.kernel.org References: <06710b30-fec8-b593-3af4-1318515b41d8@kernel.dk> <49609b89-f2f0-44b3-d732-dfcb4f73cee1@kernel.dk> <1e64d20a-42cc-31cd-0fd8-2718dd8b1f31@kernel.dk> From: Jens Axboe In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 5/18/22 10:34 AM, Lee Jones wrote: > 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 Ah ok - I don't think that's needed for this. Looking a bit deeper at this, I'm now convinced your bisect went off the rails at some point. Probably because this can be timing specific. Can you try with this patch? diff --git a/fs/io_uring.c b/fs/io_uring.c index 4330603eae35..3ecf71151fb1 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -4252,12 +4252,8 @@ static int io_statx(struct io_kiocb *req, bool force_nonblock) struct io_statx *ctx = &req->statx; int ret; - if (force_nonblock) { - /* only need file table for an actual valid fd */ - if (ctx->dfd == -1 || ctx->dfd == AT_FDCWD) - req->flags |= REQ_F_NO_FILE_TABLE; + if (force_nonblock) return -EAGAIN; - } ret = do_statx(ctx->dfd, ctx->filename, ctx->flags, ctx->mask, ctx->buffer); -- Jens Axboe