Blame SOURCES/0066-multipath-tools-use-run-instead-of-dev-shm.patch

e71b65
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
e71b65
From: Martin Wilck <mwilck@suse.com>
e71b65
Date: Thu, 1 Sep 2022 19:21:30 +0200
e71b65
Subject: [PATCH] multipath-tools: use /run instead of /dev/shm
e71b65
e71b65
/dev/shm may have unsafe permissions. Use /run instead.
e71b65
Use systemd's tmpfiles.d mechanism to create /run/multipath
e71b65
early during boot.
e71b65
e71b65
For backward compatibilty, make the runtime directory configurable
e71b65
via the "runtimedir" make variable.
e71b65
e71b65
Signed-off-by: Martin Wilck <mwilck@suse.com>
e71b65
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
e71b65
---
e71b65
 .gitignore                                        | 2 ++
e71b65
 Makefile.inc                                      | 4 +++-
e71b65
 libmultipath/defaults.h                           | 2 +-
e71b65
 multipath/Makefile                                | 9 +++++++--
e71b65
 multipath/{multipath.rules => multipath.rules.in} | 4 ++--
e71b65
 multipath/tmpfiles.conf.in                        | 1 +
e71b65
 6 files changed, 16 insertions(+), 6 deletions(-)
e71b65
 rename multipath/{multipath.rules => multipath.rules.in} (96%)
e71b65
 create mode 100644 multipath/tmpfiles.conf.in
e71b65
e71b65
diff --git a/.gitignore b/.gitignore
e71b65
index 087dffc2..6ee4fa09 100644
e71b65
--- a/.gitignore
e71b65
+++ b/.gitignore
e71b65
@@ -11,6 +11,8 @@ cscope.files
e71b65
 cscope.out
e71b65
 kpartx/kpartx
e71b65
 multipath/multipath
e71b65
+multipath/multipath.rules
e71b65
+multipath/tmpfiles.conf
e71b65
 multipathd/multipathd
e71b65
 mpathpersist/mpathpersist
e71b65
 .nfs*
e71b65
diff --git a/Makefile.inc b/Makefile.inc
e71b65
index 05027703..4c452159 100644
e71b65
--- a/Makefile.inc
e71b65
+++ b/Makefile.inc
e71b65
@@ -62,6 +62,7 @@ exec_prefix	= $(prefix)
e71b65
 usr_prefix	= $(prefix)
e71b65
 bindir		= $(exec_prefix)/usr/sbin
e71b65
 libudevdir	= $(prefix)/$(SYSTEMDPATH)/udev
e71b65
+tmpfilesdir	= $(prefix)/$(SYSTEMDPATH)/tmpfiles.d
e71b65
 udevrulesdir	= $(libudevdir)/rules.d
e71b65
 multipathdir	= $(TOPDIR)/libmultipath
e71b65
 man8dir		= $(prefix)/usr/share/man/man8
e71b65
@@ -79,6 +80,7 @@ libdmmpdir	= $(TOPDIR)/libdmmp
e71b65
 nvmedir		= $(TOPDIR)/libmultipath/nvme
e71b65
 includedir	= $(prefix)/usr/include
e71b65
 pkgconfdir	= $(usrlibdir)/pkgconfig
e71b65
+runtimedir	= /$(RUN)
e71b65
 
e71b65
 GZIP		= gzip -9 -c
e71b65
 RM		= rm -f
e71b65
@@ -120,7 +122,7 @@ WARNFLAGS	:= -Werror -Wextra -Wformat=2 $(WFORMATOVERFLOW) -Werror=implicit-int
e71b65
 		  $(WNOCLOBBERED) -Werror=cast-qual $(ERROR_DISCARDED_QUALIFIERS) \
e71b65
 		  -Wstrict-prototypes
e71b65
 CFLAGS		:= --std=gnu99 $(CFLAGS) $(OPTFLAGS) $(WARNFLAGS) -pipe \
e71b65
-		   -DBIN_DIR=\"$(bindir)\" -DLIB_STRING=\"${LIB}\" -DRUN_DIR=\"${RUN}\" \
e71b65
+		   -DBIN_DIR=\"$(bindir)\" -DLIB_STRING=\"${LIB}\" -DRUN_DIR=\"${RUN}\" -DRUNTIME_DIR=\"$(runtimedir)\" \
e71b65
 		   -MMD -MP
e71b65
 BIN_CFLAGS	= -fPIE -DPIE
e71b65
 LIB_CFLAGS	= -fPIC
e71b65
diff --git a/libmultipath/defaults.h b/libmultipath/defaults.h
e71b65
index e0dd32ad..cec82f07 100644
e71b65
--- a/libmultipath/defaults.h
e71b65
+++ b/libmultipath/defaults.h
e71b65
@@ -69,7 +69,7 @@
e71b65
 #define DEFAULT_WWIDS_FILE	"/etc/multipath/wwids"
