diff options
author | Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> | 2023-06-01 09:27:50 +0200 |
---|---|---|
committer | Jes Sorensen <jes@trained-monkey.org> | 2023-10-26 23:28:23 +0200 |
commit | e2eb503bd797908f515b58428b274f1ba6a05349 (patch) | |
tree | 88ef87abb98fe35d6e111b332536423aab7592d2 /config.c | |
parent | mdadm: define ident_set_devname() (diff) | |
download | mdadm-e2eb503bd797908f515b58428b274f1ba6a05349.tar.xz mdadm-e2eb503bd797908f515b58428b274f1ba6a05349.zip |
mdadm: Follow POSIX Portable Character Set
When the user creates a device with a name that contains whitespace,
mdadm timeouts and throws an error. This issue is caused by udev, which
truncates /dev/md link until the first whitespace.
This patch introduces prohibition of characters other than A-Za-z0-9.-_
in the device name. Also, it prohibits using leading "-" in device name,
so name won't be confused with cli parameter.
Set of allowed characters is taken from POSIX 3.280 Portable Character
Set. Also, device name length now is limited to NAME_MAX.
In some places, there are other requirements for string length (e.g. size
up to MD_NAME_MAX for device name). This routine is made to follow POSIX
and other, more strict limitations should be checked separately.
We are aware of the risk of regression in exceptional cases (as
escape_devname function is removed) that should be fixed by updating
the array name.
The POSIX validation is added for:
- 'name' parameter in every mode.
- first devlist entry, for Build, Create, Assemble, Manage, Grow.
- config entries, both devname and "name=".
Additionally, some manual cleanups are made.
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -199,9 +199,9 @@ inline void ident_init(struct mddev_ident *ident) * /dev/md_d{number} (legacy) * /dev/md_{name} * /dev/md/{name} - * {name} - anything that doesn't start from '/' or '<'. + * {name} * - * {name} must follow name's criteria. + * {name} must follow name's criteria and be POSIX compatible. * If criteria passed, duplicate memory and set devname in @ident. * * Return: %MDADM_STATUS_SUCCESS or %MDADM_STATUS_ERROR. @@ -241,8 +241,8 @@ mdadm_status_t _ident_set_devname(struct mddev_ident *ident, const char *devname else name = devname; - if (*name == '/' || *name == '<') { - ident_log(prop_name, devname, "Cannot be started from \'/\' or \'<\'", cmdline); + if (is_name_posix_compatible(name) == false) { + ident_log(prop_name, name, "Not POSIX compatible", cmdline); return MDADM_STATUS_ERROR; } @@ -283,6 +283,11 @@ static mdadm_status_t _ident_set_name(struct mddev_ident *ident, const char *nam return MDADM_STATUS_ERROR; } + if (is_name_posix_compatible(name) == false) { + ident_log(prop_name, name, "Not POSIX compatible", cmdline); + return MDADM_STATUS_ERROR; + } + snprintf(ident->name, MD_NAME_MAX + 1, "%s", name); return MDADM_STATUS_SUCCESS; } |