From: "tip-bot2 for Puranjay Mohan" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Puranjay Mohan <puranjay@kernel.org>, Song Liu <song@kernel.org>,
Josh Poimboeuf <jpoimboe@kernel.org>,
Ingo Molnar <mingo@kernel.org>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: objtool/core] objtool/klp: Add test for rejecting references to init code/data
Date: Mon, 21 Sep 2026 09:28:19 -0000 [thread overview]
Message-ID: <178998289972.2819794.15383789819699397702.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20260916184351.2720310-24-song@kernel.org>
The following commit has been merged into the objtool/core branch of tip:
Commit-ID: d6f2548ec3508fac9ad0f2a7d6f4783f9f9cd119
Gitweb: https://git.kernel.org/tip/d6f2548ec3508fac9ad0f2a7d6f4783f9f9cd119
Author: Puranjay Mohan <puranjay@kernel.org>
AuthorDate: Wed, 16 Sep 2026 11:43:16 -07:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Mon, 21 Sep 2026 11:05:20 +02:00
objtool/klp: Add test for rejecting references to init code/data
Init code and data are freed once boot finishes, so a klp relocation
against them can never resolve.
Signed-off-by: Puranjay Mohan <puranjay@kernel.org>
Signed-off-by: Song Liu <song@kernel.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Assisted-by: Claude:claude-opus-5
Link: https://patch.msgid.link/20260916184351.2720310-24-song@kernel.org
---
tools/objtool/tests/generic/fixtures/init_reference.c | 17 ++++++-
tools/objtool/tests/generic/test-init-reference.sh | 29 ++++++++++-
2 files changed, 46 insertions(+)
create mode 100644 tools/objtool/tests/generic/fixtures/init_reference.c
create mode 100755 tools/objtool/tests/generic/test-init-reference.sh
diff --git a/tools/objtool/tests/generic/fixtures/init_reference.c b/tools/objtool/tests/generic/fixtures/init_reference.c
new file mode 100644
index 0000000..9e59bdf
--- /dev/null
+++ b/tools/objtool/tests/generic/fixtures/init_reference.c
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Patched function referencing data in an .init section. */
+
+static const char __modinfo[]
+ __attribute__((section(".modinfo"), used, aligned(1))) = "\0name=vmlinux";
+
+/* volatile so the read cannot be folded into a constant, leaving no reference */
+static volatile int init_only __attribute__((section(".init.data"), used)) = 5;
+
+int target(int x)
+{
+#ifdef PATCHED
+ return x + init_only + 1;
+#else
+ return x + init_only;
+#endif
+}
diff --git a/tools/objtool/tests/generic/test-init-reference.sh b/tools/objtool/tests/generic/test-init-reference.sh
new file mode 100755
index 0000000..921cf49
--- /dev/null
+++ b/tools/objtool/tests/generic/test-init-reference.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# Init code and data are freed after boot, so a klp relocation against them can
+# never resolve. Such a patch must be rejected.
+
+. "$(dirname "$0")/../lib.sh"
+
+setup
+build_pair init_reference.c
+
+# The rejection can only happen if the patched build really does reference the
+# init symbol. The fixture makes init_only volatile so the read cannot be
+# folded away, and this checks that it worked: without a relocation klp diff
+# would succeed, and the failure below would read as a missing check rather
+# than as a fixture which stopped posing the question.
+# Either spelling will do. A file-local variable is reached through its
+# section symbol -- .init.data -- and a global one by name; which of the two
+# the compiler picks is its business, and the reference is what matters.
+in_relocs "$patched_obj" |
+ awk '$5 == ".init.data" || $5 == "init_only"' | grep -q . ||
+ fail "patched object has no reference into .init.data; the fixture tests nothing"
+
+run_diff 255
+
+diff_log | grep -q "can't patch or reference init code/data" ||
+ fail "expected rejection, got: $(diff_log | tail -1)"
+
+pass "reference to init data rejected"
prev parent reply other threads:[~2026-09-21 9:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260916184351.2720310-24-song@kernel.org>
2026-09-18 10:15 ` tip-bot2 for Puranjay Mohan
2026-09-21 9:28 ` tip-bot2 for Puranjay Mohan [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=178998289972.2819794.15383789819699397702.tip-bot2@tip-bot2 \
--to=tip-bot2@linutronix.de \
--cc=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=puranjay@kernel.org \
--cc=song@kernel.org \
--cc=x86@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
all inboxes | Powered by JetHome®