summaryrefslogtreecommitdiff
path: root/mdadm.c
diff options
context:
space:
mode:
authorBlazej Kucman <blazej.kucman@intel.com>2021-12-03 15:31:15 +0100
committerJes Sorensen <jsorensen@fb.com>2021-12-08 09:39:50 -0500
commitced5fa8b170ad448f4076e24a10c731b5cfb36ce (patch)
tree3d9bb069b988bb06da8445291076efcf31aebde6 /mdadm.c
parentb71de056cec70784ef2727e2febd7a6c88e580db (diff)
downloadmdadm-ced5fa8b170ad448f4076e24a10c731b5cfb36ce.tar.gz
mdadm: block creation with long names
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>
Diffstat (limited to 'mdadm.c')
-rw-r--r--mdadm.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/mdadm.c b/mdadm.c
index 91e6746..26299b2 100644
--- 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);