bcachefs: Fix possible null deref on mount
authorDan Robertson <dan@dlrobertson.com>
Wed, 12 May 2021 18:07:57 +0000 (14:07 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:03 +0000 (17:09 -0400)
Ensure that the block device pointer in a superblock handle is not
null before dereferencing it in bch2_dev_to_fs. The block device pointer
may be null when mounting a new bcachefs filesystem given another mounted
bcachefs filesystem exists that has at least one device that is offline.

Signed-off-by: Dan Robertson <dan@dlrobertson.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/super.c

index 9065e264c5675d7cab65b8b19ad558571bb9c3ca..71493b5ff6951d5e9ca30183ef13f417866a6f43 100644 (file)
@@ -117,7 +117,7 @@ struct bch_fs *bch2_dev_to_fs(dev_t dev)
 
        list_for_each_entry(c, &bch_fs_list, list)
                for_each_member_device_rcu(ca, c, i, NULL)
-                       if (ca->disk_sb.bdev->bd_dev == dev) {
+                       if (ca->disk_sb.bdev && ca->disk_sb.bdev->bd_dev == dev) {
                                closure_get(&c->cl);
                                goto found;
                        }