Skip to content

Commit 7569049

Browse files
Zhihao Chengrichardweinberger
authored andcommitted
ubifs: ubifs_link: Fix wrong name len calculating when UBIFS is encrypted
The length of dentry name is calculated after the raw name is encrypted, except for ubifs_link(), which could make the size of dir underflow. Here is a reproducer: touch $TMP/file mkdir $TMP/dir stat $TMP/dir for i in $(seq 1 8) do ln $TMP/file $TMP/dir/$i unlink $TMP/dir/$i done stat $TMP/dir The size of dir will be underflow(-96). Fix it by calculating dentry name's length after the name is encrypted. Fixes: f4f61d2 ("ubifs: Implement encrypted filenames") Reported-by: Roland Ruckerbauer <[email protected]> Link: https://lore.kernel.org/linux-mtd/[email protected]/T/#u Signed-off-by: Zhihao Cheng <[email protected]> Signed-off-by: Richard Weinberger <[email protected]>
1 parent d07cec9 commit 7569049

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

fs/ubifs/dir.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ static int ubifs_link(struct dentry *old_dentry, struct inode *dir,
724724
struct inode *inode = d_inode(old_dentry);
725725
struct ubifs_inode *ui = ubifs_inode(inode);
726726
struct ubifs_inode *dir_ui = ubifs_inode(dir);
727-
int err, sz_change = CALC_DENT_SIZE(dentry->d_name.len);
727+
int err, sz_change;
728728
struct ubifs_budget_req req = { .new_dent = 1, .dirtied_ino = 2,
729729
.dirtied_ino_d = ALIGN(ui->data_len, 8) };
730730
struct fscrypt_name nm;
@@ -748,6 +748,8 @@ static int ubifs_link(struct dentry *old_dentry, struct inode *dir,
748748
if (err)
749749
return err;
750750

751+
sz_change = CALC_DENT_SIZE(fname_len(&nm));
752+
751753
err = dbg_check_synced_i_size(c, inode);
752754
if (err)
753755
goto out_fname;

0 commit comments

Comments
 (0)