lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 10 Jun 2022 04:17:38 +0900
From:   OGAWA Hirofumi <hirofumi@...l.parknet.co.jp>
To:     Javier Martinez Canillas <javierm@...hat.com>
Cc:     linux-kernel@...r.kernel.org, Peter Jones <pjones@...hat.com>,
        Alexander Larsson <alexl@...hat.com>,
        Colin Walters <walters@...bum.org>,
        Alberto Ruiz <aruiz@...hat.com>,
        Muhammad Usama Anjum <usama.anjum@...labora.com>,
        Lennart Poettering <lennart@...ttering.net>,
        Chung-Chiang Cheng <cccheng@...ology.com>,
        Christian Kellner <ckellner@...hat.com>,
        Carlos Maiolino <cmaiolin@...hat.com>
Subject: Re: [PATCH v5 3/4] fat: add renameat2 RENAME_EXCHANGE flag support

Javier Martinez Canillas <javierm@...hat.com> writes:

> +static void vfat_update_nlink(struct inode *dir, struct inode *inode)
> +{
> +		if (S_ISDIR(inode->i_mode))
> +			drop_nlink(dir);
> +		else
> +			inc_nlink(dir);
> +}

[...]

> +	vfat_update_dir_metadata(old_dir, &ts);
> +	/* if directories are not the same, update new_dir as well */
> +	if (old_dir != new_dir) {
> +		vfat_update_dir_metadata(new_dir, &ts);
> +		/* nlink only needs to be updated if the file types differ */
> +		if (old_inode->i_mode != new_inode->i_mode) {
> +			vfat_update_nlink(old_dir, old_inode);
> +			vfat_update_nlink(new_dir, new_inode);
> +		}
> +	}

Looks like unnecessary complex (and comparing raw i_mode, not S_ISDIR(),
better to change before make dir dirty).  How about this change, it is
only tested slightly though? Can you review and test?

Thanks.
-- 
OGAWA Hirofumi <hirofumi@...l.parknet.co.jp>


Signed-off-by: OGAWA Hirofumi <hirofumi@...l.parknet.co.jp>
---
 fs/fat/namei_vfat.c |   25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c
index c30f829..3aef834 100644
--- a/fs/fat/namei_vfat.c	2022-06-10 03:33:40.334212176 +0900
+++ b/fs/fat/namei_vfat.c	2022-06-10 04:11:30.817064192 +0900
@@ -1055,12 +1055,10 @@ static void vfat_exchange_ipos(struct in
 	fat_attach(new_inode, old_i_pos);
 }
 
-static void vfat_update_nlink(struct inode *dir, struct inode *inode)
+static void vfat_move_nlink(struct inode *src, struct inode *dst)
 {
-		if (S_ISDIR(inode->i_mode))
-			drop_nlink(dir);
-		else
-			inc_nlink(dir);
+	drop_nlink(src);
+	inc_nlink(dst);
 }
 
 static int vfat_rename_exchange(struct inode *old_dir, struct dentry *old_dentry,
@@ -1112,7 +1110,6 @@ static int vfat_rename_exchange(struct i
 		if (err)
 			goto error_old_dotdot;
 	}
-
 	if (new_dotdot_de) {
 		err = vfat_update_dotdot_de(old_dir, new_inode, new_dotdot_bh,
 					    new_dotdot_de);
@@ -1120,16 +1117,18 @@ static int vfat_rename_exchange(struct i
 			goto error_new_dotdot;
 	}
 
+	/* if cross directory and only one is a directory, adjust nlink */
+	if (!old_dotdot_de != !new_dotdot_de) {
+		if (old_dotdot_de)
+			vfat_move_nlink(old_dir, new_dir);
+		else
+			vfat_move_nlink(new_dir, old_dir);
+	}
+
 	vfat_update_dir_metadata(old_dir, &ts);
 	/* if directories are not the same, update new_dir as well */
-	if (old_dir != new_dir) {
+	if (old_dir != new_dir)
 		vfat_update_dir_metadata(new_dir, &ts);
-		/* nlink only needs to be updated if the file types differ */
-		if (old_inode->i_mode != new_inode->i_mode) {
-			vfat_update_nlink(old_dir, old_inode);
-			vfat_update_nlink(new_dir, new_inode);
-		}
-	}
 
 out:
 	brelse(old_dotdot_bh);
_

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