7df327
From 3aca4acaea9569573d3d0e83c3c7998b56ea74c4 Mon Sep 17 00:00:00 2001
7df327
From: Hari Bathini <hbathini@linux.ibm.com>
7df327
Date: Tue, 12 Jul 2022 13:55:47 +0530
7df327
Subject: [PATCH] fix(squash): build ld cache for squash loader
7df327
7df327
Commit dc21638c3f0a fixes kdump kernel crash, due to non-conventional
7df327
library path in powerpc, by copying /etc/ld.so.cache under initdir.
7df327
While that works in general, it is vulnerable to failure because of
7df327
missing links, when the CPU is reconfigured to run in compatibility
7df327
mode of older CPU version. Avoid this by running ldconfig for squash
7df327
loader to create the necessary links & ld cache for it. Doing this
7df327
also saves a few kilobyes of space as the copied ld cache is bigger
7df327
in size than the one needed for squash loader environment.
7df327
7df327
Fixes: dc21638c3f0a ("fix(squash): keep ld cache under initdir")
7df327
Cc: Pingfan Liu <piliu@redhat.com>
7df327
Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
7df327
7df327
(Cherry-picked from f5e8250a06b5a53f6fd8e47ec976db933c91b3cd)
7df327
7df327
Resolves: #2055026
7df327
---
7df327
 dracut-init.sh                     | 14 ++++++++++++++
7df327
 dracut.sh                          | 11 +----------
7df327
 modules.d/99squash/module-setup.sh |  8 +++-----
7df327
 3 files changed, 18 insertions(+), 15 deletions(-)
7df327
7df327
diff --git a/dracut-init.sh b/dracut-init.sh
7df327
index 032c38c2..5df2e583 100644
7df327
--- a/dracut-init.sh
7df327
+++ b/dracut-init.sh
7df327
@@ -443,6 +443,20 @@ inst_rules_wildcard() {
7df327
     [[ $_found ]] || dinfo "Skipping udev rule: $_rule"
7df327
 }
7df327
 
7df327
+# make sure that library links are correct and up to date
7df327
+build_ld_cache() {
7df327
+    for f in "$dracutsysrootdir"/etc/ld.so.conf "$dracutsysrootdir"/etc/ld.so.conf.d/*; do
7df327
+        [[ -f $f ]] && inst_simple "${f#$dracutsysrootdir}"
7df327
+    done
7df327
+    if ! $DRACUT_LDCONFIG -r "$initdir" -f /etc/ld.so.conf; then
7df327
+        if [[ $EUID == 0 ]]; then
7df327
+            derror "ldconfig exited ungracefully"
7df327
+        else
7df327
+            derror "ldconfig might need uid=0 (root) for chroot()"
7df327
+        fi
7df327
+    fi
7df327
+}
7df327
+
7df327
 prepare_udev_rules() {
7df327
     [ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version | { read v _ ; echo $v ; })
7df327
 
7df327
diff --git a/dracut.sh b/dracut.sh
7df327
index 702b2f78..57f51e91 100755
7df327
--- a/dracut.sh
7df327
+++ b/dracut.sh
7df327
@@ -1601,16 +1601,7 @@ done
7df327
 
7df327
 if [[ $kernel_only != yes ]]; then
7df327
     # make sure that library links are correct and up to date
7df327
-    for f in /etc/ld.so.conf /etc/ld.so.conf.d/*; do
7df327
-        [[ -f $f ]] && inst_simple "$f"
7df327
-    done
7df327
-    if ! ldconfig -r "$initdir"; then
7df327
-        if [[ $EUID = 0 ]]; then
7df327
-            derror "ldconfig exited ungracefully"
7df327
-        else
7df327
-            derror "ldconfig might need uid=0 (root) for chroot()"
7df327
-        fi
7df327
-    fi
7df327
+    build_ld_cache
7df327
 fi
7df327
 
7df327
 if [[ $do_hardlink = yes ]] && command -v hardlink >/dev/null; then
7df327
diff --git a/modules.d/99squash/module-setup.sh b/modules.d/99squash/module-setup.sh
7df327
index e73d3184..8a0923fb 100644
7df327
--- a/modules.d/99squash/module-setup.sh
7df327
+++ b/modules.d/99squash/module-setup.sh
7df327
@@ -28,11 +28,6 @@ installpost() {
7df327
         [[ "$squash_dir" == "$i"/* ]] || mv "$i" "$squash_dir"/
7df327
     done
7df327
 
7df327
-    # initdir also needs ld.so.* to make ld.so work
7df327
-    inst /etc/ld.so.cache
7df327
-    inst /etc/ld.so.conf
7df327
-    inst_dir /etc/ld.so.conf.d
7df327
-
7df327
     # Create mount points for squash loader
7df327
     mkdir -p "$initdir"/squash/
7df327
     mkdir -p "$squash_dir"/squash/
7df327
@@ -68,6 +63,9 @@ installpost() {
7df327
     ln_r /usr/bin /bin
7df327
     ln_r /usr/sbin /sbin
7df327
     inst_simple "$moddir"/init-squash.sh /init
7df327
+
7df327
+    # make sure that library links are correct and up to date for squash loader
7df327
+    build_ld_cache
7df327
 }
7df327
 
7df327
 install() {
7df327