e71b65
 #define DEFAULT_PRKEYS_FILE    "/etc/multipath/prkeys"
e71b65
 #define DEFAULT_CONFIG_DIR	"/etc/multipath/conf.d"
e71b65
-#define MULTIPATH_SHM_BASE	"/dev/shm/multipath/"
e71b65
+#define MULTIPATH_SHM_BASE	RUNTIME_DIR "/multipath/"
e71b65
 
e71b65
 
e71b65
 static inline char *set_default(char *str)
e71b65
diff --git a/multipath/Makefile b/multipath/Makefile
e71b65
index e720c7f6..f3d98012 100644
e71b65
--- a/multipath/Makefile
e71b65
+++ b/multipath/Makefile
e71b65
@@ -12,7 +12,7 @@ EXEC = multipath
e71b65
 
e71b65
 OBJS = main.o
e71b65
 
e71b65
-all: $(EXEC)
e71b65
+all: $(EXEC) multipath.rules tmpfiles.conf
e71b65
 
e71b65
 $(EXEC): $(OBJS) $(multipathdir)/libmultipath.so $(mpathcmddir)/libmpathcmd.so
e71b65
 	$(CC) $(CFLAGS) $(OBJS) -o $(EXEC) $(LDFLAGS) $(LIBDEPS)
e71b65
@@ -27,6 +27,8 @@ install:
e71b65
 	$(INSTALL_PROGRAM) -d $(DESTDIR)$(udevrulesdir)
e71b65
 	$(INSTALL_PROGRAM) -m 644 11-dm-mpath.rules $(DESTDIR)$(udevrulesdir)
e71b65
 	$(INSTALL_PROGRAM) -m 644 $(EXEC).rules $(DESTDIR)$(libudevdir)/rules.d/62-multipath.rules
e71b65
+	$(INSTALL_PROGRAM) -d $(DESTDIR)$(tmpfilesdir)
e71b65
+	$(INSTALL_PROGRAM) -m 644 tmpfiles.conf $(DESTDIR)$(tmpfilesdir)/multipath.conf
e71b65
 	$(INSTALL_PROGRAM) -d $(DESTDIR)$(man8dir)
e71b65
 	$(INSTALL_PROGRAM) -m 644 $(EXEC).8.gz $(DESTDIR)$(man8dir)
e71b65
 	$(INSTALL_PROGRAM) -d $(DESTDIR)$(man5dir)
e71b65
@@ -43,9 +45,12 @@ uninstall:
e71b65
 	$(RM) $(DESTDIR)$(man8dir)/mpathconf.8.gz
e71b65
 
e71b65
 clean: dep_clean
e71b65
-	$(RM) core *.o $(EXEC) *.gz
e71b65
+	$(RM) core *.o $(EXEC) *.gz multipath.rules tmpfiles.conf
e71b65
 
e71b65
 include $(wildcard $(OBJS:.o=.d))
e71b65
 
e71b65
 dep_clean:
e71b65
 	$(RM) $(OBJS:.o=.d)
e71b65
+
e71b65
+%: %.in
e71b65
+	sed 's,@RUNTIME_DIR@,$(runtimedir),' $< >$@
e71b65
diff --git a/multipath/multipath.rules b/multipath/multipath.rules.in
e71b65
similarity index 96%
e71b65
rename from multipath/multipath.rules
e71b65
rename to multipath/multipath.rules.in
e71b65
index 68c30644..5c4447a2 100644
e71b65
--- a/multipath/multipath.rules
e71b65
+++ b/multipath/multipath.rules.in
e71b65
@@ -1,8 +1,8 @@
e71b65
 # Set DM_MULTIPATH_DEVICE_PATH if the device should be handled by multipath
e71b65
 SUBSYSTEM!="block", GOTO="end_mpath"
e71b65
 KERNEL!="sd*|dasd*|nvme*", GOTO="end_mpath"
e71b65
-ACTION=="remove", TEST=="/dev/shm/multipath/find_multipaths/$major:$minor", \
e71b65
-	RUN+="/usr/bin/rm -f /dev/shm/multipath/find_multipaths/$major:$minor"
e71b65
+ACTION=="remove", TEST=="@RUNTIME_DIR@/multipath/find_multipaths/$major:$minor", \
e71b65
+	RUN+="/usr/bin/rm -f @RUNTIME_DIR@/multipath/find_multipaths/$major:$minor"
e71b65
 ACTION!="add|change", GOTO="end_mpath"
e71b65
 
e71b65
 IMPORT{cmdline}="nompath"
e71b65
diff --git a/multipath/tmpfiles.conf.in b/multipath/tmpfiles.conf.in
e71b65
new file mode 100644
e71b65
index 00000000..21be438a
e71b65
--- /dev/null
e71b65
+++ b/multipath/tmpfiles.conf.in
e71b65
@@ -0,0 +1 @@
e71b65
+d @RUNTIME_DIR@/multipath 0700 root root -