Skip to content

Commit 62089b8

Browse files
nathanchanceNicolas Schier
authored andcommitted
kbuild: rpm-pkg: Generate debuginfo package manually
Commit a7c699d ("kbuild: rpm-pkg: build a debuginfo RPM") adjusted the __spec_install_post macro to include __os_install_post, which runs brp-strip. This ends up stripping module signatures, breaking loading modules with lockdown enabled. Undo most of the changes of the aforementioned debuginfo patch and mirror commit 16c36f8 ("kbuild: deb-pkg: use build ID instead of debug link for dbg package") in kernel.spec to generate a functionally equivalent debuginfo package while avoiding touching the modules after they have already been signed during modules_install. Fixes: a7c699d ("kbuild: rpm-pkg: build a debuginfo RPM") Reported-by: Holger Kiehl <Holger.Kiehl@dwd.de> Closes: https://lore.kernel.org/68c375f6-e07e-fec-434d-6a45a4f1390@praktifix.dwd.de/ Tested-by: Holger Kiehl <Holger.Kiehl@dwd.de> Signed-off-by: Nathan Chancellor <nathan@kernel.org> Link: https://patch.msgid.link/20260121-fix-module-signing-binrpm-pkg-v1-1-8fc5832b6cbc@kernel.org Signed-off-by: Nicolas Schier <nsc@kernel.org>
1 parent 63804fe commit 62089b8

1 file changed

Lines changed: 30 additions & 35 deletions

File tree

scripts/package/kernel.spec

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
%{!?_arch: %define _arch dummy}
33
%{!?make: %define make make}
44
%define makeflags %{?_smp_mflags} ARCH=%{ARCH}
5+
%define __spec_install_post /usr/lib/rpm/brp-compress || :
6+
%define debug_package %{nil}
57

68
Name: kernel
79
Summary: The Linux Kernel
@@ -46,34 +48,12 @@ against the %{version} kernel package.
4648
%endif
4749

4850
%if %{with_debuginfo}
49-
# list of debuginfo-related options taken from distribution kernel.spec
50-
# files
51-
%undefine _include_minidebuginfo
52-
%undefine _find_debuginfo_dwz_opts
53-
%undefine _unique_build_ids
54-
%undefine _unique_debug_names
55-
%undefine _unique_debug_srcs
56-
%undefine _debugsource_packages
57-
%undefine _debuginfo_subpackages
58-
%global _find_debuginfo_opts -r
59-
%global _missing_build_ids_terminate_build 1
60-
%global _no_recompute_build_ids 1
61-
%{debug_package}
51+
%package debuginfo
52+
Summary: Debug information package for the Linux kernel
53+
%description debuginfo
54+
This package provides debug information for the kernel image and modules from the
55+
%{version} package.
6256
%endif
63-
# some (but not all) versions of rpmbuild emit %%debug_package with
64-
# %%install. since we've already emitted it manually, that would cause
65-
# a package redefinition error. ensure that doesn't happen
66-
%define debug_package %{nil}
67-
68-
# later, we make all modules executable so that find-debuginfo.sh strips
69-
# them up. but they don't actually need to be executable, so remove the
70-
# executable bit, taking care to do it _after_ find-debuginfo.sh has run
71-
%define __spec_install_post \
72-
%{?__debug_package:%{__debug_install_post}} \
73-
%{__arch_install_post} \
74-
%{__os_install_post} \
75-
find %{buildroot}/lib/modules/%{KERNELRELEASE} -name "*.ko" -type f \\\
76-
| xargs --no-run-if-empty chmod u-x
7757

7858
%prep
7959
%setup -q -n linux
@@ -87,7 +67,7 @@ patch -p1 < %{SOURCE2}
8767
mkdir -p %{buildroot}/lib/modules/%{KERNELRELEASE}
8868
cp $(%{make} %{makeflags} -s image_name) %{buildroot}/lib/modules/%{KERNELRELEASE}/vmlinuz
8969
# DEPMOD=true makes depmod no-op. We do not package depmod-generated files.
90-
%{make} %{makeflags} INSTALL_MOD_PATH=%{buildroot} DEPMOD=true modules_install
70+
%{make} %{makeflags} INSTALL_MOD_PATH=%{buildroot} INSTALL_MOD_STRIP=1 DEPMOD=true modules_install
9171
%{make} %{makeflags} INSTALL_HDR_PATH=%{buildroot}/usr headers_install
9272
cp System.map %{buildroot}/lib/modules/%{KERNELRELEASE}
9373
cp .config %{buildroot}/lib/modules/%{KERNELRELEASE}/config
@@ -118,22 +98,31 @@ ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEA
11898
echo "%exclude /lib/modules/%{KERNELRELEASE}/build"
11999
} > %{buildroot}/kernel.list
120100

121-
# make modules executable so that find-debuginfo.sh strips them. this
122-
# will be undone later in %%__spec_install_post
123-
find %{buildroot}/lib/modules/%{KERNELRELEASE} -name "*.ko" -type f \
124-
| xargs --no-run-if-empty chmod u+x
125-
126101
%if %{with_debuginfo}
127102
# copying vmlinux directly to the debug directory means it will not get
128103
# stripped (but its source paths will still be collected + fixed up)
129104
mkdir -p %{buildroot}/usr/lib/debug/lib/modules/%{KERNELRELEASE}
130105
cp vmlinux %{buildroot}/usr/lib/debug/lib/modules/%{KERNELRELEASE}
106+
107+
echo /usr/lib/debug/lib/modules/%{KERNELRELEASE}/vmlinux > %{buildroot}/debuginfo.list
108+
109+
while read -r mod; do
110+
mod="${mod%.o}.ko"
111+
dbg="%{buildroot}/usr/lib/debug/lib/modules/%{KERNELRELEASE}/kernel/${mod}"
112+
buildid=$("${READELF}" -n "${mod}" | sed -n 's@^.*Build ID: \(..\)\(.*\)@\1/\2@p')
113+
link="%{buildroot}/usr/lib/debug/.build-id/${buildid}.debug"
114+
115+
mkdir -p "${dbg%/*}" "${link%/*}"
116+
"${OBJCOPY}" --only-keep-debug "${mod}" "${dbg}"
117+
ln -sf --relative "${dbg}" "${link}"
118+
119+
echo "${dbg#%{buildroot}}" >> %{buildroot}/debuginfo.list
120+
echo "${link#%{buildroot}}" >> %{buildroot}/debuginfo.list
121+
done < modules.order
131122
%endif
132123

133124
%clean
134125
rm -rf %{buildroot}
135-
rm -f debugfiles.list debuglinks.list debugsourcefiles.list debugsources.list \
136-
elfbins.list
137126

138127
%post
139128
if [ -x /usr/bin/kernel-install ]; then
@@ -172,3 +161,9 @@ fi
172161
/usr/src/kernels/%{KERNELRELEASE}
173162
/lib/modules/%{KERNELRELEASE}/build
174163
%endif
164+
165+
%if %{with_debuginfo}
166+
%files -f %{buildroot}/debuginfo.list debuginfo
167+
%defattr (-, root, root)
168+
%exclude /debuginfo.list
169+
%endif

0 commit comments

Comments
 (0)