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

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