udf: Verify link count before updating it
Subsystems (2)
Jan Kara
reviewercover udf: Verify link count before updating it
Hello,
these two patches fix syzbot complaints that corrupted filesystems can trigger warnings in VFS that link counts go negative. We need to check the link count is sane before updating it. I plan to merge these patches to my tree.
Honza
Jan Kara
reviewerPATCH 1/2 udf: Skip parent dir link count update if corrupted
If the parent directory link count is too low (likely directory inode corruption), just skip updating its link count as if it goes to 0 too early it can cause unexpected issues.
--- fs/udf/namei.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/udf/namei.c +5 -1
@@ -517,7 +517,11 @@ static int udf_rmdir(struct inode *dir, struct dentry *dentry) inode->i_nlink);clear_nlink (inode); inode->i_size =0 ; -inode_dec_link_count (dir); +if (dir->i_nlink >=3 ) +inode_dec_link_count (dir); +else +udf_warn (inode->i_sb,"parent dir link count too low (%u)\n" , + dir->i_nlink);udf_add_fid_counter (dir->i_sb, true,-1 );inode_set_mtime_to_ts (dir,inode_set_ctime_to_ts (dir,inode_set_ctime_current (inode)));
Signature · 1 line
2.35.3
Jan Kara
reviewerPATCH 2/2 udf: Verify inode link counts before performing rename
In reply to Jan KaraDuring rename, we are updating link counts of various inodes either when rename deletes target or when moving directory across directories. Verify involved link counts are sane so that we don't trip warnings in VFS.
--- fs/udf/namei.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
fs/udf/namei.c +10 -0
@@ -791,8 +791,18 @@ static int udf_rename(struct mnt_idmap *idmap, struct inode *old_dir, retval = -ENOTEMPTY ;if (!empty_dir (new_inode)) goto out_oiter; + retval = -EFSCORRUPTED ; +if (new_inode->i_nlink !=2 ) + goto out_oiter; } + retval = -EFSCORRUPTED ; +if (old_dir->i_nlink <3 ) + goto out_oiter; is_dir = true; + }else if (new_inode) { + retval = -EFSCORRUPTED ; +if (new_inode->i_nlink <1 ) + goto out_oiter; }if (is_dir && old_dir != new_dir) { retval = udf_fiiter_find_entry(old_inode, &dotdot_name,
Signature · 1 line
2.35.3