bcachefs: assign return error when iterating through layout
PATCH 1/1 bcachefs: assign return error when iterating through layout
syzbot reported a null ptr deref in __copy_user [0]
In __bch2_read_super, when a corrupt backup superblock matches the default opts offset, no error is assigned to ret and the freed superblock gets through, possibly being assigned as the best sb in bch2_fs_open and being later dereferenced, causing a fault. Assign EINVALID to ret when iterating through layout.
[0]: https://syzkaller.appspot.com/bug?extid=18a5c5e8a9c856944876
--- fs/bcachefs/super-io.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/bcachefs/super-io.c +3 -1
@@ -796,8 +796,10 @@ static int __bch2_read_super(const char *path, struct bch_opts *opts, i < layout.sb_offset + layout.nr_superblocks; i++) { offset =le64_to_cpu (*i); -if (offset ==opt_get (*opts, sb)) +if (offset ==opt_get (*opts, sb)) { + ret = -BCH_ERR_invalid;continue ; + } ret =read_one_super (sb, offset, &err);if (!ret)
Signature · 1 line
2.43.0
Kent Overstreet
AppliedQuoted 8 lines · Diogo Jahchan Koike
syzbot reported a null ptr deref in
__copy_user[0]In
__bch2_read_super, when a corrupt backup superblock matches the default opts offset, no error is assigned to ret and the freed superblock gets through, possibly being assigned as the best sb inbch2_fs_openand being later dereferenced, causing a fault. Assign EINVALID to ret when iterating through layout.
Quoted 5 lines
[0]: https://syzkaller.appspot.com/bug?extid=18a5c5e8a9c856944876
Reported-by [email protected]Signed-off-by Diogo Jahchan Koike <[email protected]>
Thanks, applied
Quoted 23 lines
--- fs/bcachefs/super-io.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)fs/bcachefs/super-io.c +3
-1@@ -796,8 +796,10 @@ static int __bch2_read_super(const char *path, struct bch_opts *opts, i < layout.sb_offset + layout.nr_superblocks; i++) { offset =le64_to_cpu (*i); -if (offset ==opt_get (*opts, sb)) +if (offset ==opt_get (*opts, sb)) { + ret = -BCH_ERR_invalid;continue ; + } ret =read_one_super (sb, offset, &err);if (!ret)Signature · 1 line
2.43.0