From 63cc79c2257adacc09744989e6eccfcae16f7d67 Mon Sep 17 00:00:00 2001 From: Joe Lawrence Date: Thu, 6 Jun 2024 09:22:44 -0400 Subject: [PATCH 1/4] kpatch-build: fix DISTRO check when specifying USERSRCDIR When kpatch-build is invoked with a -s|--sourcedir USERSRCDIR value, kpatch-build doesn't source the /etc/os-release file as it can't assume that the user-specified kernel source config matches any particular distribution. Subsequent is_supported_{rpm,deb}_distro() function calls will result in ugly syntax errors like: kpatch-build: line 697: SUPPORTED_RPM_DISTROS: bad array subscript kpatch-build: line 692: SUPPORTED_DEB_DISTROS: bad array subscript Enhance the is_supported_{rpm,deb}_distro() functions to check that a non-NULL distribution string argument exists before indexing the SUPPORTED_{RPM,DEB}_DISTROS associative arrays. Signed-off-by: Joe Lawrence --- kpatch-build/kpatch-build | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build index f1a11bd..25b0295 100755 --- a/kpatch-build/kpatch-build +++ b/kpatch-build/kpatch-build @@ -689,11 +689,11 @@ module_name_string() { } is_supported_deb_distro(){ - [[ -n "${SUPPORTED_DEB_DISTROS[$1]:-}" ]] + [[ -n "$1" ]] && [[ -n "${SUPPORTED_DEB_DISTROS[$1]:-}" ]] } is_supported_rpm_distro(){ - [[ -n "${SUPPORTED_RPM_DISTROS[$1]:-}" ]] + [[ -n "$1" ]] && [[ -n "${SUPPORTED_RPM_DISTROS[$1]:-}" ]] } print_supported_distro(){ From 711ee6d322f00a79cb0edb1d56e6664df4cc94f2 Mon Sep 17 00:00:00 2001 From: Joe Lawrence Date: Thu, 6 Jun 2024 09:22:44 -0400 Subject: [PATCH 2/4] kpatch-build: fix USERSRCDIR builds Commit 69e71f8dcc6f ("kpatch-build: cleanup kernel file backup/restore") consolidated a bunch of kernel-tree copy and restoring. As part of that effort, when kpatch-build is invoked with a -s|--sourcedir USERSRCDIR value the vmlinux file is now saved to "$TEMPDIR/kernel-backup/" and not simply "$TEMPDIR/". This results in kpatch-build confusion like: readelf: /home/jolawren/.kpatch/tmp/vmlinux: Error: No such file Update the VMLINUX reassignment in this case to point to the new path. Fixes: 69e71f8dcc6f ("kpatch-build: cleanup kernel file backup/restore") Signed-off-by: Joe Lawrence --- kpatch-build/kpatch-build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build index 25b0295..2029b55 100755 --- a/kpatch-build/kpatch-build +++ b/kpatch-build/kpatch-build @@ -956,7 +956,7 @@ if [[ -n "$USERSRCDIR" ]]; then # save original vmlinux before it gets overwritten by sourcedir build if [[ "$VMLINUX" -ef "$KERNEL_SRCDIR"/vmlinux ]]; then backup_kernel_file "vmlinux" - VMLINUX="$TEMPDIR/vmlinux" + VMLINUX="$KERNEL_BACKUPDIR/vmlinux" fi elif [[ -n "$OOT_MODULE" ]]; then if [[ -z "${CONFIGFILE}" ]]; then From 77d9346383bf0140dd376686007d006c338b383d Mon Sep 17 00:00:00 2001 From: Joe Lawrence Date: Thu, 6 Jun 2024 09:22:44 -0400 Subject: [PATCH 3/4] kpatch-build: fix setlocalversion for pre-v6.3 kernels Commit 629b5acf3dab ("kpatch-build: Fix setlocalversion issue with 6.3 kernel") fixed VERMAGIC_STRING between kpatch original/patched kernel builds by creating a temporary scripts/setlocalversion script. This was accomplished by saving the output from `make kernelversion` into a KERNELVERSION environment variable and running the (original) scripts/setlocalversion to gather a "vX.Y" + "" pair of strings. Unfortunately pre-v6.3 scripts/setlocalversion does not use the KERNELVERSION environment variable, so the same efforts results in an unusable "" + "" version string pair. Restore the original `scripts/setlocalversion --save-scmversion` invocation for source trees that (still) support the --save-scmversion option. Fixes: 629b5acf3dab ("kpatch-build: Fix setlocalversion issue with 6.3 kernel") Signed-off-by: Joe Lawrence --- kpatch-build/kpatch-build | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build index 2029b55..a734534 100755 --- a/kpatch-build/kpatch-build +++ b/kpatch-build/kpatch-build @@ -210,6 +210,8 @@ restore_kernel_files() { } cleanup() { + rm -f "$BUILDDIR/.scmversion" + remove_patches restore_kernel_files @@ -1118,18 +1120,23 @@ fi # appended to the kernel version string (VERMAGIC_STRING), even if the original # kernel was not dirty. That can complicate both the build (create-diff-object # false positive changes) and the patch module link (module version mismatch -# load failures). +# load failures). Before making any changes to the source: # -# Prevent that by replacing the original setlocalversion with a friendlier one -# which just echo's the original version. This should be done before any -# changes to the source. +# For pre-v6.3 kernels: +# Run `./scripts/setlocalversion --save-scmversion`. +# +# For v6.3+ kernels: +# Replace the original setlocalversion with a friendlier one which just echo's +# the original version. if [[ -n "$USERSRCDIR" && -e "$KERNEL_SRCDIR/.git" ]]; then cd "$KERNEL_SRCDIR" || die - backup_kernel_file "scripts/setlocalversion" - LOCALVERSION="$(make kernelversion)" - LOCALVERSION="$(KERNELVERSION="$LOCALVERSION" ./scripts/setlocalversion)" - [[ -n "$LOCALVERSION" ]] || die "setlocalversion failed" - echo "echo $LOCALVERSION" > scripts/setlocalversion + if ! ./scripts/setlocalversion --save-scmversion &>/dev/null; then + backup_kernel_file "scripts/setlocalversion" + LOCALVERSION="$(make kernelversion)" + LOCALVERSION="$(KERNELVERSION="$LOCALVERSION" ./scripts/setlocalversion)" + [[ -n "$LOCALVERSION" ]] || die "setlocalversion failed" + echo "echo $LOCALVERSION" > scripts/setlocalversion + fi fi # kernel option checking From 7d89578c6f082bf743c8e3d1efafdfd4d35a0978 Mon Sep 17 00:00:00 2001 From: Joe Lawrence Date: Fri, 7 Jun 2024 10:14:58 -0400 Subject: [PATCH 4/4] kpatch-build: suppress make directory info for `make kernelversion` When invoking kpatch-build through integration testing, like: $ make PATCH_DIR="linux-6.9.0" \ KPATCH_BUILD_OPTS="--sourcedir /root/linux" \ integration-slow results in an error as kpatch-build's `make kernelversion` adds directory information to its output: make[2]: Entering directory '/root/linux' 6.9.0 make[2]: Leaving directory '/root/linux' This screws up kpatch-build's assignment of the make output to LOCALVERSION, which was expecting only "6.9.0". Add --no-print-directory to the make invocation to avoid the undesired entering / leaving directory info. Fixes: 629b5acf3dab ("kpatch-build: Fix setlocalversion issue with 6.3 kernel") Signed-off-by: Joe Lawrence --- kpatch-build/kpatch-build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build index a734534..64a9620 100755 --- a/kpatch-build/kpatch-build +++ b/kpatch-build/kpatch-build @@ -1132,7 +1132,7 @@ if [[ -n "$USERSRCDIR" && -e "$KERNEL_SRCDIR/.git" ]]; then cd "$KERNEL_SRCDIR" || die if ! ./scripts/setlocalversion --save-scmversion &>/dev/null; then backup_kernel_file "scripts/setlocalversion" - LOCALVERSION="$(make kernelversion)" + LOCALVERSION="$(make --no-print-directory kernelversion)" LOCALVERSION="$(KERNELVERSION="$LOCALVERSION" ./scripts/setlocalversion)" [[ -n "$LOCALVERSION" ]] || die "setlocalversion failed" echo "echo $LOCALVERSION" > scripts/setlocalversion