From 23e1c008a7842ad2333f673885e17cfee7d6848b Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Sun, 27 Jun 2021 19:26:36 -0700 Subject: [PATCH] chrootsetup_*: make sure pull_in_lib libraries have +/-x When pulling in libraries into the chroot, do make sure that they either end up with 0755 or 0644 depending on whether or not the result of `test -x` thinks they're executable. Whether or not a shared library file has +x or not seems to vary wildly with apparently no obvious rhyme or reason to it. When running as root to set up the chroot, the `test -x` utility will conveniently return a "true" result if *any* of the executable bits are set and a "false" result otherwise. Propagate the result of the `test -x` check to all the executable bits to make sure the library installed in the chroot is consistent with regards to whether or not it's actually "executable". Signed-off-by: Kyle J. McKay --- chrootsetup_dragonfly.sh | 15 +++++++++++++++ chrootsetup_freebsd.sh | 15 +++++++++++++++ chrootsetup_linux.sh | 15 +++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/chrootsetup_dragonfly.sh b/chrootsetup_dragonfly.sh index 95ac19b..77e146e 100644 --- a/chrootsetup_dragonfly.sh +++ b/chrootsetup_dragonfly.sh @@ -61,16 +61,31 @@ cp_p() { fi } +fixup_lib() +{ + for _l in "$@"; do + test -f "$_l" || return 0 + if test -x "$_l"; then + chmod 0755 "$_l" + else + chmod 0644 "$_l" + fi + done + return 0 +} + # Bring in basic libraries: rm -f lib/* libexec/* # ld-elf.so.2: cp_p /libexec/ld-elf.so.2 libexec/ +fixup_lib "libexec/ld-elf.so.2" pull_in_lib() { [ -f "$1" ] || return dst="${2%/}/$(basename "$1")" if [ ! -e "$dst" ] || [ "$1" -nt "$dst" ]; then cp_p "$1" "$dst" + fixup_lib "$dst" for llib in $(ldd "$1" | grep '=>' | LC_ALL=C awk '{print $3}'); do (pull_in_lib "$llib" lib) test $? -eq 0 diff --git a/chrootsetup_freebsd.sh b/chrootsetup_freebsd.sh index abcbe1c..11eb1b0 100644 --- a/chrootsetup_freebsd.sh +++ b/chrootsetup_freebsd.sh @@ -55,16 +55,31 @@ cp_p() { fi } +fixup_lib() +{ + for _l in "$@"; do + test -f "$_l" || return 0 + if test -x "$_l"; then + chmod 0755 "$_l" + else + chmod 0644 "$_l" + fi + done + return 0 +} + # Bring in basic libraries: rm -f lib/* libexec/* # ld-elf.so.1: cp_p /libexec/ld-elf.so.1 libexec/ +fixup_lib "libexec/ld-elf.so.1" pull_in_lib() { [ -f "$1" ] || return dst="${2%/}/$(basename "$1")" if [ ! -e "$dst" ] || [ "$1" -nt "$dst" ]; then cp_p "$1" "$dst" + fixup_lib "$dst" for llib in $(ldd "$1" | grep '=>' | LC_ALL=C awk '{print $3}'); do (pull_in_lib "$llib" lib) test $? -eq 0 diff --git a/chrootsetup_linux.sh b/chrootsetup_linux.sh index 62f3d69..1bbc517 100644 --- a/chrootsetup_linux.sh +++ b/chrootsetup_linux.sh @@ -47,6 +47,19 @@ has_files() return 0 } +fixup_lib() +{ + for _l in "$@"; do + test -f "$_l" || return 0 + if test -x "$_l"; then + chmod 0755 "$_l" + else + chmod 0644 "$_l" + fi + done + return 0 +} + # Bring in basic libraries: rm -f lib/* @@ -57,6 +70,7 @@ has_files lib/ld-linux*.so* || { echo "ERROR: could not find any ld-linux*.so* file" >&2 exit 1 } +fixup_lib lib/ld-linux*.so* # Besides '=>' libs, attempt to pick up absolute path libs and create a symlink for upto one level deep extract_libs() { @@ -95,6 +109,7 @@ pull_in_lib() { dst="${2%/}/$(basename "$1")" if [ ! -e "$dst" ] || [ "$1" -nt "$dst" ]; then cp -p -t "$2" "$1" + fixup_lib "$dst" for llib in $(extract_libs "$1"); do (pull_in_lib "$llib" lib) test $? -eq 0 -- 2.11.4.GIT