Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5581400rwd; Wed, 24 May 2023 04:06:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ76hd7w6om6KcUtMh+g+k9EXqGWt/qpsO8lvMrrfLQO4hlEzSQykZFMv/MT4iQaWxkm5mDe X-Received: by 2002:a17:90b:160e:b0:253:4f8f:52fb with SMTP id la14-20020a17090b160e00b002534f8f52fbmr23705184pjb.10.1684926362185; Wed, 24 May 2023 04:06:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684926362; cv=none; d=google.com; s=arc-20160816; b=TMwVVzXXYjcEyuCnIfew89XOu+B2d5itY0e4OYd4ZvDZ0cGR74XndE79Z2ANS0kTKi lIsV3Xiw56EagaoDpw4Eo/Yem5p1VAR0gbhqVyuacffvoPOOoDaDEjUq43zdF1xP5swU wxJt97fF/1uIxG8V9BYTjDNb+ksRBWZGpyxxGESUw8bcS5oMWvVqLulGTpVzgNxyhCmH DoLOUFYdHYc8Xs7tCY8a2f2LutXoK5YawFzqPibTvnmhMYM5tJaMULRs/V3ZcHXxxXM3 7IUhs6g6vFxbyu2XBBRHWywAgC03PYvJUbui9KJfVKJ+ocJbsEhpW+DQ+fsnWdWoFFxZ +gBw== 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=iw9TySelXxG3UNCA0k4qVCUSDYtKU/y5xgxNuohqpQI=; b=m+DRL30fs/JDGMBjHbmp6xsaw+Ed6MNkb2A562qANnpnFK1q76CSLZWsdPC0JiqYQ5 KAxEVv7cACvLcyI08H9aQsDdZoYO/ywQr0KLWH2l5LnewobU5nqn2OVOLfpJXEzrKZCv PYR6lattRPmTpQXOSAUIY8GvYnvUnoo6vt6n7jqAACNMeLGt8wbTAWwTxOn53o3dSJq0 KTb4s+5vrSpp3e01yaoGmWlQ8q+LFyav8MeaxRZEza7gnNp4T7/1s2jOSElHzCKDluUy cfCwCBQM4k/l7ayFLrf3+29Z5PsVhSLXVwoXPSLboNrraSBfAZHT0ETSv+Zar7o3mupw 2nmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=1gsfTUyF; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; 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 s22-20020a17090aa11600b00252b824d13esi1161949pjp.30.2023.05.24.04.05.48; Wed, 24 May 2023 04:06:02 -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=1gsfTUyF; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; 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 S229778AbjEXKvw (ORCPT + 99 others); Wed, 24 May 2023 06:51:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229660AbjEXKvv (ORCPT ); Wed, 24 May 2023 06:51:51 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB4E4A3; Wed, 24 May 2023 03:51:50 -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-out1.suse.de (Postfix) with ESMTPS id 71E0E22189; Wed, 24 May 2023 10:51:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1684925509; 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=iw9TySelXxG3UNCA0k4qVCUSDYtKU/y5xgxNuohqpQI=; b=1gsfTUyFhZ6FyaAWvaU+Duwu5Dy4snvZ5S1smNUTz8WvTyGZMZZVSF+NdOyv/2lbdqIL/h 8yab/x42Bve6tnWzm0m/2u9UmBxqQCXC0yQg1C8c1fmOBSbo8Iio3Emsq05lUAuTL3JU/L 2iz1JkFkFdcBILWI7Z3d/hQxpACkvlo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1684925509; 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=iw9TySelXxG3UNCA0k4qVCUSDYtKU/y5xgxNuohqpQI=; b=+stSb6idZWgRZZzzph8kBjCng2hffY32yActJ2X99htdkg57j2ykTv8Zdx1DCI/6KUVnF7 aMwS3+xmLQCD8GCg== 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 633BF133E6; Wed, 24 May 2023 10:51:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id KIkpGEXsbWQ0MAAAMHmgww (envelope-from ); Wed, 24 May 2023 10:51:49 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id E2A99A075C; Wed, 24 May 2023 12:51:48 +0200 (CEST) Date: Wed, 24 May 2023 12:51:48 +0200 From: Jan Kara To: David Laight Cc: 'Jan Kara' , Ted Tso , "linux-ext4@vger.kernel.org" , "Darrick J. Wong" , "stable@vger.kernel.org" Subject: Re: [PATCH] ext4: Fix possible corruption when moving a directory with RENAME_EXCHANGE Message-ID: <20230524105148.wgjj7ayrbeol6cdx@quack3> References: <20230523131408.13470-1-jack@suse.cz> <48d1f20b2fc1418080c96a1736f6249b@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <48d1f20b2fc1418080c96a1736f6249b@AcuMS.aculab.com> 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 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 Tue 23-05-23 13:50:01, David Laight wrote: > From: Jan Kara > > Sent: 23 May 2023 14:14 > > > > Commit 0813299c586b ("ext4: Fix possible corruption when moving a > > directory") forgot that handling of RENAME_EXCHANGE renames needs the > > protection of inode lock when changing directory parents for moved > > directories. Add proper locking for that case as well. > > > > CC: stable@vger.kernel.org > > Fixes: 0813299c586b ("ext4: Fix possible corruption when moving a directory") > > Reported-by: "Darrick J. Wong" > > Signed-off-by: Jan Kara > > --- > > fs/ext4/namei.c | 23 +++++++++++++++++++++-- > > 1 file changed, 21 insertions(+), 2 deletions(-) > > > > diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c > > index 45b579805c95..b91abea1c781 100644 > > --- a/fs/ext4/namei.c > > +++ b/fs/ext4/namei.c > > @@ -4083,10 +4083,25 @@ static int ext4_cross_rename(struct inode *old_dir, struct dentry *old_dentry, > > if (retval) > > return retval; > > > > + /* > > + * We need to protect against old.inode and new.inode directory getting > > + * converted from inline directory format into a normal one. The lock > > + * ordering does not matter here as old and new are guaranteed to be > > + * incomparable in the directory hierarchy. > > + */ > > + if (S_ISDIR(old.inode->i_mode)) > > + inode_lock(old.inode); > > + if (S_ISDIR(new.inode->i_mode)) > > + inode_lock_nested(new.inode, I_MUTEX_NONDIR2); > > + > > What happens if there is another concurrent rename from new.inode > to old.inode? > That will try to acquire the locks in the other order. That is not really possible because these two renames cannot happen in parallel due to VFS locking - either old & new share parent which is locked by VFS (so there cannot be another rename in that directory) or they have different parents which are also locked by VFS (so again it is not possible to race with another rename in these two dirs). Honza -- Jan Kara SUSE Labs, CR