erofs: fix the unmapped access in z_erofs_fill_inode_lazy()
PATCH 1/1 erofs: fix the unmapped access in z_erofs_fill_inode_lazy()
From: Yue Hu <[email protected]>
Note that we are still accessing 'h_idata_size' and 'h_fragmentoff' after calling erofs_put_metabuf(), that is not correct. Fix it.
--- fs/erofs/zmap.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
fs/erofs/zmap.c +7 -8
@@ -58,7 +58,7 @@ static int z_erofs_fill_inode_lazy(struct inode *inode) pos =ALIGN (iloc (EROFS_SB (sb), vi->nid) + vi->inode_isize + vi->xattr_isize,8 ); kaddr =erofs_read_metabuf (&buf, sb,erofs_blknr (pos), -EROFS_KMAP_ATOMIC ); +EROFS_KMAP );if (IS_ERR (kaddr)) { err =PTR_ERR (kaddr); goto out_unlock;
@@ -73,7 +73,7 @@ static int z_erofs_fill_inode_lazy(struct inode *inode) vi->z_advise =Z_EROFS_ADVISE_FRAGMENT_PCLUSTER ; vi->z_fragmentoff =le64_to_cpu (*(__le64 *)h) ^ (1ULL <<63 ); vi->z_tailextent_headlcn =0 ; - goto unmap_done; + goto init_done; } vi->z_advise =le16_to_cpu (h->h_advise); vi->z_algorithmtype[0 ] = h->h_algorithmtype &15 ;
@@ -105,10 +105,6 @@ static int z_erofs_fill_inode_lazy(struct inode *inode) err = -EFSCORRUPTED ; goto unmap_done; } -unmap_done: -erofs_put_metabuf (&buf); -if (err) - goto out_unlock;if (vi->z_advise &Z_EROFS_ADVISE_INLINE_PCLUSTER ) {struct erofs_map_blocks map = {
@@ -127,7 +123,7 @@ static int z_erofs_fill_inode_lazy(struct inode *inode) err = -EFSCORRUPTED ; }if (err <0 ) - goto out_unlock; + goto unmap_done; } if (vi->z_advise & Z_EROFS_ADVISE_FRAGMENT_PCLUSTER &&
@@ -141,11 +137,14 @@ static int z_erofs_fill_inode_lazy(struct inode *inode) EROFS_GET_BLOCKS_FINDTAIL);erofs_put_metabuf (&map.buf);if (err <0 ) - goto out_unlock; + goto unmap_done; } +init_done:/* paired with smp_mb() at the beginning of the function */ smp_mb ();set_bit (EROFS_I_Z_INITED_BIT , &vi->flags); +unmap_done: +erofs_put_metabuf (&buf); out_unlock:clear_and_wake_up_bit (EROFS_I_BL_Z_BIT , &vi->flags);return err;
Signature · 1 line
2.25.1
Gao Xiang
maintainerQuoted 5 lines · Yue Hu
From: Yue Hu <[email protected]>
Note that we are still accessing '
h_idata_size' and 'h_fragmentoff' after callingerofs_put_metabuf(), that is not correct. Fix it.
Quoted 7 lines
Fixes ab92184ff8f1 ("add on-disk compressed tail-packing inline support")Fixes b15b2e307c3a ("support on-disk compressed fragments data")Signed-off-by Yue Hu <[email protected]>--- fs/erofs/zmap.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
erofs: fix invalid unmapped accesses in z_erofs_fill_inode_lazy()
fs/erofs/zmap.c static int z_erofs_fill_inode_lazy(struct inode *inode) · line 61
Quoted 10 lines
fs/erofs/zmap.c +1
-1@@ -58,7 +58,7 @@ static int z_erofs_fill_inode_lazy(struct inode *inode) pos =ALIGN (iloc (EROFS_SB (sb), vi->nid) + vi->inode_isize + vi->xattr_isize,8 ); kaddr =erofs_read_metabuf (&buf, sb,erofs_blknr (pos), -EROFS_KMAP_ATOMIC ); +EROFS_KMAP );
kaddr = erofs_read_metabuf(&buf, sb, erofs_blknr(pos), EROFS_KMAP); ?
Also I will use kmap_local later to replace kmap and kmap_atomic if possible.
Quoted 33 lines
fs/erofs/zmap.c +2
-6if (IS_ERR (kaddr)) { err =PTR_ERR (kaddr); goto out_unlock;@@ -73,7 +73,7 @@ static int z_erofs_fill_inode_lazy(struct inode *inode) vi->z_advise =Z_EROFS_ADVISE_FRAGMENT_PCLUSTER ; vi->z_fragmentoff =le64_to_cpu (*(__le64 *)h) ^ (1ULL <<63 ); vi->z_tailextent_headlcn =0 ; - goto unmap_done; + goto init_done; } vi->z_advise =le16_to_cpu (h->h_advise); vi->z_algorithmtype[0 ] = h->h_algorithmtype &15 ;@@ -105,10 +105,6 @@ static int z_erofs_fill_inode_lazy(struct inode *inode) err = -EFSCORRUPTED ; goto unmap_done; } -unmap_done: -erofs_put_metabuf (&buf); -if (err) - goto out_unlock;if (vi->z_advise &Z_EROFS_ADVISE_INLINE_PCLUSTER ) {struct erofs_map_blocks map = {@@ -127,7 +123,7 @@ static int z_erofs_fill_inode_lazy(struct inode *inode) err = -EFSCORRUPTED ; }if (err <0 ) - goto out_unlock; + goto unmap_done; } if (vi->z_advise & Z_EROFS_ADVISE_FRAGMENT_PCLUSTER &&
fs/erofs/zmap.c static int z_erofs_fill_inode_lazy(struct inode *inode) · line 142
Quoted 7 lines
fs/erofs/zmap.c +2
-1@@ -141,11 +137,14 @@ static int z_erofs_fill_inode_lazy(struct inode *inode) EROFS_GET_BLOCKS_FINDTAIL);erofs_put_metabuf (&map.buf);if (err <0 ) - goto out_unlock; + goto unmap_done; } +init_done:
done:
fs/erofs/zmap.c static int z_erofs_fill_inode_lazy(struct inode *inode) · line 146
Quoted 4 lines
fs/erofs/zmap.c +1
-0/* paired with smp_mb() at the beginning of the function */ smp_mb ();set_bit (EROFS_I_Z_INITED_BIT , &vi->flags); +unmap_done:
out_put_metabuf:
Thanks,
Gao Xiang
Quoted 7 lines
fs/erofs/zmap.c +1
-0+erofs_put_metabuf (&buf); out_unlock:clear_and_wake_up_bit (EROFS_I_BL_Z_BIT , &vi->flags);return err;Signature · 1 line
2.25.1