]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
bcachefs: Fix null deref in bch2_ioctl_read_super
authorDan Robertson <dan@dlrobertson.com>
Thu, 13 May 2021 00:54:37 +0000 (20:54 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:03 +0000 (17:09 -0400)
Do not attempt to cleanup the returned value of bch2_device_lookup if
the returned value was an error pointer. We currently check to see if
the returned value is null and run the cleanup otherwise. As a result,
we attempt to run the cleanup on a error pointer.

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

index 34085e32a1599e5e553e72dc93f18775f40ca4c0..b0cbbb70161d04957c96678c4c4ffbe87ab99b74 100644 (file)
@@ -523,7 +523,7 @@ static long bch2_ioctl_read_super(struct bch_fs *c,
        ret = copy_to_user((void __user *)(unsigned long)arg.sb,
                           sb, vstruct_bytes(sb));
 err:
-       if (ca)
+       if (!IS_ERR_OR_NULL(ca))
                percpu_ref_put(&ca->ref);
        mutex_unlock(&c->sb_lock);
        return ret;