Skip to contentSkip to conversation

btrfs: backref: this patch fixes a null pointer dereference bug.

PATCH In review Boleyn Su 3 participants 4 messages Aug 6, 2020 – Aug 7, 2020 1 message not in the archive Btrfs file system

lore
Share & tools
lore

Boleyn Su

author
#0 lore raw

PATCH 1/1 btrfs: backref: this patch fixes a null pointer dereference bug.

The if (!ret) check will always be false and it may result in ret->path being dereferenced while it is a null pointer.

Fixes a37f232b7b65 ("btrfs: backref: introduce the skeleton of btrfs_backref_iter")
Cc Chris Mason <[email protected]>
Cc Josef Bacik <[email protected]>
Cc David Sterba <[email protected]>
Cc Boleyn Su <[email protected]>
---
 fs/btrfs/backref.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/backref.c +1 -1
index ea10f7bc9..ea1c28ccb 100644
@@ -2303,7 +2303,7 @@ struct btrfs_backref_iter *btrfs_backref_iter_alloc(
 		return NULL;
 
 	ret->path = btrfs_alloc_path();
-	if (!ret) {
+	if (!ret->path) {
 		kfree(ret);
 		return NULL;
 	}
Signature · 1 line
2.28.0.163.g6104cc2f0b6-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Boleyn Su

The if (!ret) check will always be false and it may result in ret->path being dereferenced while it is a null pointer.

Fixes a37f232b7b65 ("btrfs: backref: introduce the skeleton of btrfs_backref_iter")
Cc Chris Mason <[email protected]>
Cc Josef Bacik <[email protected]>
Cc David Sterba <[email protected]>
Cc Boleyn Su <[email protected]>
Cc [email protected]> Signed-off-by: Boleyn Su <[email protected]>
Quoted 18 lines
---
 fs/btrfs/backref.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/backref.c +1 -1
index ea10f7bc9..ea1c28ccb 100644
@@ -2303,7 +2303,7 @@ struct btrfs_backref_iter *btrfs_backref_iter_alloc(
 		return NULL;
 
 	ret->path = btrfs_alloc_path();
-	if (!ret) {
+	if (!ret->path) {
 		kfree(ret);
 		return NULL;
 	}
Reviewed-by on v1 1/1
#2 lore raw
In reply to Boleyn Su
Quoted 10 lines · Boleyn Su

The if (!ret) check will always be false and it may result in ret->path being dereferenced while it is a null pointer.

Fixes a37f232b7b65 ("btrfs: backref: introduce the skeleton of btrfs_backref_iter")
Cc Chris Mason <[email protected]>
Cc Josef Bacik <[email protected]>
Cc David Sterba <[email protected]>
Cc Boleyn Su <[email protected]>

Nice catch.

Thanks,
Qu

Quoted 18 lines
---
 fs/btrfs/backref.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/backref.c +1 -1
index ea10f7bc9..ea1c28ccb 100644
@@ -2303,7 +2303,7 @@ struct btrfs_backref_iter *btrfs_backref_iter_alloc(
 		return NULL;
 
 	ret->path = btrfs_alloc_path();
-	if (!ret) {
+	if (!ret->path) {
 		kfree(ret);
 		return NULL;
 	}

A message that is not in the archive (sent off-list or not yet received): CAJkxivDhyn9ZbNyhKgs1KcTjzz_2UFMVKDi0SLkvb=O3iZ4rZA@mail.gmail.com

#4 lore raw
Quoted 3 lines · Boleyn Su

Thanks for the review. BTW, do I need to do anything else or just leave it to you?

If you mean adding the extra reviewed-by tags, no. It's handled by the awesome maintainer David.

But if you mean to find more btrfs bugs, then keep going your awesome work!

Thanks,
Qu

Quoted 53 lines

On Thu, Aug 6, 2020 at 4:04 PM Qu Wenruo <[email protected] <mailto:[email protected]>> wrote:

    On 2020/8/6 下午2:31, Boleyn Su wrote:
    > The `if (!ret)` check will always be false and it may result in
    ret->path
    > being dereferenced while it is a null pointer.
    >
    > Fixes: a37f232b7b65 ("btrfs: backref: introduce the skeleton of
    btrfs_backref_iter")
    > Cc: Chris Mason <[email protected] <mailto:[email protected]>>
    > Cc: Josef Bacik <[email protected] <mailto:[email protected]>>
    > Cc: David Sterba <[email protected] <mailto:[email protected]>>
    > Cc: Boleyn Su <[email protected] <mailto:[email protected]>>
    > Cc: [email protected] <mailto:[email protected]>
    > Signed-off-by: Boleyn Su <[email protected]
    <mailto:[email protected]>>

    Nice catch.

    Reviewed-by: Qu Wenruo <[email protected] <mailto:[email protected]>>

    Thanks,
    Qu
    > ---
    >  fs/btrfs/backref.c | 2 +-
    >  1 file changed, 1 insertion(+), 1 deletion(-)
    >
    > diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
    > index ea10f7bc9..ea1c28ccb 100644
    > --- a/fs/btrfs/backref.c
    > +++ b/fs/btrfs/backref.c
    > @@ -2303,7 +2303,7 @@ struct btrfs_backref_iter
    *btrfs_backref_iter_alloc(
    >               return NULL;
    > 
    >       ret->path = btrfs_alloc_path();
    > -     if (!ret) {
    > +     if (!ret->path) {
    >               kfree(ret);
    >               return NULL;
    >       }
    >
Signature · 4 lines
Boleyn Su (simplified Chinese: 苏蕉; traditional Chinese: 蘇蕉; Pinyin:
Sū Jiāo; Katakana: スージャオ)

My PGP public key is available at boleyn.su/pgp <https://boleyn.su/pgp>.