erofs: validate the extent length for uncompressed pclusters
authorGao Xiang <hsiangkao@linux.alibaba.com>
Mon, 5 Dec 2022 15:00:50 +0000 (23:00 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 31 Dec 2022 12:31:59 +0000 (13:31 +0100)
[ Upstream commit c505feba4c0d76084e56ec498ce819f02a7043ae ]

syzkaller reported a KASAN use-after-free:
https://syzkaller.appspot.com/bug?extid=2ae90e873e97f1faf6f2

The referenced fuzzed image actually has two issues:
 - m_pa == 0 as a non-inlined pcluster;
 - The logical length is longer than its physical length.

The first issue has already been addressed.  This patch addresses
the second issue by checking the extent length validity.

Reported-by: syzbot+2ae90e873e97f1faf6f2@syzkaller.appspotmail.com
Fixes: 02827e1796b3 ("staging: erofs: add erofs_map_blocks_iter")
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20221205150050.47784-2-hsiangkao@linux.alibaba.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/erofs/zmap.c

index f49295b..e6d5d7a 100644 (file)
@@ -698,6 +698,11 @@ static int z_erofs_do_map_blocks(struct inode *inode,
        }
 
        if (m.headtype == Z_EROFS_VLE_CLUSTER_TYPE_PLAIN) {
+               if (map->m_llen > map->m_plen) {
+                       DBG_BUGON(1);
+                       err = -EFSCORRUPTED;
+                       goto unmap_out;
+               }
                if (vi->z_advise & Z_EROFS_ADVISE_INTERLACED_PCLUSTER)
                        map->m_algorithmformat =
                                Z_EROFS_COMPRESSION_INTERLACED;