|
|
37f2b0 |
From 9b429fc0a4ffd7028b3b336589d38e32fb9045dc Mon Sep 17 00:00:00 2001
|
|
|
37f2b0 |
From: Mateusz Kusiak <mateusz.kusiak@intel.com>
|
|
|
37f2b0 |
Date: Mon, 2 Jan 2023 09:46:21 +0100
|
|
|
37f2b0 |
Subject: [PATCH 77/83] mdmon: fix segfault
|
|
|
37f2b0 |
|
|
|
37f2b0 |
Mdmon crashes if stat2devnm returns null.
|
|
|
37f2b0 |
Use open_mddev to check if device is mddevice and get name using
|
|
|
37f2b0 |
fd2devnm.
|
|
|
37f2b0 |
Refactor container name handling.
|
|
|
37f2b0 |
|
|
|
37f2b0 |
Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com>
|
|
|
37f2b0 |
Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
|
|
|
37f2b0 |
---
|
|
|
37f2b0 |
Makefile | 2 +-
|
|
|
37f2b0 |
mdmon.c | 26 ++++++++++++--------------
|
|
|
37f2b0 |
2 files changed, 13 insertions(+), 15 deletions(-)
|
|
|
37f2b0 |
|
|
|
37f2b0 |
diff --git a/Makefile b/Makefile
|
|
|
37f2b0 |
index ec1f99ed..5eac1a4e 100644
|
|
|
37f2b0 |
--- a/Makefile
|
|
|
37f2b0 |
+++ b/Makefile
|
|
|
37f2b0 |
@@ -160,7 +160,7 @@ SRCS = $(patsubst %.o,%.c,$(OBJS))
|
|
|
37f2b0 |
|
|
|
37f2b0 |
INCL = mdadm.h part.h bitmap.h
|
|
|
37f2b0 |
|
|
|
37f2b0 |
-MON_OBJS = mdmon.o monitor.o managemon.o uuid.o util.o maps.o mdstat.o sysfs.o \
|
|
|
37f2b0 |
+MON_OBJS = mdmon.o monitor.o managemon.o uuid.o util.o maps.o mdstat.o sysfs.o config.o mapfile.o mdopen.o\
|
|
|
37f2b0 |
policy.o lib.o \
|
|
|
37f2b0 |
Kill.o sg_io.o dlink.o ReadMe.o super-intel.o \
|
|
|
37f2b0 |
super-mbr.o super-gpt.o \
|
|
|
37f2b0 |
diff --git a/mdmon.c b/mdmon.c
|
|
|
37f2b0 |
index e9d035eb..ecf52dc8 100644
|
|
|
37f2b0 |
--- a/mdmon.c
|
|
|
37f2b0 |
+++ b/mdmon.c
|
|
|
37f2b0 |
@@ -363,14 +363,14 @@ int main(int argc, char *argv[])
|
|
|
37f2b0 |
}
|
|
|
37f2b0 |
|
|
|
37f2b0 |
if (all == 0 && container_name == NULL) {
|
|
|
37f2b0 |
- if (argv[optind])
|
|
|
37f2b0 |
- container_name = argv[optind];
|
|
|
37f2b0 |
+ if (argv[optind]) {
|
|
|
37f2b0 |
+ container_name = get_md_name(argv[optind]);
|
|
|
37f2b0 |
+ if (!container_name)
|
|
|
37f2b0 |
+ container_name = argv[optind];
|
|
|
37f2b0 |
+ }
|
|
|
37f2b0 |
}
|
|
|
37f2b0 |
|
|
|
37f2b0 |
- if (container_name == NULL)
|
|
|
37f2b0 |
- usage();
|
|
|
37f2b0 |
-
|
|
|
37f2b0 |
- if (argc - optind > 1)
|
|
|
37f2b0 |
+ if (container_name == NULL || argc - optind > 1)
|
|
|
37f2b0 |
usage();
|
|
|
37f2b0 |
|
|
|
37f2b0 |
if (strcmp(container_name, "/proc/mdstat") == 0)
|
|
|
37f2b0 |
@@ -402,21 +402,19 @@ int main(int argc, char *argv[])
|
|
|
37f2b0 |
free_mdstat(mdstat);
|
|
|
37f2b0 |
|
|
|
37f2b0 |
return status;
|
|
|
37f2b0 |
- } else if (strncmp(container_name, "md", 2) == 0) {
|
|
|
37f2b0 |
- int id = devnm2devid(container_name);
|
|
|
37f2b0 |
- if (id)
|
|
|
37f2b0 |
- devnm = container_name;
|
|
|
37f2b0 |
} else {
|
|
|
37f2b0 |
- struct stat st;
|
|
|
37f2b0 |
+ int mdfd = open_mddev(container_name, 1);
|
|
|
37f2b0 |
|
|
|
37f2b0 |
- if (stat(container_name, &st) == 0)
|
|
|
37f2b0 |
- devnm = xstrdup(stat2devnm(&st);;
|
|
|
37f2b0 |
+ if (mdfd < 0)
|
|
|
37f2b0 |
+ return 1;
|
|
|
37f2b0 |
+ devnm = fd2devnm(mdfd);
|
|
|
37f2b0 |
+ close(mdfd);
|
|
|
37f2b0 |
}
|
|
|
37f2b0 |
|
|
|
37f2b0 |
if (!devnm) {
|
|
|
37f2b0 |
pr_err("%s is not a valid md device name\n",
|
|
|
37f2b0 |
container_name);
|
|
|
37f2b0 |
- exit(1);
|
|
|
37f2b0 |
+ return 1;
|
|
|
37f2b0 |
}
|
|
|
37f2b0 |
return mdmon(devnm, dofork && do_fork(), takeover);
|
|
|
37f2b0 |
}
|
|
|
37f2b0 |
--
|
|
|
37f2b0 |
2.38.1
|
|
|
37f2b0 |
|