Skip to content

Commit c84074d

Browse files
Zhiguo Niugregkh
authored andcommitted
f2fs: compress: change the first parameter of page_array_{alloc,free} to sbi
[ Upstream commit 8e2a9b6 ] No logic changes, just cleanup and prepare for fixing the UAF issue in f2fs_free_dic. Signed-off-by: Zhiguo Niu <[email protected]> Signed-off-by: Baocong Liu <[email protected]> Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]> Stable-dep-of: 3986868 ("f2fs: compress: fix UAF of f2fs_inode_info in f2fs_free_dic") Signed-off-by: Sasha Levin <[email protected]>
1 parent 1270983 commit c84074d

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

fs/f2fs/compress.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,18 @@
2323
static struct kmem_cache *cic_entry_slab;
2424
static struct kmem_cache *dic_entry_slab;
2525

26-
static void *page_array_alloc(struct inode *inode, int nr)
26+
static void *page_array_alloc(struct f2fs_sb_info *sbi, int nr)
2727
{
28-
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
2928
unsigned int size = sizeof(struct page *) * nr;
3029

3130
if (likely(size <= sbi->page_array_slab_size))
3231
return f2fs_kmem_cache_alloc(sbi->page_array_slab,
33-
GFP_F2FS_ZERO, false, F2FS_I_SB(inode));
32+
GFP_F2FS_ZERO, false, sbi);
3433
return f2fs_kzalloc(sbi, size, GFP_NOFS);
3534
}
3635

37-
static void page_array_free(struct inode *inode, void *pages, int nr)
36+
static void page_array_free(struct f2fs_sb_info *sbi, void *pages, int nr)
3837
{
39-
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
4038
unsigned int size = sizeof(struct page *) * nr;
4139

4240
if (!pages)
@@ -149,13 +147,13 @@ int f2fs_init_compress_ctx(struct compress_ctx *cc)
149147
if (cc->rpages)
150148
return 0;
151149

152-
cc->rpages = page_array_alloc(cc->inode, cc->cluster_size);
150+
cc->rpages = page_array_alloc(F2FS_I_SB(cc->inode), cc->cluster_size);
153151
return cc->rpages ? 0 : -ENOMEM;
154152
}
155153

156154
void f2fs_destroy_compress_ctx(struct compress_ctx *cc, bool reuse)
157155
{
158-
page_array_free(cc->inode, cc->rpages, cc->cluster_size);
156+
page_array_free(F2FS_I_SB(cc->inode), cc->rpages, cc->cluster_size);
159157
cc->rpages = NULL;
160158
cc->nr_rpages = 0;
161159
cc->nr_cpages = 0;
@@ -622,6 +620,7 @@ static void *f2fs_vmap(struct page **pages, unsigned int count)
622620

623621
static int f2fs_compress_pages(struct compress_ctx *cc)
624622
{
623+
struct f2fs_sb_info *sbi = F2FS_I_SB(cc->inode);
625624
struct f2fs_inode_info *fi = F2FS_I(cc->inode);
626625
const struct f2fs_compress_ops *cops =
627626
f2fs_cops[fi->i_compress_algorithm];
@@ -642,7 +641,7 @@ static int f2fs_compress_pages(struct compress_ctx *cc)
642641
cc->nr_cpages = DIV_ROUND_UP(max_len, PAGE_SIZE);
643642
cc->valid_nr_cpages = cc->nr_cpages;
644643

645-
cc->cpages = page_array_alloc(cc->inode, cc->nr_cpages);
644+
cc->cpages = page_array_alloc(sbi, cc->nr_cpages);
646645
if (!cc->cpages) {
647646
ret = -ENOMEM;
648647
goto destroy_compress_ctx;
@@ -716,7 +715,7 @@ static int f2fs_compress_pages(struct compress_ctx *cc)
716715
if (cc->cpages[i])
717716
f2fs_compress_free_page(cc->cpages[i]);
718717
}
719-
page_array_free(cc->inode, cc->cpages, cc->nr_cpages);
718+
page_array_free(sbi, cc->cpages, cc->nr_cpages);
720719
cc->cpages = NULL;
721720
destroy_compress_ctx:
722721
if (cops->destroy_compress_ctx)
@@ -1340,7 +1339,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
13401339
cic->magic = F2FS_COMPRESSED_PAGE_MAGIC;
13411340
cic->inode = inode;
13421341
atomic_set(&cic->pending_pages, cc->valid_nr_cpages);
1343-
cic->rpages = page_array_alloc(cc->inode, cc->cluster_size);
1342+
cic->rpages = page_array_alloc(sbi, cc->cluster_size);
13441343
if (!cic->rpages)
13451344
goto out_put_cic;
13461345

@@ -1442,13 +1441,13 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
14421441
spin_unlock(&fi->i_size_lock);
14431442

14441443
f2fs_put_rpages(cc);
1445-
page_array_free(cc->inode, cc->cpages, cc->nr_cpages);
1444+
page_array_free(sbi, cc->cpages, cc->nr_cpages);
14461445
cc->cpages = NULL;
14471446
f2fs_destroy_compress_ctx(cc, false);
14481447
return 0;
14491448

14501449
out_destroy_crypt:
1451-
page_array_free(cc->inode, cic->rpages, cc->cluster_size);
1450+
page_array_free(sbi, cic->rpages, cc->cluster_size);
14521451

14531452
for (--i; i >= 0; i--) {
14541453
if (!cc->cpages[i])
@@ -1469,7 +1468,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
14691468
f2fs_compress_free_page(cc->cpages[i]);
14701469
cc->cpages[i] = NULL;
14711470
}
1472-
page_array_free(cc->inode, cc->cpages, cc->nr_cpages);
1471+
page_array_free(sbi, cc->cpages, cc->nr_cpages);
14731472
cc->cpages = NULL;
14741473
return -EAGAIN;
14751474
}
@@ -1499,7 +1498,7 @@ void f2fs_compress_write_end_io(struct bio *bio, struct page *page)
14991498
end_page_writeback(cic->rpages[i]);
15001499
}
15011500

1502-
page_array_free(cic->inode, cic->rpages, cic->nr_rpages);
1501+
page_array_free(sbi, cic->rpages, cic->nr_rpages);
15031502
kmem_cache_free(cic_entry_slab, cic);
15041503
}
15051504

@@ -1640,7 +1639,7 @@ static int f2fs_prepare_decomp_mem(struct decompress_io_ctx *dic,
16401639
if (!allow_memalloc_for_decomp(F2FS_I_SB(dic->inode), pre_alloc))
16411640
return 0;
16421641

1643-
dic->tpages = page_array_alloc(dic->inode, dic->cluster_size);
1642+
dic->tpages = page_array_alloc(F2FS_I_SB(dic->inode), dic->cluster_size);
16441643
if (!dic->tpages)
16451644
return -ENOMEM;
16461645

@@ -1700,7 +1699,7 @@ struct decompress_io_ctx *f2fs_alloc_dic(struct compress_ctx *cc)
17001699
if (!dic)
17011700
return ERR_PTR(-ENOMEM);
17021701

1703-
dic->rpages = page_array_alloc(cc->inode, cc->cluster_size);
1702+
dic->rpages = page_array_alloc(sbi, cc->cluster_size);
17041703
if (!dic->rpages) {
17051704
kmem_cache_free(dic_entry_slab, dic);
17061705
return ERR_PTR(-ENOMEM);
@@ -1721,7 +1720,7 @@ struct decompress_io_ctx *f2fs_alloc_dic(struct compress_ctx *cc)
17211720
dic->rpages[i] = cc->rpages[i];
17221721
dic->nr_rpages = cc->cluster_size;
17231722

1724-
dic->cpages = page_array_alloc(dic->inode, dic->nr_cpages);
1723+
dic->cpages = page_array_alloc(sbi, dic->nr_cpages);
17251724
if (!dic->cpages) {
17261725
ret = -ENOMEM;
17271726
goto out_free;
@@ -1751,6 +1750,7 @@ static void f2fs_free_dic(struct decompress_io_ctx *dic,
17511750
bool bypass_destroy_callback)
17521751
{
17531752
int i;
1753+
struct f2fs_sb_info *sbi = F2FS_I_SB(dic->inode);
17541754

17551755
f2fs_release_decomp_mem(dic, bypass_destroy_callback, true);
17561756

@@ -1762,7 +1762,7 @@ static void f2fs_free_dic(struct decompress_io_ctx *dic,
17621762
continue;
17631763
f2fs_compress_free_page(dic->tpages[i]);
17641764
}
1765-
page_array_free(dic->inode, dic->tpages, dic->cluster_size);
1765+
page_array_free(sbi, dic->tpages, dic->cluster_size);
17661766
}
17671767

17681768
if (dic->cpages) {
@@ -1771,10 +1771,10 @@ static void f2fs_free_dic(struct decompress_io_ctx *dic,
17711771
continue;
17721772
f2fs_compress_free_page(dic->cpages[i]);
17731773
}
1774-
page_array_free(dic->inode, dic->cpages, dic->nr_cpages);
1774+
page_array_free(sbi, dic->cpages, dic->nr_cpages);
17751775
}
17761776

1777-
page_array_free(dic->inode, dic->rpages, dic->nr_rpages);
1777+
page_array_free(sbi, dic->rpages, dic->nr_rpages);
17781778
kmem_cache_free(dic_entry_slab, dic);
17791779
}
17801780

0 commit comments

Comments
 (0)