bcachefs: mount: fix null deref with null devname
authorDan Robertson <dan@dlrobertson.com>
Thu, 10 Jun 2021 11:52:42 +0000 (07:52 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:06 +0000 (17:09 -0400)
 - Fix null deref on mount when given a null device name.
 - Move the dev_name checks to return EINVAL when it is invalid.

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

index 99885fb..efb4673 100644 (file)
@@ -1325,9 +1325,6 @@ static char **split_devs(const char *_dev_name, unsigned *nr)
        char *dev_name = NULL, **devs = NULL, *s;
        size_t i, nr_devs = 0;
 
-       if (strlen(_dev_name) == 0)
-               return NULL;
-
        dev_name = kstrdup(_dev_name, GFP_KERNEL);
        if (!dev_name)
                return NULL;
@@ -1503,6 +1500,9 @@ static struct dentry *bch2_mount(struct file_system_type *fs_type,
        if (ret)
                return ERR_PTR(ret);
 
+       if (!dev_name || strlen(dev_name) == 0)
+               return ERR_PTR(-EINVAL);
+
        devs = split_devs(dev_name, &nr_devs);
        if (!devs)
                return ERR_PTR(-ENOMEM);