find-debuginfo: Make sure files are writable before manipulating them

- Add 0005-writable.patch

Resolves: #RHEL-71661
debugedit 5.1 regression with read-only exe/lib files and gdb-add-index error reporting [rhel9]
This commit is contained in:
Mark Wielaard 2025-03-23 18:05:44 +01:00
parent 33d15dfaa3
commit 04b2642b8e
2 changed files with 94 additions and 1 deletions

89
0005-writable.patch Normal file
View File

@ -0,0 +1,89 @@
commit 971a74d79b48a19ff1446642f39b3c5a8a7db238
Author: Mark Wielaard <mark@klomp.org>
Date: Thu Nov 28 17:58:54 2024 +0100
find-debuginfo: Check files are writable before modifying them
Since commit dfe1f7ff3 ("find-debuginfo.sh: Exit with real exit status
in parallel jobs") there is a check whether gdb-add-index worked
correctly and find-debuginfo would fail (even in parallel mode) if an
error occured.
This turned out to show that gdb-add-index needs write permission to
add the gdb index to the file. This is also the case for a couple of
other things, like running objcopy --merge-notes. debugedit and
add_minidebug already made sure it had write permission.
To make sure find-debuginfo doesn't (partially) fail extend the
writable check to include the gdb-add-index and objcopy --merge-notes
invocation.
Signed-off-by: Mark Wielaard <mark@klomp.org>
diff --git a/scripts/find-debuginfo.in b/scripts/find-debuginfo.in
index a360bf0582dc..4e4ef5a64005 100755
--- a/scripts/find-debuginfo.in
+++ b/scripts/find-debuginfo.in
@@ -467,10 +467,22 @@
$strict && exit 2
fi
+ # debugedit makes sure to to get write permission to the file and
+ # restores original state after modifications. Other utilities
+ # might not.
+ f_writable="false"
+ if test -w "$f"; then f_writable="true"; fi
+
# Add .gdb_index if requested.
if $include_gdb_index; then
if type gdb-add-index >/dev/null 2>&1; then
+ if test "$f_writable" = "false"; then
+ chmod u+w "$f"
+ fi
gdb-add-index "$f"
+ if test "$f_writable" = "false"; then
+ chmod u-w "$f"
+ fi
else
echo >&2 "*** ERROR: GDB index requested, but no gdb-add-index installed"
exit 2
@@ -497,7 +512,13 @@ do_file()
# Compress any annobin notes in the original binary.
# Ignore any errors, since older objcopy don't support --merge-notes.
+ if test "$f_writable" = "false"; then
+ chmod u+w "$f"
+ fi
objcopy --merge-notes "$f" 2>/dev/null || true
+ if test "$f_writable" = "false"; then
+ chmod u-w "$f"
+ fi
# A binary already copied into /usr/lib/debug doesn't get stripped,
# just has its file names collected and adjusted.
@@ -507,7 +528,7 @@ do_file()
esac
mkdir -p "${debugdn}"
- if test -w "$f"; then
+ if test "$f_writable" = "true"; then
strip_to_debug "${debugfn}" "$f"
else
chmod u+w "$f"
@@ -529,7 +550,15 @@ do_file()
application/x-executable*) skip_mini=false ;;
application/x-pie-executable*) skip_mini=false ;;
esac
- $skip_mini || add_minidebug "${debugfn}" "$f"
+ if test "$skip_mini" = "true"; then
+ if test "$f_writable" = "false"; then
+ chmod u+w "$f"
+ fi
+ add_minidebug "${debugfn}" "$f"
+ if test "$f_writable" = "false"; then
+ chmod u-w "$f"
+ fi
+ fi
fi
echo "./${f#$RPM_BUILD_ROOT}" >> "$ELFBINSFILE"

View File

@ -1,6 +1,6 @@
Name: debugedit
Version: 5.0
Release: 6%{?dist}
Release: 7%{?dist}
Summary: Tools for debuginfo creation
License: GPLv3+ and GPLv2+ and LGPLv2+
URL: https://sourceware.org/debugedit/
@ -43,6 +43,7 @@ Patch2: 0002-scripts-find-debuginfo.in-Add-q-quiet.patch
Patch3: 0001-debugedit-Add-support-for-.debug_str_offsets-DW_FORM.patch
Patch4: 0003-elf_strptr.patch
Patch5: 0004-compress.patch
Patch6: 0005-writable.patch
%description
The debugedit project provides programs and scripts for creating
@ -86,6 +87,9 @@ make check %{?_smp_mflags}
%{_mandir}/man1/find-debuginfo.1*
%changelog
* Fri Mar 21 2025 Mark Wielaard <mjw@redhat.com> - 5.0-7
- Add 0005-writable.patch
* Fri Mar 21 2025 Mark Wielaard <mjw@redhat.com> - 5.0-6
- Add 0003-elf_strptr.patch
- Add 0004-compress.patch