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

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