Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1658312rwr; Wed, 3 May 2023 19:57:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ73G1XZLVVDegcGpXIG0BdTBi/DOig+g7Hltm8eI9RpFOCF9O1KfvxILfRt6vOEisxChoHc X-Received: by 2002:a05:6a20:3d13:b0:f0:e8a5:17cc with SMTP id y19-20020a056a203d1300b000f0e8a517ccmr1067229pzi.11.1683169027769; Wed, 03 May 2023 19:57:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683169027; cv=none; d=google.com; s=arc-20160816; b=JybQgGdcq+kbiMFVuL3dWokMoBoseHDBujcTWZPCbD4UIzoycF3+9GD5knrWCug6ng TZHGRT0By0C8Agd632R17MC1V4ZuDClQMG5MCU8cr3ndjHc2+n9tQY7D4+7MIRgwjypW 5kuD3+11V5AquM89KocJn5IAmYdQvWViaIforsjJ1INbZJNZ2NfEHs8lWKKP404FKPAN Frl7e/FaUPVROw9uMKGjcZ8+/Zdoqy/kt8/cbtMo7gKa4iUcm0chy8QiSsxjGx/ndF4H lZcIxCPmCfxUUgXWhSK8BA+5kk6N6GBPzeDL3EteFMnQ+v3yDb2nsVGxlyGEjkp6H32I QNCA== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=eTCuQQB8yacNMzkTzo2O6BZ9pz+ntZF06EuAP3MO3FE=; b=bKcjhmayJEdzUSSQdwQiVaPdSIyhPUvoh6MCuMOFkIToH1XsQnb8UvqZuuQLrCl6i7 mGC6VH81dOIk1wfX+iBW8hcB+KvVBk3QusHmqN6O9R0zrjwaxSj05+Cejh1Kl9xqqVL/ FOSS5Hz+/LQeS/bXt/guTgOOiSBOMsdtIqq+tkljPdCshw8jNe443R+wP8XQNEy+v7Qg ilDM0D3Wvn6TosTsCF9iX3qXhRelpYlQsj+fGKnbIE/oI0Lh3sDv1KlgLL99I4sCYcRe up+RsJFO0FfbAh5/M1NbrbIx06m0DESpsiAgJuXTHHAN9nzwm+Bkh56C7MXMUCzVswe8 xPSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mit.edu header.s=outgoing header.b=joIpqTZO; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mit.edu Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kn14-20020a17090b480e00b00246ba136cc1si14472227pjb.137.2023.05.03.19.56.45; Wed, 03 May 2023 19:57:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@mit.edu header.s=outgoing header.b=joIpqTZO; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mit.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229460AbjEDCmN (ORCPT + 99 others); Wed, 3 May 2023 22:42:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbjEDCmM (ORCPT ); Wed, 3 May 2023 22:42:12 -0400 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7141E42 for ; Wed, 3 May 2023 19:42:10 -0700 (PDT) Received: from cwcc.thunk.org (pool-173-48-120-46.bstnma.fios.verizon.net [173.48.120.46]) (authenticated bits=0) (User authenticated as tytso@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id 3442fwbm011830 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 3 May 2023 22:41:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mit.edu; s=outgoing; t=1683168123; bh=eTCuQQB8yacNMzkTzo2O6BZ9pz+ntZF06EuAP3MO3FE=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=joIpqTZO0iOaq+VVu1pFERnpUALgscJWuyuWUXBw6vwZgCaBb+xbqBQtgXSYm/IhA 85FU4jiL0aebQh98yWEYT7RWSFB2esoQx0dideQF+59GKXQ2m6Sbz5rUbI3WlMOTJg 9rrviasRtv9zJDNlYjN1fdn71W/tEBfnPSTOUqp3U/MeVxu6PA4SBbyKuAct3k2aaI 8M4XFaQBr0JOvHPaadq26lh7bPW4RzuWSmUF6iqKRt7ERtEG7zQsGpCWjVVbEjPnq1 Hxv1tqLXoPQRYiJr9S2mvBjkcnumAALliUvKpq9Gip32L8YyZlbMZkn+Rfwc+L8WIN FVkmmGcwx7e+Q== Received: by cwcc.thunk.org (Postfix, from userid 15806) id D7A6915C02E2; Wed, 3 May 2023 22:41:57 -0400 (EDT) Date: Wed, 3 May 2023 22:41:57 -0400 From: "Theodore Ts'o" To: Jan Kara Cc: linux-ext4@vger.kernel.org, Dmitry Vyukov , syzbot+4a03518df1e31b537066@syzkaller.appspotmail.com Subject: Re: [PATCH] ext4: Fix data races when using cached status extents Message-ID: <20230504024157.GB650928@mit.edu> References: <20230503182128.14115-1-jack@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230503182128.14115-1-jack@suse.cz> X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham 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-ext4@vger.kernel.org On Wed, May 03, 2023 at 08:21:28PM +0200, Jan Kara wrote: > When using cached extent stored in extent status tree in tree->cache_es > another process holding ei->i_es_lock for reading can be racing with us > setting new value of tree->cache_es. If the compiler would decide to > refetch tree->cache_es at an unfortunate moment, it could result in a > bogus in_range() check. Fix the possible race by using READ_ONCE() when > using tree->cache_es only under ei->i_es_lock for reading. > > Reported-by: syzbot+4a03518df1e31b537066@syzkaller.appspotmail.com > Link: https://lore.kernel.org/all/000000000000d3b33905fa0fd4a6@google.com > Suggested-by: Dmitry Vyukov > Signed-off-by: Jan Kara Don't we also need a WRITE_ONCE here? diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c index 7bc221038c6c..4694582cf255 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c @@ -293,7 +293,7 @@ static void __es_find_extent_range(struct inode *inode, } if (es1 && matching_fn(es1)) { - tree->cache_es = es1; + WRITE_ONCE(tree->cache_es, es1); es->es_lblk = es1->es_lblk; es->es_len = es1->es_len; es->es_pblk = es1->es_pblk; - Ted