Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp569332rwd; Thu, 1 Jun 2023 04:07:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ51eJcW+AI6T/o4c9Gi1ZndNIuC1HXpzTrhphwcLVwG0AAhiD7xkPz2gRBHEPWx79wbREo3 X-Received: by 2002:a17:903:48d:b0:1ac:7345:f254 with SMTP id jj13-20020a170903048d00b001ac7345f254mr7184567plb.33.1685617679161; Thu, 01 Jun 2023 04:07:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685617679; cv=none; d=google.com; s=arc-20160816; b=M+c9I0thKJivFhBDiT2idqKbThMw7Nz46VZpNLVmoAijqdUd3By1TBwUooE39bnuzM EAQWNotv5Ryq4bSeWmOpIuPrFzSFVr+eBiGRbDII1uEbiBRRyke2zxN+krBTbmDEw9nG cdMyIiDDj71NHLx8SXVdO2lp8qVktHtjh6W+6OMedTGNgu3xlgdS5nNY+HNHimyMXlQe 5la4CQa4kqa7Dt5GgtcyDBg27WWE13z+s3uEO6s/a9OeHXoQSk5YDwt0uFU4irCLLkgn 0t3jqPuCWbg8EMkDLl10nLluoAepRDqvC64MZvD+WoCXl5tteQqwULivx1KSlcEuFNNJ iOsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=MzXOzo95g617qUk7Z949h4EoD3WLK3t1qcqqyGoLxTU=; b=MKaGymiKDoTB6yYma0Pgf1zxjpBOUrgPh8gdEUjc686Y07sObznX2zW0R2wMJT8lj8 YM9TFZm671Ln4y2g3DajGrbTicdU5bFggnjd0iAzZg5zFq1b6afUKQOh1b6vuqWlNm2W QSqP7QV9gmf5wfcn+8PpeDD4kj1+H0LDrdazFqXc0E0pk0+SWZhgfVqsF506U/J1GUkY Jbhabtvv27LyYOGHe9KvCtrZmFaXR7c286YCG+IzEi7Gc5GszfqWJpnxWexbTrT+lnKe z0ZE3qmdwj1kFWIg1C/llzNOmF6WIv1IBYtIVkkwCU22N+9+nczsbI89WqYLriT7Fn99 SK5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=JnxZsTeR; dkim=neutral (no key) header.i=@suse.cz header.b=12MljAV3; 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 ix1-20020a170902f80100b001a99b965c47si2568239plb.411.2023.06.01.04.07.44; Thu, 01 Jun 2023 04:07:59 -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=JnxZsTeR; dkim=neutral (no key) header.i=@suse.cz header.b=12MljAV3; 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 S233075AbjFAK6k (ORCPT + 99 others); Thu, 1 Jun 2023 06:58:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233126AbjFAK6f (ORCPT ); Thu, 1 Jun 2023 06:58:35 -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 8AF9412C; Thu, 1 Jun 2023 03:58:32 -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 1FFBE1FD99; Thu, 1 Jun 2023 10:58:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1685617111; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MzXOzo95g617qUk7Z949h4EoD3WLK3t1qcqqyGoLxTU=; b=JnxZsTeRlkpGAeNVzMjBvMt7Um93iLPpsI45FFwBn30paVGGbNnEWH9M38MdENSm/kGngr DioDvnCcG1CcHf7FQaY8W0HEFG7aKNjvivi3Ap/HmVOb0RlNIIEAtXneeUIB3XUbbBvMbk zXCS+ZxYtK5OM8dZmOv8TRYohjVDer8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1685617111; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MzXOzo95g617qUk7Z949h4EoD3WLK3t1qcqqyGoLxTU=; b=12MljAV3Jn4lWXoFOIkKiAO7uA5l6sXWVPVfp8DSkd5pTHVzE2MnGWF2CEZjuth948cp5s BtU9qfzM+5cVWrBw== 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 122FA13A34; Thu, 1 Jun 2023 10:58:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id mmNoBNd5eGSCWAAAMHmgww (envelope-from ); Thu, 01 Jun 2023 10:58:31 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 2CDDBA0764; Thu, 1 Jun 2023 12:58:30 +0200 (CEST) From: Jan Kara To: Al Viro Cc: , Christian Brauner , Miklos Szeredi , "Darrick J. Wong" , Ted Tso , Jaegeuk Kim , , , linux-f2fs-devel@lists.sourceforge.net, Jan Kara Subject: [PATCH v2 6/6] fs: Restrict lock_two_nondirectories() to non-directory inodes Date: Thu, 1 Jun 2023 12:58:26 +0200 Message-Id: <20230601105830.13168-6-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230601104525.27897-1-jack@suse.cz> References: <20230601104525.27897-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2200; i=jack@suse.cz; h=from:subject; bh=yzjONH0NaYO0JExUsRNFVNqF61b/6Z8qTkqJfHdGKlg=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBkeHnRAOKwOpYmoYaDVDZoAJJC7iZvp0hWjbPFBMUr e9B2zauJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCZHh50QAKCRCcnaoHP2RA2ZLRB/ 9A5mErZNr1GSw4bvqyRiHpBJmYLCWR4lihVK9MrTDZk08vVOCpc8BAsxg5oODQk0iMm3VyWYYLKWrR tZpGfLNVVN9J+mp08tZRHTqzVmO2Vg1q/2eiHEQkWYSPHnJHAmAPXsS2XuUUkxDmK5B+rPgf+hKsFQ 5qg5tUZAuaUsZGy1zMAqXObFZSzjefBZrc251g++8ukB03T/LNLAVwtjvKgGmesBoq8BJdO93TYFlB INP8z2ollQ8Oqi7hSsJH2uhrQleqLb+y1+OfV/Ocf+LM4vBCuWoJGtGua+7Rg5bpG/kpJEXZmghiEY 6HGqXDo1+FmRvBPkx7nJT/lFffiE8I X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Content-Transfer-Encoding: 8bit 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 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 | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index 4000ab08bbc0..e8d10fd18378 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -1148,7 +1148,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 @@ -1156,13 +1156,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); @@ -1173,9 +1169,11 @@ EXPORT_SYMBOL(lock_two_nondirectories); */ void unlock_two_nondirectories(struct inode *inode1, struct inode *inode2) { - if (inode1 && !S_ISDIR(inode1->i_mode)) + WARN_ON_ONCE(S_ISDIR(inode1->i_mode)); + WARN_ON_ONCE(S_ISDIR(inode2->i_mode)); + if (inode1) inode_unlock(inode1); - if (inode2 && !S_ISDIR(inode2->i_mode) && inode2 != inode1) + if (inode2 && inode2 != inode1) inode_unlock(inode2); } EXPORT_SYMBOL(unlock_two_nondirectories); -- 2.35.3