Skip to content

Commit 63fa605

Browse files
committed
Merge tag 'erofs-for-6.12-rc4-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs
Pull erofs fixes from Gao Xiang: "The main one fixes a syzbot issue due to the invalid inode type out of file-backed mounts. The others are minor cleanups without actual logic changes. Summary: - Make sure only regular inodes can be used for file-backed mounts - Two minor codebase cleanups" * tag 'erofs-for-6.12-rc4-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs: erofs: get rid of kaddr in `struct z_erofs_maprecorder` erofs: get rid of z_erofs_try_to_claim_pcluster() erofs: ensure regular inodes for file-backed mounts
2 parents 6485cf5 + ae54567 commit 63fa605

File tree

3 files changed

+31
-43
lines changed

3 files changed

+31
-43
lines changed

fs/erofs/super.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,14 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb,
191191
if (IS_ERR(file))
192192
return PTR_ERR(file);
193193

194-
dif->file = file;
195-
if (!erofs_is_fileio_mode(sbi))
194+
if (!erofs_is_fileio_mode(sbi)) {
196195
dif->dax_dev = fs_dax_get_by_bdev(file_bdev(file),
197196
&dif->dax_part_off, NULL, NULL);
197+
} else if (!S_ISREG(file_inode(file)->i_mode)) {
198+
fput(file);
199+
return -EINVAL;
200+
}
201+
dif->file = file;
198202
}
199203

200204
dif->blocks = le32_to_cpu(dis->blocks);
@@ -714,7 +718,10 @@ static int erofs_fc_get_tree(struct fs_context *fc)
714718
if (IS_ERR(sbi->fdev))
715719
return PTR_ERR(sbi->fdev);
716720

717-
return get_tree_nodev(fc, erofs_fc_fill_super);
721+
if (S_ISREG(file_inode(sbi->fdev)->i_mode) &&
722+
sbi->fdev->f_mapping->a_ops->read_folio)
723+
return get_tree_nodev(fc, erofs_fc_fill_super);
724+
fput(sbi->fdev);
718725
}
719726
#endif
720727
return ret;

fs/erofs/zdata.c

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -710,24 +710,6 @@ static int z_erofs_attach_page(struct z_erofs_decompress_frontend *fe,
710710
return ret;
711711
}
712712

