From: Josh Poimboeuf <jpoimboe@kernel.org>
To: Song Liu <song@kernel.org>
Cc: live-patching@vger.kernel.org, linux-kselftest@vger.kernel.org,
jikos@kernel.org, mbenes@suse.cz, pmladek@suse.com,
joe.lawrence@redhat.com, shuah@kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] klp-build: Reuse the target kernel randstruct seed
Date: Sat, 21 Nov 2026 23:00:16 -0800 [thread overview]
Message-ID: <awKS7r98LjmecdIM@jpoimboe> (raw)
In-Reply-To: <20261020212341.706367-1-song@kernel.org>
On Tue, Oct 20, 2026 at 02:23:41PM -0700, Song Liu wrote:
> CONFIG_RANDSTRUCT randomizes struct layouts based on a seed which kbuild
> generates from /dev/urandom. A livepatch has to observe the same layouts
> as the kernel it is loaded into, but klp-build runs 'make clean', after
> which kbuild generates a new seed, and the resulting module can't be
> loaded:
>
> module livepatch_foo: .gnu.linkonce.this_module
> section size must match the kernel's built struct module size at run time
>
> struct module had grown 64 bytes of padding relative to the running
> kernel (0x540 vs 0x500). Every other randomized struct the patch touches
> would be read at the wrong offsets too, so this is not just a loader nit.
>
> Reuse the seed of the kernel being patched, taken from --randstruct-seed
> or from scripts/basic/randstruct.seed in the tree, and refuse to build
> when CONFIG_RANDSTRUCT is on and no valid seed is available. A wrong
> module is worse than no module.
>
> Pin scripts/gen-randstruct-seed.sh rather than the generated seed file:
> clean_kernel() removes scripts/basic/.randstruct.seed.cmd, so kbuild's
> if_changed finds no saved command and regenerates the seed no matter what
> the file already holds. The generator is stashed, so it is restored on
> exit like scripts/setlocalversion.
>
> Read the seed before set_kernelversion(), but pin the generator after it.
> set_kernelversion() runs 'make listnewconfig' and 'make syncconfig', which
> build scripts/basic as well, so after a 'make clean' they would replace
> the seed before the default seed file is read. But if the generator is
> already modified when 'make kernelrelease' runs, setlocalversion appends
> "-dirty" to the kernel release and the module's vermagic no longer
> matches the target kernel.
>
> The Clang and GCC plugin implementations both derive their layouts only
> from scripts/basic/randstruct.seed, so pinning the seed covers
> CONFIG_GCC_PLUGIN_RANDSTRUCT too. Drop the check that rejected it. The
> plugin requires a 64 character seed, which is what gen-randstruct-seed.sh
> writes, so validate exactly that format.
>
> An explicit option is needed rather than deriving the path from
> uname -r, because the build host is usually not running the kernel being
> patched.
>
> Signed-off-by: Song Liu <song@kernel.org>
Seems fine, can you address the Sashiko comments?
--
Josh
prev parent reply other threads:[~2026-11-22 7:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-20 21:23 Song Liu
2026-11-22 7:00 ` Josh Poimboeuf [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=awKS7r98LjmecdIM@jpoimboe \
--to=jpoimboe@kernel.org \
--cc=jikos@kernel.org \
--cc=joe.lawrence@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=pmladek@suse.com \
--cc=shuah@kernel.org \
--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
all inboxes | Powered by JetHome®