Skip to content

Commit 8045e29

Browse files
committed
fat: Fix vfat_lookup()
After d_find_alias(), vfat_lookup() checks !(->d_flags & DCACHE_DISCONNECTED) without IS_ROOT(). This means it hits non-anonymous but disconnected dentry. (NOTE: d_splice_alias() doesn't clear DCACHE_DISCONNECTED) But, vfat_lookup() has interest to alias if it was non-anonymous. So, this adds vfat_d_anon_disconn() helper to check it correctly. Another bug is refcnt leak. It needs dput() for uninterested alias. Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
1 parent 3c8ad49 commit 8045e29

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

‎fs/fat/namei_vfat.c‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,15 @@ static int vfat_find(struct inode *dir, struct qstr *qname,
701701
return fat_search_long(dir, qname->name, len, sinfo);
702702
}
703703

704+
/*
705+
* (nfsd's) anonymous disconnected dentry?
706+
* NOTE: !IS_ROOT() is not anonymous (I.e. d_splice_alias() did the job).
707+
*/
708+
static int vfat_d_anon_disconn(struct dentry *dentry)
709+
{
710+
return IS_ROOT(dentry) && (dentry->d_flags & DCACHE_DISCONNECTED);
711+
}
712+
704713
static struct dentry *vfat_lookup(struct inode *dir, struct dentry *dentry,
705714
struct nameidata *nd)
706715
{
@@ -729,11 +738,11 @@ static struct dentry *vfat_lookup(struct inode *dir, struct dentry *dentry,
729738
}
730739

731740
alias = d_find_alias(inode);
732-
if (alias && !(alias->d_flags & DCACHE_DISCONNECTED)) {
741+
if (alias && !vfat_d_anon_disconn(alias)) {
733742
/*
734-
* This inode has non DCACHE_DISCONNECTED dentry. This
735-
* means, the user did ->lookup() by an another name
736-
* (longname vs 8.3 alias of it) in past.
743+
* This inode has non anonymous-DCACHE_DISCONNECTED
744+
* dentry. This means, the user did ->lookup() by an
745+
* another name (longname vs 8.3 alias of it) in past.
737746
*
738747
* Switch to new one for reason of locality if possible.
739748
*/
@@ -743,7 +752,9 @@ static struct dentry *vfat_lookup(struct inode *dir, struct dentry *dentry,
743752
iput(inode);
744753
unlock_super(sb);
745754
return alias;
746-
}
755+
} else
756+
dput(alias);
757+
747758
out:
748759
unlock_super(sb);
749760
dentry->d_op = sb->s_root->d_op;

0 commit comments

Comments
 (0)