Commit 30c97ad1 authored by zhangyi (F)'s avatar zhangyi (F) Committed by ZhaoLong Wang
Browse files

jffs2: move jffs2_init_inode_info() just after allocating inode

hulk inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I8TC11


CVE: NA

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

After commit 4fdcfab5 ("jffs2: fix use-after-free on symlink
traversal"), it expose a freeing uninitialized memory problem due to
this commit move the operaion of freeing f->target to
jffs2_i_callback(), which may not be initialized in some error path of
allocating jffs2 inode (eg: jffs2_iget()->iget_locked()->
destroy_inode()->..->jffs2_i_callback()->kfree(f->target)).

Fix this by initialize the jffs2_inode_info just after allocating it.

Signed-off-by: default avatarzhangyi (F) <yi.zhang@huawei.com>

Conflicts:
	fs/jffs2/super.c

Signed-off-by: default avatarZhaoLong Wang <wangzhaolong1@huawei.com>
parent 45c76c86
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -271,7 +271,6 @@ struct inode *jffs2_iget(struct super_block *sb, unsigned long ino)
	f = JFFS2_INODE_INFO(inode);
	c = JFFS2_SB_INFO(inode->i_sb);

	jffs2_init_inode_info(f);
	mutex_lock(&f->sem);

	ret = jffs2_do_read_inode(c, f, inode->i_ino, &latest_node);
@@ -439,7 +438,6 @@ struct inode *jffs2_new_inode (struct inode *dir_i, umode_t mode, struct jffs2_r
		return ERR_PTR(-ENOMEM);

	f = JFFS2_INODE_INFO(inode);
	jffs2_init_inode_info(f);
	mutex_lock(&f->sem);

	memset(ri, 0, sizeof(*ri));
+2 −0
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@ static struct inode *jffs2_alloc_inode(struct super_block *sb)
	f = alloc_inode_sb(sb, jffs2_inode_cachep, GFP_KERNEL);
	if (!f)
		return NULL;

	jffs2_init_inode_info(f);
	return &f->vfs_inode;
}