Skip to contentSkip to conversation

Add support for escaping device-mapper names (to be in sync with udev whitelist)

PATCH New Peter Rajnoha 1 participant 1 message Oct 7, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add support for escaping device-mapper names (to be in sync with udev whitelist)

This patch restrict device names used in device-mapper to comply with udev whitelist. If not whitelisted, we use an escape mechanism that udev accepts - that is \xNN where NN is a hex value of the character.

(Related rhbz #736486, #740575)

Peter

---
 libdm/ioctl/libdm-iface.c   |    7 ++++
 libdm/ioctl/libdm-targets.h |    1 +
 libdm/libdevmapper.h        |    1 +
 libdm/libdm-common.c        |   67 +++++++++++++++++++++++++++++++++++++++++--
 tools/dmsetup.c             |   11 ++++++-
 5 files changed, 82 insertions(+), 5 deletions(-)
libdm/ioctl/libdm-iface.c +7 -0
index aab6305..4565266 100644
@@ -835,6 +835,13 @@ int dm_task_retry_remove(struct dm_task *dmt)
 	return 1;
 }
 
+int dm_task_name_escape(struct dm_task *dmt)
+{
+	dmt->name_escape = 1;
+
+	return 1;
+}
+
 int dm_task_query_inactive_table(struct dm_task *dmt)
 {
 	dmt->query_inactive_table = 1;
libdm/ioctl/libdm-targets.h +1 -0
index ca08fe8..46c5e88 100644
@@ -64,6 +64,7 @@ struct dm_task {
 	int new_uuid;
 	int secure_data;
 	int retry_remove;
+	int name_escape;
 	int enable_checks;
 
 	char *uuid;
libdm/libdevmapper.h +1 -0
index fdf8943..ae2803e 100644
@@ -192,6 +192,7 @@ int dm_task_query_inactive_table(struct dm_task *dmt);
 int dm_task_suppress_identical_reload(struct dm_task *dmt);
 int dm_task_secure_data(struct dm_task *dmt);
 int dm_task_retry_remove(struct dm_task *dmt);
+int dm_task_name_escape(struct dm_task *dmt);
 
 /*
  * Enable checks for common mistakes such as issuing ioctls in an unsafe order.
libdm/libdm-common.c +64 -3

84 lines not on this page · raw message

tools/dmsetup.c +9 -2
index f35c8a5..41637f5 100644
@@ -130,6 +130,7 @@ enum {
 	MINOR_ARG,
 	MODE_ARG,
 	NAMEPREFIXES_ARG,
+	NONAMEESCAPE_ARG,
 	NOFLUSH_ARG,
 	NOHEADINGS_ARG,
 	NOLOCKFS_ARG,
@@ -608,6 +609,9 @@ static int _create(CMD_ARGS)
 	if (!(dmt = dm_task_create(DM_DEVICE_CREATE)))
 		return 0;
 
+	if (!_switches[NONAMEESCAPE_ARG])
+		dm_task_name_escape(dmt);
+
 	if (!dm_task_set_name(dmt, argv[1]))
 		goto out;
 
@@ -2806,8 +2810,8 @@ static void _usage(FILE *out)
 
 	fprintf(out, "Usage:\n\n");
 	fprintf(out, "dmsetup [--version] [-h|--help [-c|-C|--columns]]\n"
-		"        [--checks] [-v|--verbose [-v|--verbose ...]]\n"
-		"        [-r|--readonly] [--noopencount] [--nolockfs] [--inactive]\n"
+		"        [--checks] [-v|--verbose [-v|--verbose ...]] [-r|--readonly]\n"
+		"        [--nonameescape] [--noopencount] [--nolockfs] [--inactive]\n"
 		"        [--udevcookie [cookie]] [--noudevrules] [--noudevsync] [--verifyudev]\n"
 		"        [-y|--yes] [--readahead [+]<sectors>|auto|none] [--retry]\n"
 		"        [-c|-C|--columns] [-o <fields>] [-O|--sort <sort_fields>]\n"
@@ -3172,6 +3176,7 @@ static int _process_switches(int *argc, char ***argv, const char *dev_dir)
 		{"minor", 1, &ind, MINOR_ARG},
 		{"mode", 1, &ind, MODE_ARG},
 		{"nameprefixes", 0, &ind, NAMEPREFIXES_ARG},
+		{"nonameescape", 0, &ind, NONAMEESCAPE_ARG},
 		{"noflush", 0, &ind, NOFLUSH_ARG},
 		{"noheadings", 0, &ind, NOHEADINGS_ARG},
 		{"nolockfs", 0, &ind, NOLOCKFS_ARG},
@@ -3339,6 +3344,8 @@ static int _process_switches(int *argc, char ***argv, const char *dev_dir)
 			_switches[INACTIVE_ARG]++;
 		if ((ind == NAMEPREFIXES_ARG))
 			_switches[NAMEPREFIXES_ARG]++;
+		if ((ind == NONAMEESCAPE_ARG))
+			_switches[NONAMEESCAPE_ARG]++;
 		if ((ind == NOFLUSH_ARG))
 			_switches[NOFLUSH_ARG]++;
 		if ((ind == NOHEADINGS_ARG))