erofs: fix missing unmap if z_erofs_get_extent_compressedlen() fails
PATCH 1/2 erofs: fix missing unmap if z_erofs_get_extent_compressedlen() fails
Otherwise, meta buffers could be leaked.
--- fs/erofs/zmap.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
fs/erofs/zmap.c +2 -4
@@ -694,7 +694,7 @@ static int z_erofs_do_map_blocks(struct inode *inode, map->m_pa =blknr_to_addr (m.pblk); err =z_erofs_get_extent_compressedlen (&m, initial_lcn);if (err) - goto out; + goto unmap_out; }if (m.headtype ==Z_EROFS_VLE_CLUSTER_TYPE_PLAIN ) {
@@ -718,14 +718,12 @@ static int z_erofs_do_map_blocks(struct inode *inode,if (!err) map->m_flags |=EROFS_MAP_FULL_MAPPED ; } + unmap_out:erofs_unmap_metabuf (&m.map->buf); - -out:erofs_dbg ("%s, m_la %llu m_pa %llu m_llen %llu m_plen %llu m_flags 0%o" , __func__, map->m_la, map->m_pa, map->m_llen, map->m_plen, map->m_flags); -return err; }
Signature · 1 line
2.24.4
PATCH 2/2 erofs: validate the extent length for uncompressed pclusters
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.
--- fs/erofs/zmap.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/erofs/zmap.c +5 -0
@@ -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 ;
Signature · 1 line
2.24.4
Re: [PATCH 2/2] erofs: validate the extent length for uncompressed pclusters
Quoted 7 lines · Gao Xiang
syzkaller reported a KASAN use-after-free:
https://syzkaller.appspot.com/bug?extid=2ae90e873e97f1faf6f2The referenced fuzzed image actually has two issues:
-m_pa== 0 as a non-inlined pcluster;
- The logical length is longer than its physical length.
Quoted 6 lines
The first issue has already been addressed. This patch addresses the second issue by checking the extent length validity.
Reported-by [email protected]Fixes 02827e1796b3 ("staging: erofs: add erofs_map_blocks_iter")Signed-off-by Gao Xiang <[email protected]>
Thanks,
Quoted 4 lines · On Mon, 5 Dec 2022 23:00:49 +0800 Gao Xiang <[email protected]>…
Otherwise, meta buffers could be leaked.
Fixes cec6e93beadf ("erofs: support parsing big pcluster compress indexes")Signed-off-by Gao Xiang <[email protected]>
Quoted 33 lines
--- fs/erofs/zmap.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)fs/erofs/zmap.c +2
-4@@ -694,7 +694,7 @@ static int z_erofs_do_map_blocks(struct inode *inode, map->m_pa =blknr_to_addr (m.pblk); err =z_erofs_get_extent_compressedlen (&m, initial_lcn);if (err) - goto out; + goto unmap_out; }if (m.headtype ==Z_EROFS_VLE_CLUSTER_TYPE_PLAIN ) {@@ -718,14 +718,12 @@ static int z_erofs_do_map_blocks(struct inode *inode,if (!err) map->m_flags |=EROFS_MAP_FULL_MAPPED ; } + unmap_out:erofs_unmap_metabuf (&m.map->buf); - -out:erofs_dbg ("%s, m_la %llu m_pa %llu m_llen %llu m_plen %llu m_flags 0%o" , __func__, map->m_la, map->m_pa, map->m_llen, map->m_plen, map->m_flags); -return err; }
Quoted 4 lines · Gao Xiang
Otherwise, meta buffers could be leaked.
Fixes cec6e93beadf ("erofs: support parsing big pcluster compress indexes")Signed-off-by Gao Xiang <[email protected]>
Thanks,