Blame SOURCES/0084-libmultipath-limit-paths-that-can-get-wwid-from-envi.patch

86e138
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
86e138
From: Benjamin Marzinski <bmarzins@redhat.com>
86e138
Date: Wed, 8 Feb 2023 19:31:02 -0600
86e138
Subject: [PATCH] libmultipath: limit paths that can get wwid from environment
86e138
86e138
Currently, whenever getting the uid_attribute from udev database fails,
86e138
multipath will try to get it from the environment variables. This
86e138
normally isn't a problem, since either multipath -u is getting called
86e138
from a uevent, and the environment will have the correct value in that
86e138
variable, or that variable won't be set. However, when find_multipaths
86e138
is configured to "smart", this causes problems. For maybe devices,
86e138
multipath needs to get the WWIDs of all the other block devices, to see
86e138
if they match the maybe device wwid.  If one of those devices doesn't
86e138
have uid_attribute set in its udev database, multipath will check the
86e138
environment for it, and it will find that variable set to the WWID
86e138
of the maybe device that this uevent is for.  This means that all
86e138
devices with no WWID will end up appearing to have the same WWID as
86e138
the maybe device, causing multipath to incorrectly claim it.
86e138
86e138
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
86e138
---
86e138
 libmultipath/discovery.c | 2 +-
86e138
 libmultipath/structs.h   | 1 +
86e138
 multipath/main.c         | 2 ++
86e138
 3 files changed, 4 insertions(+), 1 deletion(-)
86e138
86e138
diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
86e138
index f593a7bf..a592a54e 100644
86e138
--- a/libmultipath/discovery.c
86e138
+++ b/libmultipath/discovery.c
86e138
@@ -2032,7 +2032,7 @@ get_udev_uid(struct path * pp, char *uid_attribute, struct udev_device *udev)
86e138
 	const char *value;
86e138
 
86e138
 	value = udev_device_get_property_value(udev, uid_attribute);
86e138
-	if (!value || strlen(value) == 0)
86e138
+	if ((!value || strlen(value) == 0) && pp->can_use_env_uid)
86e138
 		value = getenv(uid_attribute);
86e138
 	if (value && strlen(value)) {
86e138
 		len = strlcpy(pp->wwid, value, WWID_SIZE);
86e138
diff --git a/libmultipath/structs.h b/libmultipath/structs.h
86e138
index 0867b91d..4b308561 100644
86e138
--- a/libmultipath/structs.h
86e138
+++ b/libmultipath/structs.h
86e138
@@ -360,6 +360,7 @@ struct path {
86e138
 	int fast_io_fail;
86e138
 	unsigned int dev_loss;
86e138
 	int eh_deadline;
86e138
+	bool can_use_env_uid;
86e138
 	/* configlet pointers */
86e138
 	vector hwe;
86e138
 	struct gen_path generic_path;
86e138
diff --git a/multipath/main.c b/multipath/main.c
86e138
index 41d01c7e..e056c51c 100644
86e138
--- a/multipath/main.c
86e138
+++ b/multipath/main.c
86e138
@@ -653,6 +653,8 @@ check_path_valid(const char *name, struct config *conf, bool is_uevent)
86e138
 	pp = alloc_path();
86e138
 	if (!pp)
86e138
 		return RTVL_FAIL;
86e138
+	if (is_uevent)
86e138
+		pp->can_use_env_uid = true;
86e138
 
86e138
 	r = is_path_valid(name, conf, pp, is_uevent);
86e138
 	if (r <= PATH_IS_ERROR || r >= PATH_MAX_VALID_RESULT)