aba27b5983
Fix coverity issue 34533 and /dev/md symlink not created for second RAID container issue 50776 Resolves: RHEL-34533, RHEL50776 Signed-off-by: Xiao Ni <xni@redhat.com>
159 lines
5.0 KiB
Diff
159 lines
5.0 KiB
Diff
From 998544c198c156db027a6e4f1b201910b138041e Mon Sep 17 00:00:00 2001
|
|
From: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
|
|
Date: Mon, 15 Jul 2024 12:29:24 +0200
|
|
Subject: [PATCH 126/157] mdadm: do not allow leading dot in MD device name
|
|
|
|
Do not allow to use '.' on first place for named MD device.
|
|
Having leading dot might be confusing, MD device cannot be hidden.
|
|
It also removes possibility to create md device with name '.'.
|
|
|
|
Additionally, code optimalizations are done.
|
|
|
|
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
|
|
---
|
|
config.c | 75 +++++++++++++++++++++++++++++++-------------------------
|
|
1 file changed, 41 insertions(+), 34 deletions(-)
|
|
|
|
diff --git a/config.c b/config.c
|
|
index cd2379bd..6ea905f3 100644
|
|
--- a/config.c
|
|
+++ b/config.c
|
|
@@ -188,8 +188,36 @@ inline void ident_init(struct mddev_ident *ident)
|
|
ident->uuid_set = 0;
|
|
}
|
|
|
|
+/** ident_check_name() - helper function to verify name.
|
|
+ * @name: name to check.
|
|
+ * @prop_name: the name of the property it is validated against, used for logging.
|
|
+ * @cmdline: context dependent actions.
|
|
+ *
|
|
+ * @name must follow name's criteria, be POSIX compatible and does not have leading dot.
|
|
+ */
|
|
+static mdadm_status_t ident_check_name(const char *name, const char *prop_name, const bool cmdline)
|
|
+{
|
|
+ if (!is_string_lq(name, MD_NAME_MAX + 1)) {
|
|
+ ident_log(prop_name, name, "Too long or empty", cmdline);
|
|
+ return MDADM_STATUS_ERROR;
|
|
+ }
|
|
+
|
|
+ if (*name == '.') {
|
|
+ /* MD device should not be considered as hidden. */
|
|
+ ident_log(prop_name, name, "Leading dot forbidden", cmdline);
|
|
+ return MDADM_STATUS_ERROR;
|
|
+ }
|
|
+
|
|
+ if (!is_name_posix_compatible(name)) {
|
|
+ ident_log(prop_name, name, "Not POSIX compatible", cmdline);
|
|
+ return MDADM_STATUS_ERROR;
|
|
+ }
|
|
+
|
|
+ return MDADM_STATUS_SUCCESS;
|
|
+}
|
|
+
|
|
/**
|
|
- * _ident_set_devname()- verify devname and set it in &mddev_ident.
|
|
+ * _ident_set_devname() - verify devname and set it in &mddev_ident.
|
|
* @ident: pointer to &mddev_ident.
|
|
* @devname: devname to be set.
|
|
* @cmdline: context dependent actions. If set, ignore keyword is not allowed.
|
|
@@ -202,8 +230,7 @@ inline void ident_init(struct mddev_ident *ident)
|
|
* /dev/md/{name}
|
|
* {name}
|
|
*
|
|
- * {name} must follow name's criteria and be POSIX compatible.
|
|
- * If criteria passed, duplicate memory and set devname in @ident.
|
|
+ * If verification passed, duplicate memory and set devname in @ident.
|
|
*
|
|
* Return: %MDADM_STATUS_SUCCESS or %MDADM_STATUS_ERROR.
|
|
*/
|
|
@@ -216,6 +243,7 @@ mdadm_status_t _ident_set_devname(struct mddev_ident *ident, const char *devname
|
|
static const char named_dev_pref[] = DEV_NUM_PREF "_";
|
|
static const int named_dev_pref_size = sizeof(named_dev_pref) - 1;
|
|
const char *prop_name = "devname";
|
|
+ mdadm_status_t ret;
|
|
const char *name;
|
|
|
|
if (ident->devname) {
|
|
@@ -242,53 +270,40 @@ mdadm_status_t _ident_set_devname(struct mddev_ident *ident, const char *devname
|
|
else
|
|
name = devname;
|
|
|
|
- if (is_name_posix_compatible(name) == false) {
|
|
- ident_log(prop_name, name, "Not POSIX compatible", cmdline);
|
|
- return MDADM_STATUS_ERROR;
|
|
- }
|
|
-
|
|
- if (is_string_lq(name, MD_NAME_MAX + 1) == false) {
|
|
- ident_log(prop_name, devname, "Invalid length", cmdline);
|
|
- return MDADM_STATUS_ERROR;
|
|
- }
|
|
+ ret = ident_check_name(name, prop_name, cmdline);
|
|
+ if (ret)
|
|
+ return ret;
|
|
pass:
|
|
ident->devname = xstrdup(devname);
|
|
return MDADM_STATUS_SUCCESS;
|
|
}
|
|
|
|
/**
|
|
- * _ident_set_name()- set name in &mddev_ident.
|
|
+ * _ident_set_name() - set name in &mddev_ident.
|
|
* @ident: pointer to &mddev_ident.
|
|
* @name: name to be set.
|
|
- * @cmdline: context dependent actions.
|
|
*
|
|
* If criteria passed, set name in @ident.
|
|
* Note: name is not used by config file, it for cmdline only.
|
|
*
|
|
* Return: %MDADM_STATUS_SUCCESS or %MDADM_STATUS_ERROR.
|
|
*/
|
|
-static mdadm_status_t _ident_set_name(struct mddev_ident *ident, const char *name,
|
|
- const bool cmdline)
|
|
+mdadm_status_t ident_set_name(struct mddev_ident *ident, const char *name)
|
|
{
|
|
assert(name);
|
|
assert(ident);
|
|
|
|
const char *prop_name = "name";
|
|
+ mdadm_status_t ret;
|
|
|
|
if (ident->name[0]) {
|
|
- ident_log(prop_name, name, "Already defined", cmdline);
|
|
+ ident_log(prop_name, name, "Already defined", true);
|
|
return MDADM_STATUS_ERROR;
|
|
}
|
|
|
|
- if (is_string_lq(name, MD_NAME_MAX + 1) == false) {
|
|
- ident_log(prop_name, name, "Too long or empty", cmdline);
|
|
- return MDADM_STATUS_ERROR;
|
|
- }
|
|
-
|
|
- if (is_name_posix_compatible(name) == false) {
|
|
- ident_log(prop_name, name, "Not POSIX compatible", cmdline);
|
|
- return MDADM_STATUS_ERROR;
|
|
- }
|
|
+ ret = ident_check_name(name, prop_name, true);
|
|
+ if (ret)
|
|
+ return ret;
|
|
|
|
snprintf(ident->name, MD_NAME_MAX + 1, "%s", name);
|
|
return MDADM_STATUS_SUCCESS;
|
|
@@ -302,14 +317,6 @@ mdadm_status_t ident_set_devname(struct mddev_ident *ident, const char *name)
|
|
return _ident_set_devname(ident, name, true);
|
|
}
|
|
|
|
-/**
|
|
- * ident_set_name()- exported, for cmdline.
|
|
- */
|
|
-mdadm_status_t ident_set_name(struct mddev_ident *ident, const char *name)
|
|
-{
|
|
- return _ident_set_name(ident, name, true);
|
|
-}
|
|
-
|
|
struct conf_dev {
|
|
struct conf_dev *next;
|
|
char *name;
|
|
--
|
|
2.41.0
|
|
|