Skip to content

kpatch-build: initialize VARIANT variable - #1536

Merged
usebeforefree merged 1 commit into
dynup:masterfrom
usebeforefree:variant-bug
Nov 12, 2026
Merged

usebeforefree merged 1 commit into
dynup:masterfrom
usebeforefree:variant-bug

Conversation

@usebeforefree

Copy link
Copy Markdown
Contributor

Otherwise the script is environment sensitive.

I've discovered this when running:

$ kpatch-build \
    --oot-module "$PWD/test_module_module_repatching.ko" \
    --oot-module-src "$PWD" \
    -n test_klp_module_repatching klp_module_repatching.patch

ERROR: --variant requires --sourcerpm or --sourcedir.

This is an edge case that should be handled as well in this, or another PR.

@usebeforefree
usebeforefree force-pushed the variant-bug branch 2 times, most recently from c350fa2 to e345d8f Compare November 11, 2026 16:32
@usebeforefree

Copy link
Copy Markdown
Contributor Author

Variant is in fact assigned in oot paths, via ARCHVERSION:

if [[ -n "$OOT_MODULE" ]]; then
ARCHVERSION="$(modinfo -F vermagic "$OOT_MODULE" | awk '{print $1}')"
fi

finally:

if [[ -z "$VARIANT" ]] && [[ "$ARCHVERSION" =~ \+(.*)$ ]]; then
VARIANT="${BASH_REMATCH[1]//_/-}"
fi

But it doesn't do anything as far as I can see.

In order not to create bugs and/or raise cryptic errors, I suggest this fix for now:

diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build
index 67a0e54..2bb02c3 100755
--- a/kpatch-build/kpatch-build
+++ b/kpatch-build/kpatch-build
@@ -939,6 +939,10 @@ if [[ -n "$SRCRPM" ]]; then
        fi
 fi

+if [[ -n "$KVARIANT" && -n "$OOT_MODULE" ]]; then
+       die "--variant is incompatible with --oot-module"
+fi
+
 if [[ -n "$KVARIANT" && -z "$SRCRPM" && -z "$USERSRCDIR" ]]; then
        die "--variant requires --sourcerpm or --sourcedir"
 fi

When the -s|--sourcedir option is not provided, kpatch-build sources
/etc/os-release.  On Fedora that file defines a variable called VARIANT,
which in turn overwrites kpatch-build's user provided -V|--variant
VARIANT value, producing a bug.

Fixes: 5adfdd4 ("kpatch-build, lib.sh, man: add kernel variant support")
Signed-off-by: Marko Kostić <mkostic@redhat.com>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com> (commit msg)
@usebeforefree

Copy link
Copy Markdown
Contributor Author

Tests passed, merging

@usebeforefree
usebeforefree merged commit 862cda5 into dynup:master Nov 12, 2026
29 of 32 checks passed
@usebeforefree
usebeforefree deleted the variant-bug branch November 12, 2026 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants