fs/btrfs: avoid null pointer dereference if reloc control has not been initialized
PATCH 3/3 fs/btrfs: avoid null pointer dereference if reloc control has not been initialized
Similar to commmit<389305b2>, it turns out that fs_info::reloc_ctl can be NULL , so there should be a check for rc to prevent null pointer dereference.
--- fs/btrfs/relocation.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/btrfs/relocation.c +6 -0
@@ -626,6 +626,9 @@ static int __must_check __add_reloc_root(struct btrfs_root *root)struct mapping_node *node;struct reloc_control *rc = fs_info->reloc_ctl; +if (!rc) +return 0 ; + node =kmalloc (sizeof (*node),GFP_NOFS );if (!node)return -ENOMEM ;
@@ -703,6 +706,9 @@ static int __update_reloc_root(struct btrfs_root *root)struct rb_node *rb_node;struct mapping_node *node =NULL ;struct reloc_control *rc = fs_info->reloc_ctl; + +if (!rc) +return 0 ;spin_lock (&rc->reloc_root_tree.lock); rb_node = rb_simple_search(&rc->reloc_root_tree.rb_root,
Signature · 1 line
2.7.4
Quoted 1 line · Defang Bo
Similar to commmit<389305b2>,
Please use full commit reference like 389305b2aa68 ("btrfs: relocation:
Only remove reloc rb_trees if reloc control has been initialized")
Quoted 1 line
it turns out that
fs_info::reloc_ctlcan be NULL ,
Please describe how the NULL can get there.
A message that is not in the archive (sent off-list or not yet received): [email protected]
I'm keeping the rest of the mail as I received it, it's completely garbled and would need manual reformatting. The changelog and even the diff are completely on one line(!).
Quoted 3 lines · bodefang
Similar to commmit<389305b2aa68>(“btrfs: relocation: Only remove reloc
rb_treesif reloc control has been initialized”).it turns out thatfs_info::reloc_ctlcan be NULL inbtrfs_recover_relocation()as we allocate relocation control after allreloc roots have been verified.,so there should be a check for rc to prevent null pointer dereference.
Oh and don't add reviewed-by unless it's explicitly stated by the person.
Quoted 31 lines
Changes since v1:
- More accurate description for this patch to describe how the NULL can get there.
---
---fs/btrfs/relocation.c| 6 ++++++ 1 file changed, 6 insertions(+) diff --gita/fs/btrfs/relocation.cb/fs/btrfs/relocation.cindex 3602806..ca03571 100644 ---a/fs/btrfs/relocation.c+++b/fs/btrfs/relocation.c@@ -626,6 +626,9 @@ static int__must_check__add_reloc_root(struct btrfs_root *root)structmapping_node*node; structreloc_control*rc =fs_info->reloc_ctl; + if (!rc) + return 0; + node =kmalloc(sizeof(*node), GFP_NOFS); if (!node) return-ENOMEM; @@ -703,6 +706,9 @@ static int__update_reloc_root(struct btrfs_root *root)structrb_node*rb_node; structmapping_node*node = NULL; structreloc_control*rc =fs_info->reloc_ctl; + + if (!rc) + return 0;spin_lock(&rc->reloc_root_tree.lock);rb_node= rb_simple_search(&rc->reloc_root_tree.rb_root, -- 2.7.4Quoted 9 lines · David Sterba
Quoted 1 line · Defang Bo
Similar to commmit<389305b2>,
Please use full commit reference like
389305b2aa68("btrfs: relocation:
Only remove relocrb_treesif reloc control has been initialized")Quoted 1 line
it turns out that
fs_info::reloc_ctlcan be NULL ,Please describe how the NULL can get there.