Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3320280rwd; Mon, 29 May 2023 08:42:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7CbSwdSEqFi3irVDxg3B0A+1XOwu7+UmbpyXGbTGLJ5E27PsWB5Tf6wziPB0JrjiEICbjv X-Received: by 2002:a17:903:41d0:b0:1b0:e0a:b7ab with SMTP id u16-20020a17090341d000b001b00e0ab7abmr13058235ple.31.1685374940602; Mon, 29 May 2023 08:42:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685374940; cv=none; d=google.com; s=arc-20160816; b=HbWHRSLaXe+qYYbU45usE6AahRHFwenb8jMSStG2UulGUMtta5+wSZ8argNHPZ69un Ge8S5W8HPQeFTS8YkG5BYvzJwDRwYnS33TFb8U0E2E7X8OP1CdW7d3HWypCOKI0TWuHa qxYJS4L8m9PkIiZ3WEQMEwX2zo3spgHLnfnuz2KBYVij2M/M7FZC9tHv8QD9mOnpjJUz X5zdB8JyQ5Srsp+dwJ17UV5a5BgxNmxq/MHtAFAxcFFAYVQPew/mQP5DFyX2Mvw4GpVL tnZ5RYrKZr4bMZIi60AjUpozHo4ViTaQRHQt4aovr5KOtgz+vxBFnuB5GLIkXtz2alD3 fBHw== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:dkim-signature; bh=5x//7WihZJHP1ybBvKd6Troh9+7buiiSd3Ne59BgSEw=; b=XJuxPukUySp2NpqeZppzkLC6ZXwaFCE3sirQG5e5iLNTbGsl90FPqvX6DuHt9ilCiB b2BFlKMk4xj6dpUpnAjfDVKvwPcKkWYILHY5lMsFt6KVO9usWVz67LB1R+L7XQqpj8YB c4ggm2Jbm9hfQHKTpXdJ7Xf+MOpNDaCt6EEShVa8/C0d6/uLkZwhBbi2epouiUJx0WBm 9gphNvhpREd2i3AMXwY61X4Eyv881dAw4Z0acQ5kvIUX9Y26i4nS4otryMShm89/SpI0 9hewZlOUafLgLEhG6p/RIW5FfxD1jt6eGJFf+3ZQcZJgDErkvO5jP/Ix1AaeSc9yChLv SA8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=fSpO7ae3; dkim=neutral (no key) header.i=@suse.cz; 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 r3-20020a170902be0300b001ae014d8d03si7806315pls.432.2023.05.29.08.42.04; Mon, 29 May 2023 08:42:20 -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=fSpO7ae3; dkim=neutral (no key) header.i=@suse.cz; 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 S229875AbjE2PiC (ORCPT + 99 others); Mon, 29 May 2023 11:38:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229735AbjE2PiB (ORCPT ); Mon, 29 May 2023 11:38:01 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED9FBF0; Mon, 29 May 2023 08:37:55 -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 A13CB1F8B0; Mon, 29 May 2023 15:37:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1685374674; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5x//7WihZJHP1ybBvKd6Troh9+7buiiSd3Ne59BgSEw=; b=fSpO7ae3VdnMdXRDt9Y0DgiDJbH0T7K3W5P4bBRjL+L/BxE+bLD+2Csqqs4Aw9c6ncV85s //0FCpp9/c45UE4B1CzxbNvvJkhIf+47hE8Zdcfv1+N31NNgr2rY+PEBH/9d3SQVwoD+2I JS1f4SwRyENJ/I6HnI4mWulU1S2DJZs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1685374674; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5x//7WihZJHP1ybBvKd6Troh9+7buiiSd3Ne59BgSEw=; b=lf3ZWecKucEDCJ60SKDHz/Mb7QuqwTjJgxmnrSoFrZFJtwpPVPzhebfnSEeyqO4LZ5J5MO gnAzWelT/f/35kCA== 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 81ACD13466; Mon, 29 May 2023 15:37:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id nRcSH9LGdGQmSAAAMHmgww (envelope-from ); Mon, 29 May 2023 15:37:54 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id E43C8A0717; Mon, 29 May 2023 14:42:08 +0200 (CEST) Date: Mon, 29 May 2023 14:42:08 +0200 From: Jan Kara To: Amir Goldstein Cc: Jan Kara , Al Viro , linux-fsdevel@vger.kernel.org, Christian Brauner , Miklos Szeredi , "Darrick J. Wong" , Ted Tso , Jaegeuk Kim , linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-xfs@vger.kernel.org Subject: Re: [PATCH 6/6] fs: Restrict lock_two_nondirectories() to non-directory inodes Message-ID: <20230529124208.2oou7jt3iitwxk4v@quack3> References: <20230525100654.15069-1-jack@suse.cz> <20230525101624.15814-6-jack@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_SOFTFAIL,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 Fri 26-05-23 15:13:06, Amir Goldstein wrote: > On Thu, May 25, 2023 at 1:17 PM Jan Kara wrote: > > > > Currently lock_two_nondirectories() is skipping any passed directories. > > After vfs_rename() uses lock_two_inodes(), all the remaining four users > > of this function pass only regular files to it. So drop the somewhat > > unusual "skip directory" logic and instead warn if anybody passes > > directory to it. This also allows us to use lock_two_inodes() in > > lock_two_nondirectories() to concentrate the lock ordering logic in less > > places. > > > > Signed-off-by: Jan Kara > > --- > > fs/inode.c | 12 ++++-------- > > 1 file changed, 4 insertions(+), 8 deletions(-) > > > > diff --git a/fs/inode.c b/fs/inode.c > > index 2015fa50d34a..accf5125a049 100644 > > --- a/fs/inode.c > > +++ b/fs/inode.c > > @@ -1140,7 +1140,7 @@ void lock_two_inodes(struct inode *inode1, struct inode *inode2, > > /** > > * lock_two_nondirectories - take two i_mutexes on non-directory objects > > * > > - * Lock any non-NULL argument that is not a directory. > > + * Lock any non-NULL argument. Passed objects must not be directories. > > * Zero, one or two objects may be locked by this function. > > * > > * @inode1: first inode to lock > > @@ -1148,13 +1148,9 @@ void lock_two_inodes(struct inode *inode1, struct inode *inode2, > > */ > > void lock_two_nondirectories(struct inode *inode1, struct inode *inode2) > > { > > - if (inode1 > inode2) > > - swap(inode1, inode2); > > - > > - if (inode1 && !S_ISDIR(inode1->i_mode)) > > - inode_lock(inode1); > > - if (inode2 && !S_ISDIR(inode2->i_mode) && inode2 != inode1) > > - inode_lock_nested(inode2, I_MUTEX_NONDIR2); > > + WARN_ON_ONCE(S_ISDIR(inode1->i_mode)); > > + WARN_ON_ONCE(S_ISDIR(inode2->i_mode)); > > + lock_two_inodes(inode1, inode2, I_MUTEX_NORMAL, I_MUTEX_NONDIR2); > > } > > EXPORT_SYMBOL(lock_two_nondirectories); > > > > Need the same treatment to unlock_two_nondirectories() because now if > someone does pass a directory they will get a warning but also a leaked lock. Yes, probably that is good defensive programming. I'll update the patch. Honza -- Jan Kara SUSE Labs, CR