Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4365609rwd; Tue, 23 May 2023 06:55:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Fl92QRjl2Bi9LoF6jPf1BpMsACBjHtcOZ8aVf9gxuGoln5wmLvHcD+z55qpuUlCCbQ0x+ X-Received: by 2002:a17:90a:4598:b0:253:7023:a620 with SMTP id v24-20020a17090a459800b002537023a620mr11463374pjg.35.1684850100539; Tue, 23 May 2023 06:55:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684850100; cv=none; d=google.com; s=arc-20160816; b=oeNEYflqwDIZIBjA5khSUgp1NWbxKvW1SrSXRIToWDG8OdGgKIdDRTlbV5mR4QMD6D VTjrGRnsmAonHVf20nxJQTQ8Q93FWKRMk4qj0V/eE2oOnF+2pGeYPQnKGb7UxwsbfWpj dL76lVKhWYgsW3wRcqHijNr7gKBwwRjIN8l0EKrby9m1f2TuYEQqhB//Rf8x02M4gb0Q TbxV3IPyqPNfOxZfhkxhWgdfyMJsMEm+J5pSeMwm0ErFm7GqZQ5mSC3N8RS26SrHMMCH gw36LxgFBbcDSYbh6OzmB7JTJiuigRZMEWXkAJZh5mfBzuELf0KO3b8GxBzzenqrAx5D Ss2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=cDZfsk20qg+AXLZ027jalzQyFCQIwYMH4M6B0oQN79Q=; b=v3XZ8B9a2oXHcwYcFgE+UBtnagz/qSRYKa8uO9TGhBR91GkW8jmJXkm7PKs10zViMk sFx62ymV9ZjWegFrxiyHDYR1ZO5Ala+L8ItZx5Ji35/xzGVXQuqRN69hhIp4iOjYeeoE fkhM2oObzlhK8xELLzw9nzEfLvX1tk/+rj9DqQq/CGvRYh9Rk0whz/eNep3CLu5g5NTL PNlJB+6BTjIItsrANDFVwL//GPv3Tca9ZFLGpLam7/uTWZlKZ8Ax5anFt6WQr706/SDS XvoZOCIIbRfmWRW4uaQ9gmHiBoU8B0fHNhFy8E5tacar3QjW2W30nL506M3P3DY30YYE gmHA== ARC-Authentication-Results: i=1; mx.google.com; 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=aculab.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fs22-20020a17090af29600b002535ce9f084si6426953pjb.69.2023.05.23.06.54.44; Tue, 23 May 2023 06:55:00 -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; 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=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236702AbjEWNuN convert rfc822-to-8bit (ORCPT + 99 others); Tue, 23 May 2023 09:50:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235087AbjEWNuN (ORCPT ); Tue, 23 May 2023 09:50:13 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A371CA for ; Tue, 23 May 2023 06:50:10 -0700 (PDT) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-182-swcgAvrnOkKU0tujxjiZ0g-1; Tue, 23 May 2023 14:50:03 +0100 X-MC-Unique: swcgAvrnOkKU0tujxjiZ0g-1 Received: from AcuMS.Aculab.com (10.202.163.4) by AcuMS.aculab.com (10.202.163.4) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Tue, 23 May 2023 14:50:01 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Tue, 23 May 2023 14:50:01 +0100 From: David Laight To: 'Jan Kara' , Ted Tso CC: "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 Thread-Topic: [PATCH] ext4: Fix possible corruption when moving a directory with RENAME_EXCHANGE Thread-Index: AQHZjXiOnO+KSeLc6k+5S1Un0bHvlK9n30WA Date: Tue, 23 May 2023 13:50:01 +0000 Message-ID: <48d1f20b2fc1418080c96a1736f6249b@AcuMS.aculab.com> References: <20230523131408.13470-1-jack@suse.cz> In-Reply-To: <20230523131408.13470-1-jack@suse.cz> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,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 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. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)