Skip to content

Commit

Permalink
bcachefs: return err ptr instead of null in read sb clean
Browse files Browse the repository at this point in the history
syzbot reported a null-ptr-deref in bch2_fs_start. [0]

When a sb is marked clear but doesn't have a clean section
bch2_read_superblock_clean returns NULL which PTR_ERR_OR_ZERO
lets through, eventually leading to a null ptr dereference down
the line. Adjust read sb clean to return an ERR_PTR indicating the
invalid clean section.

[0] https://syzkaller.appspot.com/bug?extid=1cecc37d87c4286e5543

Reported-by: [email protected]
Closes: https://syzkaller.appspot.com/bug?extid=1cecc37d87c4286e5543
Signed-off-by: Diogo Jahchan Koike <[email protected]>
Signed-off-by: Kent Overstreet <[email protected]>
  • Loading branch information
Diogo Jahchan Koike authored and Kent Overstreet committed Sep 10, 2024
1 parent 5cf488d commit b72bcc9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion fs/bcachefs/sb-clean.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ struct bch_sb_field_clean *bch2_read_superblock_clean(struct bch_fs *c)
SET_BCH_SB_CLEAN(c->disk_sb.sb, false);
c->sb.clean = false;
mutex_unlock(&c->sb_lock);
return NULL;
return ERR_PTR(-BCH_ERR_invalid_sb_clean);
}

clean = kmemdup(sb_clean, vstruct_bytes(&sb_clean->field),
Expand Down

0 comments on commit b72bcc9

Please sign in to comment.