Skip to content

Commit a11adf7

Browse files
Kemeng Shitytso
authored andcommitted
ext4: implement filesystem specific alloc_inode in unit test
We expect inode with ext4_info_info type as following: mbt_kunit_init mbt_mb_init ext4_mb_init ext4_mb_init_backend sbi->s_buddy_cache = new_inode(sb); EXT4_I(sbi->s_buddy_cache)->i_disksize = 0; Implement alloc_inode ionde with ext4_inode_info type to avoid out-of-bounds write. Signed-off-by: Kemeng Shi <[email protected]> Reported-by: Guenter Roeck <[email protected]> Tested-by: Guenter Roeck <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 0a46ef2 commit a11adf7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

fs/ext4/mballoc-test.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,31 @@ struct mbt_ext4_super_block {
3030
#define MBT_CTX(_sb) (&MBT_SB(_sb)->mbt_ctx)
3131
#define MBT_GRP_CTX(_sb, _group) (&MBT_CTX(_sb)->grp_ctx[_group])
3232

33+
static struct inode *mbt_alloc_inode(struct super_block *sb)
34+
{
35+
struct ext4_inode_info *ei;
36+
37+
ei = kmalloc(sizeof(struct ext4_inode_info), GFP_KERNEL);
38+
if (!ei)
39+
return NULL;
40+
41+
INIT_LIST_HEAD(&ei->i_orphan);
42+
init_rwsem(&ei->xattr_sem);
43+
init_rwsem(&ei->i_data_sem);
44+
inode_init_once(&ei->vfs_inode);
45+
ext4_fc_init_inode(&ei->vfs_inode);
46+
47+
return &ei->vfs_inode;
48+
}
49+
50+
static void mbt_free_inode(struct inode *inode)
51+
{
52+
kfree(EXT4_I(inode));
53+
}
54+
3355
static const struct super_operations mbt_sops = {
56+
.alloc_inode = mbt_alloc_inode,
57+
.free_inode = mbt_free_inode,
3458
};
3559

3660
static void mbt_kill_sb(struct super_block *sb)

0 commit comments

Comments
 (0)