!121 mdmon: fix segfault

From: @fandeyuan 
Reviewed-by: @swf504 
Signed-off-by: @swf504
This commit is contained in:
openeuler-ci-bot 2024-08-31 01:35:19 +00:00 committed by Gitee
commit 91f02b3b79
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 91 additions and 1 deletions

View File

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

View File

@ -1,6 +1,6 @@
Name: mdadm
Version: 4.1
Release: rc2.0.20
Release: rc2.0.21
Summary: The software RAID arrays user manage tools
License: GPLv2+
URL: http://www.kernel.org/pub/linux/utils/raid/mdadm/
@ -38,6 +38,7 @@ Patch6024: 6024-Fix-memory-leak-in-file-Manage.patch
Patch6025: 6025-Manage-fix-check-after-dereference-issue.patch
Patch6026: 6026-Mdmonitor-Fix-segfault.patch
Patch6027: 6027-udev-allow-for-udev-attribute-reading-bug.patch
Patch6028: 6028-mdmon-fix-segfault.patch
BuildRequires: systemd gcc binutils
Requires(post): systemd coreutils
@ -103,6 +104,9 @@ install -d -m 710 %{buildroot}/var/run/mdadm/
%{_mandir}/man*/*
%changelog
* Wed Aug 28 2024 Deyuan Fan <fandeyuan@kylinos.cn> - 4.1-rc2.0.21
- mdmon: fix segfault
* Wed Aug 28 2024 wuguanghao <wuguanghao3@huawei.cn> - 4.1-rc2.0.20
- udev: allow udev attribute reading bug