* [PATCH 3/3] fs/btrfs: avoid null pointer dereference if reloc control has not been initialized
@ 2020-12-27 14:55 Defang Bo
2021-01-04 15:11 ` David Sterba
0 siblings, 1 reply; 3+ messages in thread
From: Defang Bo @ 2020-12-27 14:55 UTC (permalink / raw)
To: clm, josef, dsterba; +Cc: linux-btrfs, linux-kernel, Defang Bo
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.
Signed-off-by: Defang Bo <bodefang@126.com>
---
fs/btrfs/relocation.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 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)
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,
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 3/3] fs/btrfs: avoid null pointer dereference if reloc control has not been initialized
2020-12-27 14:55 [PATCH 3/3] fs/btrfs: avoid null pointer dereference if reloc control has not been initialized Defang Bo
@ 2021-01-04 15:11 ` David Sterba
[not found] ` <125f3257.193a.176d084a633.Coremail.bodefang@126.com>
0 siblings, 1 reply; 3+ messages in thread
From: David Sterba @ 2021-01-04 15:11 UTC (permalink / raw)
To: Defang Bo; +Cc: clm, josef, dsterba, linux-btrfs, linux-kernel
On Sun, Dec 27, 2020 at 10:55:31PM +0800, Defang Bo wrote:
> Similar to commmit<389305b2>,
Please use full commit reference like 389305b2aa68 ("btrfs: relocation:
Only remove reloc rb_trees if reloc control has been initialized")
> it turns out that fs_info::reloc_ctl can be NULL ,
Please describe how the NULL can get there.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] fs/btrfs: avoid null pointer dereference if reloc control has not been initialized
[not found] ` <125f3257.193a.176d084a633.Coremail.bodefang@126.com>
@ 2021-01-05 11:38 ` David Sterba
0 siblings, 0 replies; 3+ messages in thread
From: David Sterba @ 2021-01-05 11:38 UTC (permalink / raw)
To: bodefang; +Cc: clm, josef, dsterba, linux-btrfs, linux-kernel
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(!).
On Tue, Jan 05, 2021 at 11:08:42AM +0800, bodefang wrote:
> Similar to commmit<389305b2aa68>(“btrfs: relocation: Only remove reloc rb_trees if reloc control has been initialized”).it turns out that fs_info::reloc_ctl can be NULL in btrfs_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.
>
> Signed-off-by: Defang Bo <bodefang@126.com>Reviewed-by: David Sterba <dsterba@suse.cz>---
Oh and don't add reviewed-by unless it's explicitly stated by the
person.
> 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 --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 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) 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, -- 2.7.4
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> At 2021-01-04 23:11:13, "David Sterba" <dsterba@suse.cz> wrote:
> >On Sun, Dec 27, 2020 at 10:55:31PM +0800, Defang Bo wrote:
> >> Similar to commmit<389305b2>,
> >
> >Please use full commit reference like 389305b2aa68 ("btrfs: relocation:
> >Only remove reloc rb_trees if reloc control has been initialized")
> >
> >> it turns out that fs_info::reloc_ctl can be NULL ,
> >
> >Please describe how the NULL can get there.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-01-05 11:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-27 14:55 [PATCH 3/3] fs/btrfs: avoid null pointer dereference if reloc control has not been initialized Defang Bo
2021-01-04 15:11 ` David Sterba
[not found] ` <125f3257.193a.176d084a633.Coremail.bodefang@126.com>
2021-01-05 11:38 ` [PATCH v2] " David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).