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

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