nilfs2: fix NULL i_assoc_inode dereference in nilfs_mdt_save_to_shadow_map
Ryusuke Konishi
maintainerPATCH 1/1 nilfs2: fix NULL i_assoc_inode dereference in nilfs_mdt_save_to_shadow_map
From: Deepanshu Kartikey <[email protected]>
The DAT inode's btree node cache (i_assoc_inode) is initialized lazily during btree operations. However, nilfs_mdt_save_to_shadow_map() assumes i_assoc_inode is already initialized when copying dirty pages to the shadow map during GC.
If NILFS_IOCTL_CLEAN_SEGMENTS is called immediately after mount before any btree operation has occurred on the DAT inode, i_assoc_inode is NULL leading to a general protection fault.
Fix this by calling nilfs_attach_btree_node_cache() on the DAT inode in nilfs_dat_read() at mount time, ensuring i_assoc_inode is always initialized before any GC operation can use it.
---
Hi Viacheslav,
Please queue this patch first.
It fixes a potential NULL pointer dereference defect that could be triggered (likely most cases are intentionally) via the GC ioctl.
Thanks,
Ryusuke Konishi
fs/nilfs2/dat.c | 3 +++ 1 file changed, 3 insertions(+)
fs/nilfs2/dat.c +3 -0
@@ -524,6 +524,9 @@ int nilfs_dat_read(struct super_block *sb, size_t entry_size,if (err) goto failed; + err =nilfs_attach_btree_node_cache (dat); +if (err) + goto failed; err =nilfs_read_inode_common (dat, raw_inode);if (err) goto failed;
Signature · 1 line
2.43.0
Hi Ryusuke,
Quoted 41 lines · Ryusuke Konishi
From: Deepanshu Kartikey <[email protected]>
The DAT inode's btree node cache (
i_assoc_inode) is initialized lazily during btree operations. However,nilfs_mdt_save_to_shadow_map()assumesi_assoc_inodeis already initialized when copying dirty pages to the shadow map during GC.If
NILFS_IOCTL_CLEAN_SEGMENTSis called immediately after mount before any btree operation has occurred on the DAT inode,i_assoc_inodeis NULL leading to a general protection fault.Fix this by calling
nilfs_attach_btree_node_cache()on the DAT inode innilfs_dat_read()at mount time, ensuringi_assoc_inodeis always initialized before any GC operation can use it.Reported-by [email protected]Tested-by [email protected]Fixes e897be17a441 ("nilfs2: fix lockdep warnings in page operations for btree nodes")Signed-off-by Deepanshu Kartikey <[email protected]>Signed-off-by Ryusuke Konishi <[email protected]>---
Hi Viacheslav,Please queue this patch first.
It fixes a potential NULL pointer dereference defect that could be triggered (likely most cases are intentionally) via the GC ioctl.
Thanks,
Ryusuke Konishifs/nilfs2/dat.c | 3 +++ 1 file changed, 3 insertions(+)fs/nilfs2/dat.c +0
-0
fs/nilfs2/dat.c int nilfs_dat_read(struct super_block *sb, size_t entry_size, · line 532
Quoted 9 lines
fs/nilfs2/dat.c +3
-0@@ -524,6 +524,9 @@ int nilfs_dat_read(struct super_block *sb, size_t entry_size,if (err) goto failed; + err =nilfs_attach_btree_node_cache (dat); +if (err) + goto failed; err =nilfs_read_inode_common (dat, raw_inode);if (err) goto failed;
Applied on for-next branch of NILFS2 git tree.
Thanks,
Slava.