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

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