713-
static void z_erofs_try_to_claim_pcluster(struct z_erofs_decompress_frontend *f)
714-
{
715-
struct z_erofs_pcluster *pcl = f->pcl;
716-
z_erofs_next_pcluster_t *owned_head = &f->owned_head;
717-
718-
/* type 1, nil pcluster (this pcluster doesn't belong to any chain.) */
719-
if (cmpxchg(&pcl->next, Z_EROFS_PCLUSTER_NIL,
720-
*owned_head) == Z_EROFS_PCLUSTER_NIL) {
721-
*owned_head = &pcl->next;
722-
/* so we can attach this pcluster to our submission chain. */
723-
f->mode = Z_EROFS_PCLUSTER_FOLLOWED;
724-
return;
725-
}
726-
727-
/* type 2, it belongs to an ongoing chain */
728-
f->mode = Z_EROFS_PCLUSTER_INFLIGHT;
729-
}
730-
731713
static int z_erofs_register_pcluster(struct z_erofs_decompress_frontend *fe)
732714
{
733715
struct erofs_map_blocks *map = &fe->map;
@@ -803,7 +785,6 @@ static int z_erofs_pcluster_begin(struct z_erofs_decompress_frontend *fe)
803785
int ret;
804786

805787
DBG_BUGON(fe->pcl);
806-
807788
/* must be Z_EROFS_PCLUSTER_TAIL or pointed to previous pcluster */
808789
DBG_BUGON(fe->owned_head == Z_EROFS_PCLUSTER_NIL);
809790

@@ -823,7 +804,15 @@ static int z_erofs_pcluster_begin(struct z_erofs_decompress_frontend *fe)
823804

824805
if (ret == -EEXIST) {
825806
mutex_lock(&fe->pcl->lock);
826-
z_erofs_try_to_claim_pcluster(fe);
807+
/* check if this pcluster hasn't been linked into any chain. */
808+
if (cmpxchg(&fe->pcl->next, Z_EROFS_PCLUSTER_NIL,
809+
fe->owned_head) == Z_EROFS_PCLUSTER_NIL) {
810+
/* .. so it can be attached to our submission chain */
811+
fe->owned_head = &fe->pcl->next;
812+
fe->mode = Z_EROFS_PCLUSTER_FOLLOWED;
813+
} else { /* otherwise, it belongs to an inflight chain */
814+
fe->mode = Z_EROFS_PCLUSTER_INFLIGHT;
815+
}
827816
} else if (ret) {
828817
return ret;
829818
}

fs/erofs/zmap.c

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
struct z_erofs_maprecorder {
1111
struct inode *inode;
1212
struct erofs_map_blocks *map;
13-
void *kaddr;
14-
1513
unsigned long lcn;
1614
/* compression extent information gathered */
1715
u8 type, headtype;
@@ -33,14 +31,11 @@ static int z_erofs_load_full_lcluster(struct z_erofs_maprecorder *m,
3331
struct z_erofs_lcluster_index *di;
3432
unsigned int advise;
3533

36-
m->kaddr = erofs_read_metabuf(&m->map->buf, inode->i_sb,
37-
pos, EROFS_KMAP);
38-
if (IS_ERR(m->kaddr))
39-
return PTR_ERR(m->kaddr);
40-
41-
m->nextpackoff = pos + sizeof(struct z_erofs_lcluster_index);
34+
di = erofs_read_metabuf(&m->map->buf, inode->i_sb, pos, EROFS_KMAP);
35+
if (IS_ERR(di))
36+
return PTR_ERR(di);
4237
m->lcn = lcn;
43-
di = m->kaddr;
38+
m->nextpackoff = pos + sizeof(struct z_erofs_lcluster_index);
4439

4540
advise = le16_to_cpu(di->di_advise);
4641
m->type = advise & Z_EROFS_LI_LCLUSTER_TYPE_MASK;
@@ -53,8 +48,7 @@ static int z_erofs_load_full_lcluster(struct z_erofs_maprecorder *m,
5348
DBG_BUGON(1);
5449
return -EFSCORRUPTED;
5550
}
56-
m->compressedblks = m->delta[0] &
57-
~Z_EROFS_LI_D0_CBLKCNT;
51+
m->compressedblks = m->delta[0] & ~Z_EROFS_LI_D0_CBLKCNT;
5852
m->delta[0] = 1;
5953
}
6054
m->delta[1] = le16_to_cpu(di->di_u.delta[1]);
@@ -110,9 +104,9 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m,
110104
struct erofs_inode *const vi = EROFS_I(m->inode);
111105
const unsigned int lclusterbits = vi->z_logical_clusterbits;
112106
unsigned int vcnt, lo, lobits, encodebits, nblk, bytes;
113-
int i;
114-
u8 *in, type;
115107
bool big_pcluster;
108+
u8 *in, type;
109+
int i;
116110

117111
if (1 << amortizedshift == 4 && lclusterbits <= 14)
118112
vcnt = 2;
@@ -121,16 +115,18 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m,
121115
else
122116
return -EOPNOTSUPP;
123117

118+
in = erofs_read_metabuf(&m->map->buf, m->inode->i_sb, pos, EROFS_KMAP);
119+
if (IS_ERR(in))
120+
return PTR_ERR(in);
121+
124122
/* it doesn't equal to round_up(..) */
125123
m->nextpackoff = round_down(pos, vcnt << amortizedshift) +
126124
(vcnt << amortizedshift);
127125
big_pcluster = vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_1;
128126
lobits = max(lclusterbits, ilog2(Z_EROFS_LI_D0_CBLKCNT) + 1U);
129127
encodebits = ((vcnt << amortizedshift) - sizeof(__le32)) * 8 / vcnt;
130128
bytes = pos & ((vcnt << amortizedshift) - 1);
131-
132-
in = m->kaddr - bytes;
133-
129+
in -= bytes;
134130
i = bytes >> amortizedshift;
135131

136132
lo = decode_compactedbits(lobits, in, encodebits * i, &type);
@@ -255,10 +251,6 @@ static int z_erofs_load_compact_lcluster(struct z_erofs_maprecorder *m,
255251
amortizedshift = 2;
256252
out:
257253
pos += lcn * (1 << amortizedshift);
258-
m->kaddr = erofs_read_metabuf(&m->map->buf, inode->i_sb,
259-
pos, EROFS_KMAP);
260-
if (IS_ERR(m->kaddr))
261-
return PTR_ERR(m->kaddr);
262254
return unpack_compacted_index(m, amortizedshift, pos, lookahead);
263255
}
264256

0 commit comments

Comments
 (0)