Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp333866rwr; Thu, 4 May 2023 03:59:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5xJuJk+hoQr2LHkcCsYIytKkEvPss5s/xBi8kZxTgbxY/7k+xPXjt+glqj8Lbc3KR2h/SN X-Received: by 2002:a05:6a00:2e93:b0:63a:8f4c:8be1 with SMTP id fd19-20020a056a002e9300b0063a8f4c8be1mr2011585pfb.10.1683197965533; Thu, 04 May 2023 03:59:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683197965; cv=none; d=google.com; s=arc-20160816; b=S1YMUTFeeYPMRMm/XyYVkvzBUA1UjibQNFuTDng3tCmWf8vJatMWHOa5RXjdne6uoi F0vX+YbdTGdh2oQlOecLS2bVG9dD1H2ZOE4JmmyLvHFinLFq26fPfxTKI7oDDEyAL9gw Kyw8xKqeOUVK+EReoOSx2NN27JFMNzKCSjKC0+DuUaCsN34zsgskjPIucB6IQioQLo05 BAeKUjpkI2YwR1NB+gbsfNkll4Q6lzgF7SG1Ef3pH1lEu/8bE07BjukDZ/bgSchbTEM2 HDVDQ74+x9axAm/hq45zYKr7rLYZmhlLny7mngj6lFEL6+3DikUnRdxk+uc7JA6OoOXd Nbzg== 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 :dkim-signature; bh=4YGkcY/Z/fvObTORyRf7XhotLzUb2DChADXCyEToWUs=; b=ux7XYMNIAKRfYeqKw3LW713IjXpkms2l3WzXCq88qPBp8fK1tj5aEAfk9z5TYwJ9GV psDj1ue7gJ3nkUl7jClDPFHynlbLfMLBfus35RNfTUWHIVp6pxCoYgEHkmV33nBH690F +fJd702R5ESc17FAwM1eyY7XHUxykBmU7P6+0KEJ4zhRsdj25a9TKS7wsmuvt8zuu2mr 4e9vFCL/pOQARlwEPqZMbAVDnKnBszSAC7L/GoLupwRBIdlqWjQaY+mBPpvme5UjIQ9g es0LGZiELyDbY+qRpgtXamUaYScNsKPo+FcaAsWkp8F4k9jEwn1C5JVYL5cfWI55v2JU H2Hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=JXa50Itl; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=TaUfxS5f; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l123-20020a622581000000b0063d232464absi34421832pfl.214.2023.05.04.03.59.04; Thu, 04 May 2023 03:59:25 -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=pass header.i=@suse.cz header.s=susede2_rsa header.b=JXa50Itl; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=TaUfxS5f; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229830AbjEDKue (ORCPT + 99 others); Thu, 4 May 2023 06:50:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229978AbjEDKuc (ORCPT ); Thu, 4 May 2023 06:50:32 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 419EB3C1F for ; Thu, 4 May 2023 03:50:31 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id F3B2320A04; Thu, 4 May 2023 10:50:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1683197430; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=4YGkcY/Z/fvObTORyRf7XhotLzUb2DChADXCyEToWUs=; b=JXa50ItlAYvpJaq5CeaNo++Z9Q4UhCiMcqvp0wkNKibW00VchNgxEiVE8jjfkJxPyhzGPg sj9eqe6tE8bmvPG/j+Zcs39pYyqa5p6g39tVbK8zTZuDcIbiQVBlKHZFdb+NWHThsYt5ok 0H/1xB/oKw+lAUrXuTO4GPzP2vyT+4Q= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1683197430; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=4YGkcY/Z/fvObTORyRf7XhotLzUb2DChADXCyEToWUs=; b=TaUfxS5f+IaqrTGHFFprtMLEFiZvLTcko20Z+v9JkDGTBCrCUOEvNM9Fv0mB/1sgOVv2TA jnhUGz4xNRiQNXBw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id E6DD813444; Thu, 4 May 2023 10:50:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id hiBaOPWNU2TzBgAAMHmgww (envelope-from ); Thu, 04 May 2023 10:50:29 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 79443A0722; Thu, 4 May 2023 12:50:29 +0200 (CEST) Date: Thu, 4 May 2023 12:50:29 +0200 From: Jan Kara To: Theodore Ts'o Cc: Jan Kara , 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: <20230504105029.5sq7p6x3r6h7yjvw@quack3> References: <20230503182128.14115-1-jack@suse.cz> <20230504024157.GB650928@mit.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230504024157.GB650928@mit.edu> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 03-05-23 22:41:57, Theodore Ts'o wrote: > 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? Right, we should do that as well. I'll update the patch. Honza > > 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 -- Jan Kara SUSE Labs, CR