Skip to content

Commit 664609e

Browse files
taigerhuhsiangkao
authored andcommitted
erofs: fix illegal unmapped accesses in z_erofs_fill_inode_lazy()
Note that we are still accessing 'h_idata_size' and 'h_fragmentoff' after calling erofs_put_metabuf(), that is not correct. Fix it. Fixes: ab92184 ("erofs: add on-disk compressed tail-packing inline support") Fixes: b15b2e3 ("erofs: support on-disk compressed fragments data") Signed-off-by: Yue Hu <[email protected]> Reviewed-by: Gao Xiang <[email protected]> Reviewed-by: Chao Yu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Gao Xiang <[email protected]>
1 parent 9abf231 commit 664609e

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

fs/erofs/zmap.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ static int z_erofs_fill_inode_lazy(struct inode *inode)
5757

5858
pos = ALIGN(iloc(EROFS_SB(sb), vi->nid) + vi->inode_isize +
5959
vi->xattr_isize, 8);
60-
kaddr = erofs_read_metabuf(&buf, sb, erofs_blknr(pos),
61-
EROFS_KMAP_ATOMIC);
60+
kaddr = erofs_read_metabuf(&buf, sb, erofs_blknr(pos), EROFS_KMAP);
6261
if (IS_ERR(kaddr)) {
6362
err = PTR_ERR(kaddr);
6463
goto out_unlock;
@@ -73,7 +72,7 @@ static int z_erofs_fill_inode_lazy(struct inode *inode)
7372
vi->z_advise = Z_EROFS_ADVISE_FRAGMENT_PCLUSTER;
7473
vi->z_fragmentoff = le64_to_cpu(*(__le64 *)h) ^ (1ULL << 63);
7574
vi->z_tailextent_headlcn = 0;
76-
goto unmap_done;
75+
goto done;
7776
}
7877
vi->z_advise = le16_to_cpu(h->h_advise);
7978
vi->z_algorithmtype[0] = h->h_algorithmtype & 15;
@@ -85,7 +84,7 @@ static int z_erofs_fill_inode_lazy(struct inode *inode)
8584
erofs_err(sb, "unknown HEAD%u format %u for nid %llu, please upgrade kernel",
8685
headnr + 1, vi->z_algorithmtype[headnr], vi->nid);
8786
err = -EOPNOTSUPP;
88-
goto unmap_done;
87+
goto out_put_metabuf;
8988
}
9089

9190
vi->z_logical_clusterbits = LOG_BLOCK_SIZE + (h->h_clusterbits & 7);
@@ -95,20 +94,16 @@ static int z_erofs_fill_inode_lazy(struct inode *inode)
9594
erofs_err(sb, "per-inode big pcluster without sb feature for nid %llu",
9695
vi->nid);
9796
err = -EFSCORRUPTED;
98-
goto unmap_done;
97+
goto out_put_metabuf;
9998
}
10099
if (vi->datalayout == EROFS_INODE_FLAT_COMPRESSION &&
101100
!(vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_1) ^
102101
!(vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_2)) {
103102
erofs_err(sb, "big pcluster head1/2 of compact indexes should be consistent for nid %llu",
104103
vi->nid);
105104
err = -EFSCORRUPTED;
106-
goto unmap_done;
105+
goto out_put_metabuf;
107106
}
108-
unmap_done:
109-
erofs_put_metabuf(&buf);
110-
if (err)
111-
goto out_unlock;
112107

113108
if (vi->z_advise & Z_EROFS_ADVISE_INLINE_PCLUSTER) {
114109
struct erofs_map_blocks map = {
@@ -127,7 +122,7 @@ static int z_erofs_fill_inode_lazy(struct inode *inode)
127122
err = -EFSCORRUPTED;
128123
}
129124
if (err < 0)
130-
goto out_unlock;
125+
goto out_put_metabuf;
131126
}
132127

133128
if (vi->z_advise & Z_EROFS_ADVISE_FRAGMENT_PCLUSTER &&
@@ -141,11 +136,14 @@ static int z_erofs_fill_inode_lazy(struct inode *inode)
141136
EROFS_GET_BLOCKS_FINDTAIL);
142137
erofs_put_metabuf(&map.buf);
143138
if (err < 0)
144-
goto out_unlock;
139+
goto out_put_metabuf;
145140
}
141+
done:
146142
/* paired with smp_mb() at the beginning of the function */
147143
smp_mb();
148144
set_bit(EROFS_I_Z_INITED_BIT, &vi->flags);
145+
out_put_metabuf:
146+
erofs_put_metabuf(&buf);
149147
out_unlock:
150148
clear_and_wake_up_bit(EROFS_I_BL_Z_BIT, &vi->flags);
151149
return err;

0 commit comments

Comments
 (0)