]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdadm: block creation with long names
authorBlazej Kucman <blazej.kucman@intel.com>
Fri, 3 Dec 2021 14:31:15 +0000 (15:31 +0100)
committerJes Sorensen <jsorensen@fb.com>
Wed, 8 Dec 2021 14:39:50 +0000 (09:39 -0500)
This fixes buffer overflows in create_mddev(). It prohibits
creation with not supported names for DDF and native. For IMSM,
mdadm will do silent cut to 16 later.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
mdadm.8.in
mdadm.c
mdadm.h

index 28d773c217799799d4c7653fb783fb51f4860d33..68e100cb409ad2929b56f9b28c17a649b3796a49 100644 (file)
@@ -2186,6 +2186,11 @@ is run, but will be created by
 .I udev
 once the array becomes active.
 
+The max length md-device name is limited to 32 characters.
+Different metadata types have more strict limitation
+(like IMSM where only 16 characters are allowed).
+For that reason, long name could be truncated or rejected, it depends on metadata policy.
+
 As devices are added, they are checked to see if they contain RAID
 superblocks or filesystems.  They are also checked to see if the variance in
 device size exceeds 1%.
diff --git a/mdadm.c b/mdadm.c
index 91e67467edc45eb4c21035ad313bf99f8f51c3a0..26299b2ea7a1f6bc7e1d6a1bd68a1d9e4ba5b72c 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -1359,9 +1359,16 @@ int main(int argc, char *argv[])
                        mdfd = open_mddev(devlist->devname, 1);
                        if (mdfd < 0)
                                exit(1);
-               } else
+               } else {
+                       char *bname = basename(devlist->devname);
+
+                       if (strlen(bname) > MD_NAME_MAX) {
+                               pr_err("Name %s is too long.\n", devlist->devname);
+                               exit(1);
+                       }
                        /* non-existent device is OK */
                        mdfd = open_mddev(devlist->devname, 0);
+               }
                if (mdfd == -2) {
                        pr_err("device %s exists but is not an md array.\n", devlist->devname);
                        exit(1);
diff --git a/mdadm.h b/mdadm.h
index 54567396c2e8c496c6de831e056990c14097d66f..c7268a712c9de3d003902ec333df22046a4d85b3 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -1880,3 +1880,8 @@ enum r0layout {
 #define INVALID_SECTORS 1
 /* And another special number needed for --data_offset=variable */
 #define VARIABLE_OFFSET 3
+
+/**
+ * This is true for native and DDF, IMSM allows 16.
+ */
+#define MD_NAME_MAX 32