diff options
author | OGAWA Hirofumi <[email protected]> | 2016-01-20 14:59:38 -0800 |
---|---|---|
committer | Linus Torvalds <[email protected]> | 2016-01-20 17:09:18 -0800 |
commit | a3082d526f2d406d4b488e49a508a0062a23314f (patch) | |
tree | 5d4b38520c00134925329278b127ae75ff45e902 | |
parent | a513d86983164a1f74a226ab7006deffbf63907e (diff) |
fat: add simple validation for directory inode
This detects simple corruption cases of directory, and tries to avoid
further damage to user data.
And performance impact of this validation should be very low, or not
measurable.
Signed-off-by: OGAWA Hirofumi <[email protected]>
Reported-by: Vegard Nossum <[email protected]>
Tested-by: Vegard Nossum <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
-rw-r--r-- | fs/fat/inode.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/fs/fat/inode.c b/fs/fat/inode.c index 3ac9078fde65..08ef5fd0d502 100644 --- a/fs/fat/inode.c +++ b/fs/fat/inode.c @@ -449,6 +449,24 @@ static int fat_calc_dir_size(struct inode *inode) return 0; } +static int fat_validate_dir(struct inode *dir) +{ + struct super_block *sb = dir->i_sb; + + if (dir->i_nlink < 2) { + /* Directory should have "."/".." entries at least. */ + fat_fs_error(sb, "corrupted directory (invalid entries)"); + return -EIO; + } + if (MSDOS_I(dir)->i_start == 0 || + MSDOS_I(dir)->i_start == MSDOS_SB(sb)->root_cluster) { + /* Directory should point valid cluster. */ + fat_fs_error(sb, "corrupted directory (invalid i_start)"); + return -EIO; + } + return 0; +} + /* doesn't deal with root inode */ int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de) { @@ -475,6 +493,10 @@ int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de) MSDOS_I(inode)->mmu_private = inode->i_size; set_nlink(inode, fat_subdirs(inode)); + + error = fat_validate_dir(inode); + if (error < 0) + return error; } else { /* not a directory */ inode->i_generation |= 1; inode->i_mode = fat_make_mode(sbi, de->attr, |