bcachefs: assign return error when iterating through layout
authorDiogo Jahchan Koike <djahchankoike@gmail.com>
Mon, 23 Sep 2024 22:22:14 +0000 (19:22 -0300)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 28 Sep 2024 01:46:34 +0000 (21:46 -0400)
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

Reported-by: syzbot+18a5c5e8a9c856944876@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=18a5c5e8a9c856944876
Signed-off-by: Diogo Jahchan Koike <djahchankoike@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/super-io.c

index d86d5dae54c9d1bb1f9737e2a1dcebb2329f85a2..b2e914841b5f9656a24d05bd7cfed0f31304099d 100644 (file)
@@ -799,8 +799,10 @@ retry:
             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)