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