From: Joe Lawrence <joe.lawrence@redhat.com>
To: live-patching@vger.kernel.org
Cc: Josh Poimboeuf <jpoimboe@kernel.org>, Song Liu <song@kernel.org>,
Miroslav Benes <mbenes@suse.cz>, Petr Mladek <pmladek@suse.com>,
Yafang Shao <laoar.shao@gmail.com>
Subject: [RFC PATCH v2 7/7] livepatch/klp-build: add validation for user-supplied OOT objects
Date: Wed, 26 Aug 2026 15:50:00 -0400 [thread overview]
Message-ID: <20260826195000.455905-8-joe.lawrence@redhat.com> (raw)
In-Reply-To: <20260826195000.455905-1-joe.lawrence@redhat.com>
With the --orig-dir and --patched-dir options, the user performs the
respective original and patched builds manually. Therefore it is
important to sanity check the supplied objects to the best of our
ability before entering the diff/extraction pipeline.
Add check_oot_object() and check_oot_objects() to verify:
- Each orig/ object has a matching patched/ counterpart
- At least one .text.<func> section is present, implying
-ffunction-sections compiler flag was used
- Matching compiler versions
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
---
scripts/livepatch/klp-build | 47 ++++++++++++++++++++++++++++++++++---
1 file changed, 44 insertions(+), 3 deletions(-)
diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build
index e118f133e923..fc5d968fe235 100755
--- a/scripts/livepatch/klp-build
+++ b/scripts/livepatch/klp-build
@@ -982,17 +982,58 @@ build_patch_module() {
}
+check_oot_object() {
+ local file="$1"
+
+ readelf -S "$file" 2>/dev/null | command grep -q '\.text\.' ||
+ die "$file: no .text.<func> sections found; was -ffunction-sections used?"
+}
+
+check_oot_objects() {
+ local orig_dir="$1"
+ local patched_dir="$2"
+ local -a files
+ local rel
+
+ command -v readelf &>/dev/null ||
+ die "readelf not found (required for OOT object validation)"
+
+ find "$orig_dir" -type f -name "*.o" -printf '%P\n' | mapfile -t files
+ [[ ${#files[@]} -gt 0 ]] || die "no .o files found in $orig_dir"
+
+ for rel in "${files[@]}"; do
+ [[ -f "$patched_dir/$rel" ]] ||
+ die "$rel found in orig dir but missing from patched dir"
+
+ check_oot_object "$orig_dir/$rel"
+ check_oot_object "$patched_dir/$rel"
+
+ local orig_cc patched_cc
+ orig_cc="$(readelf -p .comment "$orig_dir/$rel" 2>/dev/null | sed -n 's/.*\] *//p' | head -1)"
+ patched_cc="$(readelf -p .comment "$patched_dir/$rel" 2>/dev/null | sed -n 's/.*\] *//p' | head -1)"
+ if [[ -n "$orig_cc" && -n "$patched_cc" && "$orig_cc" != "$patched_cc" ]]; then
+ warn "$rel: compiler mismatch between orig and patched"
+ warn " orig: $orig_cc"
+ warn " patched: $patched_cc"
+ fi
+ done
+
+ find "$patched_dir" -type f -name "*.o" -printf '%P\n' | while read -r rel; do
+ [[ -f "$orig_dir/$rel" ]] ||
+ warn "$rel found in patched dir but missing from orig dir"
+ done
+}
+
setup_oot() {
local files=()
local rel
+ check_oot_objects "$USER_ORIG_DIR" "$USER_PATCHED_DIR"
+
mkdir -p "$ORIG_DIR" "$PATCHED_DIR"
find "$USER_ORIG_DIR" -type f -name "*.o" -printf '%P\n' | mapfile -t files
- [[ ${#files[@]} -gt 0 ]] || die "no .o files found in $USER_ORIG_DIR"
for rel in "${files[@]}"; do
- [[ -f "$USER_PATCHED_DIR/$rel" ]] ||
- die "$rel found in orig dir but missing from patched dir"
mkdir -p "$ORIG_DIR/$(dirname "$rel")"
mkdir -p "$PATCHED_DIR/$(dirname "$rel")"
cp -f "$USER_ORIG_DIR/$rel" "$ORIG_DIR/$rel"
--
2.55.0
prev parent reply other threads:[~2026-08-26 19:50 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-26 19:49 [RFC PATCH v2 0/7] klp-build: OOT module support Joe Lawrence
2026-08-26 19:49 ` [RFC PATCH v2 1/7] objtool/klp: simplify read_exports file handling Joe Lawrence
2026-08-26 23:31 ` Song Liu
2026-08-26 19:49 ` [RFC PATCH v2 2/7] objtool/klp: add --symvers option to klp diff Joe Lawrence
2026-08-26 23:31 ` Song Liu
2026-08-26 19:49 ` [RFC PATCH v2 3/7] objtool/klp: allow special section entry size overrides Joe Lawrence
2026-08-27 19:17 ` Josh Poimboeuf
2026-08-26 19:49 ` [RFC PATCH v2 4/7] objtool: add target architecture to usage Joe Lawrence
2026-08-26 19:57 ` sashiko-bot
2026-08-27 19:23 ` Josh Poimboeuf
2026-08-26 19:49 ` [RFC PATCH v2 5/7] livepatch/klp-build: add basic out-of-tree module support Joe Lawrence
2026-08-26 20:00 ` sashiko-bot
2026-08-27 21:21 ` Josh Poimboeuf
2026-08-26 19:49 ` [RFC PATCH v2 6/7] livepatch/klp-build: add pre-built object support for advanced OOT workflows Joe Lawrence
2026-08-26 20:01 ` sashiko-bot
2026-08-27 21:45 ` Josh Poimboeuf
2026-08-26 19:50 ` Joe Lawrence [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260826195000.455905-8-joe.lawrence@redhat.com \
--to=joe.lawrence@redhat.com \
--cc=jpoimboe@kernel.org \
--cc=laoar.shao@gmail.com \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=pmladek@suse.com \
--cc=song@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox