提交 e15e6869 编写于 作者: Y Yu Kuai 提交者: Jialin Zhang

eulerfs: add error handling for nv_init()

hulk inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I78RUK
CVE: NA

--------------------------------

Currently nv_init() doesn't handle errors, null-ptr-dereference will be
triggered if errors occur.
Signed-off-by: NYu Kuai <yukuai3@huawei.com>
Reviewed-by: NHou Tao <houtao1@huawei.com>
Signed-off-by: NJialin Zhang <zhangjialin11@huawei.com>
上级 2eb22263
...@@ -525,7 +525,7 @@ void nv_fini(struct super_block *sb) ...@@ -525,7 +525,7 @@ void nv_fini(struct super_block *sb)
kfree(sbi->gpool); kfree(sbi->gpool);
} }
void nv_init(struct super_block *sb, bool init) int nv_init(struct super_block *sb, bool init)
{ {
struct eufs_sb_info *sbi = EUFS_SB(sb); struct eufs_sb_info *sbi = EUFS_SB(sb);
struct mem_pool *ppool; struct mem_pool *ppool;
...@@ -533,6 +533,9 @@ void nv_init(struct super_block *sb, bool init) ...@@ -533,6 +533,9 @@ void nv_init(struct super_block *sb, bool init)
/* allocate pools */ /* allocate pools */
sbi->gpool = kmalloc(sizeof(struct mem_pool), GFP_KERNEL); sbi->gpool = kmalloc(sizeof(struct mem_pool), GFP_KERNEL);
if (!sbi->gpool)
return -ENOMEM;
INIT_LIST_HEAD(&sbi->gpool->large_list); INIT_LIST_HEAD(&sbi->gpool->large_list);
INIT_LIST_HEAD(&sbi->gpool->page_list); INIT_LIST_HEAD(&sbi->gpool->page_list);
INIT_LIST_HEAD(&sbi->gpool->line4_list); INIT_LIST_HEAD(&sbi->gpool->line4_list);
...@@ -543,6 +546,9 @@ void nv_init(struct super_block *sb, bool init) ...@@ -543,6 +546,9 @@ void nv_init(struct super_block *sb, bool init)
sbi->gpool->nlines = 0; sbi->gpool->nlines = 0;
sbi->rest_pool = kmalloc(sizeof(struct mem_pool), GFP_KERNEL); sbi->rest_pool = kmalloc(sizeof(struct mem_pool), GFP_KERNEL);
if (!sbi->rest_pool)
goto err_rest_pool;
INIT_LIST_HEAD(&sbi->rest_pool->large_list); INIT_LIST_HEAD(&sbi->rest_pool->large_list);
INIT_LIST_HEAD(&sbi->rest_pool->page_list); INIT_LIST_HEAD(&sbi->rest_pool->page_list);
INIT_LIST_HEAD(&sbi->rest_pool->line4_list); INIT_LIST_HEAD(&sbi->rest_pool->line4_list);
...@@ -554,6 +560,9 @@ void nv_init(struct super_block *sb, bool init) ...@@ -554,6 +560,9 @@ void nv_init(struct super_block *sb, bool init)
sbi->rest_pool->nlines = 0; sbi->rest_pool->nlines = 0;
sbi->ppool = alloc_percpu(struct mem_pool); sbi->ppool = alloc_percpu(struct mem_pool);
if (!sbi->ppool)
goto err_ppool;
for_each_online_cpu(cpu) { for_each_online_cpu(cpu) {
ppool = per_cpu_ptr(sbi->ppool, cpu); ppool = per_cpu_ptr(sbi->ppool, cpu);
INIT_LIST_HEAD(&ppool->large_list); INIT_LIST_HEAD(&ppool->large_list);
...@@ -568,6 +577,15 @@ void nv_init(struct super_block *sb, bool init) ...@@ -568,6 +577,15 @@ void nv_init(struct super_block *sb, bool init)
} }
partition(sb, init); partition(sb, init);
return 0;
err_ppool:
kfree(sbi->rest_pool);
sbi->rest_pool = NULL;
err_rest_pool:
kfree(sbi->gpool);
sbi->gpool = NULL;
return -ENOMEM;
} }
static int cut_from_list_remaining(struct list_head *head, int remaining, static int cut_from_list_remaining(struct list_head *head, int remaining,
......
...@@ -134,7 +134,7 @@ int nvmalloc_pre(struct super_block *sb, struct alloc_batch *ab, size_t count, ...@@ -134,7 +134,7 @@ int nvmalloc_pre(struct super_block *sb, struct alloc_batch *ab, size_t count,
size_t size); size_t size);
void *nvmalloc(struct super_block *sb, size_t size, u8 tag, bool nonblocking); void *nvmalloc(struct super_block *sb, size_t size, u8 tag, bool nonblocking);
void nvfree(struct super_block *sb, void *ptr, bool rest); void nvfree(struct super_block *sb, void *ptr, bool rest);
void nv_init(struct super_block *sb, bool init); int nv_init(struct super_block *sb, bool init);
void nv_fini(struct super_block *sb); void nv_fini(struct super_block *sb);
void eufs_get_layout(struct super_block *sb, bool init); void eufs_get_layout(struct super_block *sb, bool init);
......
...@@ -332,7 +332,9 @@ static struct eufs_inode *eufs_init(struct super_block *sb, unsigned long size) ...@@ -332,7 +332,9 @@ static struct eufs_inode *eufs_init(struct super_block *sb, unsigned long size)
sbi->s_crash_ver = 1; sbi->s_crash_ver = 1;
super->s_crash_ver = cpu_to_le64(1); super->s_crash_ver = cpu_to_le64(1);
nv_init(sb, true); if (nv_init(sb, true))
return ERR_PTR(-ENOMEM);
super->s_page_map = cpu_to_le64(p2o(sb, sbi->page_map)); super->s_page_map = cpu_to_le64(p2o(sb, sbi->page_map));
super->s_mtime = 0; super->s_mtime = 0;
...@@ -478,7 +480,9 @@ static int eufs_fill_super(struct super_block *sb, void *data, int silent) ...@@ -478,7 +480,9 @@ static int eufs_fill_super(struct super_block *sb, void *data, int silent)
eufs_pbarrier(); eufs_pbarrier();
} }
nv_init(sb, false); err = nv_init(sb, false);
if (err)
goto out;
root_pi = (struct eufs_inode *)s2p(sb, super->s_root_pi); root_pi = (struct eufs_inode *)s2p(sb, super->s_root_pi);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册