Commit 025c55a4 authored by Diogo Jahchan Koike's avatar Diogo Jahchan Koike Committed by Kent Overstreet

bcachefs: return err ptr instead of null in read sb clean

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: syzbot+1cecc37d87c4286e5543@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=1cecc37d87c4286e5543Signed-off-by: default avatarDiogo Jahchan Koike <djahchankoike@gmail.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent abb43dd6
...@@ -155,7 +155,7 @@ struct bch_sb_field_clean *bch2_read_superblock_clean(struct bch_fs *c) ...@@ -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); SET_BCH_SB_CLEAN(c->disk_sb.sb, false);
c->sb.clean = false; c->sb.clean = false;
mutex_unlock(&c->sb_lock); mutex_unlock(&c->sb_lock);
return NULL; return ERR_PTR(-BCH_ERR_invalid_sb_clean);
} }
clean = kmemdup(sb_clean, vstruct_bytes(&sb_clean->field), clean = kmemdup(sb_clean, vstruct_bytes(&sb_clean->field),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment