diff mbox series

[1/4] ubifs: Correctly set inode size in ubifs_link()

Message ID 20210122212229.17072-2-richard@nod.at
State Changes Requested
Headers show
Series [1/4] ubifs: Correctly set inode size in ubifs_link() | expand

Commit Message

Richard Weinberger Jan. 22, 2021, 9:22 p.m. UTC
We need to use fscrypt filename handling wrappers
when calculating the size of a directory entry, otherwise
UBIFS will report the wrong value (size of plain instead of cihper text)
for st_size of a directory if fscrypt is enabled.

Cc: stable@vger.kernel.org
Fixes: f4f61d2cc6d8 ("ubifs: Implement encrypted filenames")
Signed-off-by: Richard Weinberger <richard@nod.at>
---
 fs/ubifs/dir.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Zhihao Cheng Jan. 23, 2021, 2:35 a.m. UTC | #1
在 2021/1/23 5:22, Richard Weinberger 写道:
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
> diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c
> index 9a6b8660425a..04912dedca48 100644
> --- a/fs/ubifs/dir.c
> +++ b/fs/ubifs/dir.c
> @@ -693,7 +693,7 @@ static int ubifs_link(struct dentry *old_dentry, struct inode *dir,
>   	struct inode *inode = d_inode(old_dentry);
>   	struct ubifs_inode *ui = ubifs_inode(inode);
>   	struct ubifs_inode *dir_ui = ubifs_inode(dir);
> -	int err, sz_change = CALC_DENT_SIZE(dentry->d_name.len);
> +	int err, sz_change;
>   	struct ubifs_budget_req req = { .new_dent = 1, .dirtied_ino = 2,
>   				.dirtied_ino_d = ALIGN(ui->data_len, 8) };
>   	struct fscrypt_name nm;
> @@ -731,6 +731,8 @@ static int ubifs_link(struct dentry *old_dentry, struct inode *dir,
>   	if (inode->i_nlink == 0)
>   		ubifs_delete_orphan(c, inode->i_ino);
>   
> +	sz_change = CALC_DENT_SIZE(fname_len(&nm));
> +
>   	inc_nlink(inode);
>   	ihold(inode);
>   	inode->i_ctime = current_time(inode);
>
diff mbox series

Patch

diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c
index 9a6b8660425a..04912dedca48 100644
--- a/fs/ubifs/dir.c
+++ b/fs/ubifs/dir.c
@@ -693,7 +693,7 @@  static int ubifs_link(struct dentry *old_dentry, struct inode *dir,
 	struct inode *inode = d_inode(old_dentry);
 	struct ubifs_inode *ui = ubifs_inode(inode);
 	struct ubifs_inode *dir_ui = ubifs_inode(dir);
-	int err, sz_change = CALC_DENT_SIZE(dentry->d_name.len);
+	int err, sz_change;
 	struct ubifs_budget_req req = { .new_dent = 1, .dirtied_ino = 2,
 				.dirtied_ino_d = ALIGN(ui->data_len, 8) };
 	struct fscrypt_name nm;
@@ -731,6 +731,8 @@  static int ubifs_link(struct dentry *old_dentry, struct inode *dir,
 	if (inode->i_nlink == 0)
 		ubifs_delete_orphan(c, inode->i_ino);
 
+	sz_change = CALC_DENT_SIZE(fname_len(&nm));
+
 	inc_nlink(inode);
 	ihold(inode);
 	inode->i_ctime = current_time(inode);