Skip to contentSkip to conversation

Rework uevent filtering and merging

PATCH In review [email protected] 2 participants 20 messages Apr 4, 2022 Device mapper

lore
Share & tools
lore
maintainer Reviewed-by on v2 5/15
#6 lore raw

Re: [dm-devel] [PATCH v2 05/15] multipathd: reconfigure: disallow changing uid_attrs

Quoted 5 lines · On Mon, Apr 04, 2022 at 07:04:47PM +0200, [email protected] wrote:

uevent merging by WWID relies on the uid_attrs config option. As we drop struct config between calls to uevent_merge(), we must be sure that the WWID is not changed in reconfigure().

Quoted 101 lines
---
 multipath/multipath.conf.5 |  2 ++
 multipathd/main.c          | 59 ++++++++++++++++++++++++++++++++------
 2 files changed, 52 insertions(+), 9 deletions(-)
multipath/multipath.conf.5 +2 -0
index 605b46e..a9cd776 100644
@@ -264,6 +264,8 @@ If this option is configured and matches the device
 node name of a device, it overrides any other configured  methods for
 determining the WWID for this device.
 .PP
+This option cannot be changed during runtime with the multipathd \fBreconfigure\fR command.
+.PP
 The default is: \fB<unset>\fR. To enable uevent merging, set it e.g. to
 \(dqsd:ID_SERIAL dasd:ID_UID nvme:ID_WWN\(dq.
 .RE
multipathd/main.c +50 -9
index 13b1948..6808ad1 100644
@@ -2835,11 +2835,58 @@ void rcu_free_config(struct rcu_head *head)
 	free_config(conf);
 }
 
+static bool reconfigure_check_uid_attrs(const struct _vector *old_attrs,
+					const struct _vector *new_attrs)
+{
+	int i;
+	char *old;
+
+	if (VECTOR_SIZE(old_attrs) != VECTOR_SIZE(new_attrs))
+		return true;
+
+	vector_foreach_slot(old_attrs, old, i) {
+		char *new = VECTOR_SLOT(new_attrs, i);
+
+		if (strcmp(old, new))
+			return true;
+	}
+
+	return false;
+}
+
+static void reconfigure_check(struct config *old, struct config *new)
+{
+	int old_marginal_pathgroups;
+
+	old_marginal_pathgroups = old->marginal_pathgroups;
+	if ((old_marginal_pathgroups == MARGINAL_PATHGROUP_FPIN) !=
+	    (new->marginal_pathgroups == MARGINAL_PATHGROUP_FPIN)) {
+		condlog(1, "multipathd must be restarted to turn %s fpin marginal paths",
+			(old_marginal_pathgroups == MARGINAL_PATHGROUP_FPIN)?
+			"off" : "on");
+		new->marginal_pathgroups = old_marginal_pathgroups;
+	}
+
+	if (reconfigure_check_uid_attrs(&old->uid_attrs, &new->uid_attrs)) {
+		int i;
+		void *ptr;
+
+		condlog(1, "multipathd must be restarted to change uid_attrs, keeping old values");
+		vector_foreach_slot(&new->uid_attrs, ptr, i)
+			free(ptr);
+		vector_reset(&new->uid_attrs);
+		new->uid_attrs = old->uid_attrs;
+
+		/* avoid uid_attrs being freed in rcu_free_config() */
+		old->uid_attrs.allocated = 0;
+		old->uid_attrs.slot = NULL;
+	}
+}
+
 static int
 reconfigure (struct vectors *vecs, enum force_reload_types reload_type)
 {
 	struct config * old, *conf;
-	int old_marginal_pathgroups;
 
 	conf = load_config(DEFAULT_CONFIGFILE);
 	if (!conf)
@@ -2870,14 +2917,8 @@ reconfigure (struct vectors *vecs, enum force_reload_types reload_type)
 	uxsock_timeout = conf->uxsock_timeout;
 
 	old = rcu_dereference(multipath_conf);
-	old_marginal_pathgroups = old->marginal_pathgroups;
-	if ((old_marginal_pathgroups == MARGINAL_PATHGROUP_FPIN) !=
-	    (conf->marginal_pathgroups == MARGINAL_PATHGROUP_FPIN)) {
-		condlog(1, "multipathd must be restarted to turn %s fpin marginal paths",
-			(old_marginal_pathgroups == MARGINAL_PATHGROUP_FPIN)?
-			"off" : "on");
-		conf->marginal_pathgroups = old_marginal_pathgroups;
-	}
+	reconfigure_check(old, conf);
+
 	conf->sequence_nr = old->sequence_nr + 1;
 	rcu_assign_pointer(multipath_conf, conf);
 	call_rcu(&old->rcu, rcu_free_config);
Signature · 1 line
2.35.1

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

maintainer Reviewed-by on v2 14/15
#16 lore raw

Re: [dm-devel] [PATCH v2 14/15] libmultipath: apply_format(): prevent buffer overflow

Quoted 1 line · On Mon, Apr 04, 2022 at 07:04:56PM +0200, [email protected] wrote:

Potential overflow found by coverity (CID 376918).

Quoted 19 lines
---
 libmultipath/callout.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libmultipath/callout.c +1 -1
index dac088c..57c3481 100644
@@ -160,7 +160,7 @@ int apply_format(char * string, char * cmd, struct path * pp)
 	myfree = CALLOUT_MAX_SIZE;
 
 	if (!pos) {
-		strcpy(dst, string);
+		strlcpy(dst, string, CALLOUT_MAX_SIZE);
 		return 0;
 	}
 
Signature · 1 line
2.35.1

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

maintainer Reviewed-by on v2 15/15
#18 lore raw

Re: [dm-devel] [PATCH v2 15/15] libmultipath: avoid memory leak with uid_attrs

Quoted 3 lines · On Mon, Apr 04, 2022 at 07:04:57PM +0200, [email protected] wrote:

Free all vector elements when freeing uid_attrs.

Quoted 48 lines
---
 libmultipath/config.c | 5 +++++
 libmultipath/dict.c   | 5 +++++
 2 files changed, 10 insertions(+)
libmultipath/config.c +5 -0
index 7346c37..bfaf041 100644
@@ -656,6 +656,9 @@ static struct config *alloc_config (void)
 
 static void _uninit_config(struct config *conf)
 {
+	void *ptr;
+	int i;
+
 	if (!conf)
 		conf = &__internal_config;
 
@@ -668,6 +671,8 @@ static void _uninit_config(struct config *conf)
 	if (conf->uid_attribute)
 		free(conf->uid_attribute);
 
+	vector_foreach_slot(&conf->uid_attrs, ptr, i)
+		free(ptr);
 	vector_reset(&conf->uid_attrs);
 
 	if (conf->getuid)
libmultipath/dict.c +5 -0
index 26cbe78..3b99296 100644
@@ -597,8 +597,13 @@ static int uid_attrs_handler(struct config *conf, vector strvec,
 			     const char *file, int line_nr)
 {
 	char *val;
+	void *ptr;
+	int i;
 
+	vector_foreach_slot(&conf->uid_attrs, ptr, i)
+		free(ptr);
 	vector_reset(&conf->uid_attrs);
+
 	val = set_value(strvec);
 	if (!val)
 		return 1;
Signature · 1 line
2.35.1

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel