udf: Fix BUG on corrupted inode
authorJan Kara <jack@suse.cz>
Wed, 12 Dec 2018 13:29:20 +0000 (14:29 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 12 Feb 2019 18:46:03 +0000 (19:46 +0100)
[ Upstream commit d288d95842f1503414b7eebce3773bac3390457e ]

When inode is corrupted so that extent type is invalid, some functions
(such as udf_truncate_extents()) will just BUG. Check that extent type
is valid when loading the inode to memory.

Reported-by: Anatoly Trosinenko <anatoly.trosinenko@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/udf/inode.c

index 8dacf4f..28b9d7c 100644 (file)
@@ -1357,6 +1357,12 @@ reread:
 
        iinfo->i_alloc_type = le16_to_cpu(fe->icbTag.flags) &
                                                        ICBTAG_FLAG_AD_MASK;
+       if (iinfo->i_alloc_type != ICBTAG_FLAG_AD_SHORT &&
+           iinfo->i_alloc_type != ICBTAG_FLAG_AD_LONG &&
+           iinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
+               ret = -EIO;
+               goto out;
+       }
        iinfo->i_unique = 0;
        iinfo->i_lenEAttr = 0;
        iinfo->i_lenExtents = 0;