mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-06-17 20:25:19 +00:00
fat: validate ->i_start before using
On corrupted FATfs may have invalid ->i_start. To handle it, this checks ->i_start before using, and return proper error code. Link: http://lkml.kernel.org/r/87o9f8y1t5.fsf_-_@mail.parknet.co.jp Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> Reported-by: Anatoly Trosinenko <anatoly.trosinenko@gmail.com> Tested-by: Anatoly Trosinenko <anatoly.trosinenko@gmail.com> Cc: Alan Cox <gnomes@lxorguk.ukuu.org.uk> Cc: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
f663b5b38f
commit
0afa962666
3 changed files with 20 additions and 10 deletions
|
@ -225,7 +225,8 @@ static inline void cache_init(struct fat_cache_id *cid, int fclus, int dclus)
|
|||
int fat_get_cluster(struct inode *inode, int cluster, int *fclus, int *dclus)
|
||||
{
|
||||
struct super_block *sb = inode->i_sb;
|
||||
const int limit = sb->s_maxbytes >> MSDOS_SB(sb)->cluster_bits;
|
||||
struct msdos_sb_info *sbi = MSDOS_SB(sb);
|
||||
const int limit = sb->s_maxbytes >> sbi->cluster_bits;
|
||||
struct fat_entry fatent;
|
||||
struct fat_cache_id cid;
|
||||
int nr;
|
||||
|
@ -234,6 +235,12 @@ int fat_get_cluster(struct inode *inode, int cluster, int *fclus, int *dclus)
|
|||
|
||||
*fclus = 0;
|
||||
*dclus = MSDOS_I(inode)->i_start;
|
||||
if (!fat_valid_entry(sbi, *dclus)) {
|
||||
fat_fs_error_ratelimit(sb,
|
||||
"%s: invalid start cluster (i_pos %lld, start %08x)",
|
||||
__func__, MSDOS_I(inode)->i_pos, *dclus);
|
||||
return -EIO;
|
||||
}
|
||||
if (cluster == 0)
|
||||
return 0;
|
||||
|
||||
|
@ -250,9 +257,8 @@ int fat_get_cluster(struct inode *inode, int cluster, int *fclus, int *dclus)
|
|||
/* prevent the infinite loop of cluster chain */
|
||||
if (*fclus > limit) {
|
||||
fat_fs_error_ratelimit(sb,
|
||||
"%s: detected the cluster chain loop"
|
||||
" (i_pos %lld)", __func__,
|
||||
MSDOS_I(inode)->i_pos);
|
||||
"%s: detected the cluster chain loop (i_pos %lld)",
|
||||
__func__, MSDOS_I(inode)->i_pos);
|
||||
nr = -EIO;
|
||||
goto out;
|
||||
}
|
||||
|
@ -262,9 +268,8 @@ int fat_get_cluster(struct inode *inode, int cluster, int *fclus, int *dclus)
|
|||
goto out;
|
||||
else if (nr == FAT_ENT_FREE) {
|
||||
fat_fs_error_ratelimit(sb,
|
||||
"%s: invalid cluster chain (i_pos %lld)",
|
||||
__func__,
|
||||
MSDOS_I(inode)->i_pos);
|
||||
"%s: invalid cluster chain (i_pos %lld)",
|
||||
__func__, MSDOS_I(inode)->i_pos);
|
||||
nr = -EIO;
|
||||
goto out;
|
||||
} else if (nr == FAT_ENT_EOF) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue