On Thu, 21 Nov 2024 03:55:29 +0000, Al Viro wrote: > > user_path_at()-> > > filename_lookup()-> > > path_lookupat()-> > > lookup_last()-> > > walk_component()-> > > __lookup_slow()-> > > ntfs_lookup()-> > > d_splice_alias()-> > > > > 2. The subsequent chmod fails, causing the inode to be set to bad. > > What's wrong with "return an error"? make_bad_inode() is executed in attr_set_size() and the error code -ENOENT is returned; attr_set_size() defined in fs/ntfs3/attrib.c > > > 3. During the link operation, d_instantiate() is executed in ntfs_link() to associate the bad inode with the dentry. > > Yecchhh... If nothing else, check for is_bad_inode() should be there > for as long as make_bad_inode() is done on live inodes. I checked is_bad_inode() in ntfs_link(), see line 146 of ntfs_link(), please see my V3 of the patch [2]. [1] fs/ntfs3/namei.c 19 static int ntfs_link(struct dentry *ode, struct inode *dir, struct dentry *de) 18 { 17 int err; 16 struct inode *inode = d_inode(ode); 15 struct ntfs_inode *ni = ntfs_i(inode); 14 13 if (S_ISDIR(inode->i_mode)) 12 return -EPERM; 11 10 if (inode->i_nlink >= NTFS_LINK_MAX) 9 return -EMLINK; 8 7 ni_lock_dir(ntfs_i(dir)); 6 if (inode != dir) 5 ni_lock(ni); 4 3 inc_nlink(inode); 2 ihold(inode); 1 146 err = ntfs_link_inode(inode, de); 1 2 if (!err) { 3 inode_set_ctime_current(inode); 4 inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); 5 mark_inode_dirty(inode); 6 mark_inode_dirty(dir); 7 d_instantiate(de, inode); [2] Reported-by: syzbot+73d8fc29ec7cba8286fa@xxxxxxxxxxxxxxxxxxxxxxxxx Closes: https://syzkaller.appspot.com/bug?extid=73d8fc29ec7cba8286fa Signed-off-by: Lizhi Xu <lizhi.xu@xxxxxxxxxxxxx> --- V1 --> V2: add the root cause of the i_link not set issue and imporve the check V2 --> V3: when creating a symbolic link, first check whether the inode of file is bad. fs/ntfs3/inode.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c index be04d2845bb7..fefbdcf75016 100644 --- a/fs/ntfs3/inode.c +++ b/fs/ntfs3/inode.c @@ -1719,6 +1719,9 @@ int ntfs_link_inode(struct inode *inode, struct dentry *dentry) struct ntfs_sb_info *sbi = inode->i_sb->s_fs_info; struct NTFS_DE *de; + if (is_bad_inode(inode)) + return -EIO; + /* Allocate PATH_MAX bytes. */ de = __getname(); if (!de)