bcachefs: avoid out-of-bounds in split_devs
authorStijn Tintel <stijn@linux-ipv6.be>
Thu, 13 May 2021 20:08:47 +0000 (23:08 +0300)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:03 +0000 (17:09 -0400)
Calling mount with an empty source string causes an out-of-bounds error
in split_devs. Check the length of the source string to avoid this.

Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/fs.c

index b00f352011321062a96268087c3599ee90b9913d..5eef67358cfb0fa46e80372a63a6822c8443fed6 100644 (file)
@@ -32,6 +32,7 @@
 #include <linux/random.h>
 #include <linux/seq_file.h>
 #include <linux/statfs.h>
+#include <linux/string.h>
 #include <linux/xattr.h>
 
 static struct kmem_cache *bch2_inode_cache;
@@ -1324,6 +1325,9 @@ 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;