From: sashiko-bot@kernel.org
To: jpoimboe@kernel.org, mbenes@suse.cz, joe.lawrence@redhat.com,
pmladek@suse.com, song@kernel.org, jikos@kernel.org
Cc: "Yafang Shao" <laoar.shao@gmail.com>, live-patching@vger.kernel.org
Subject: Re: [PATCH v5 9/9] selftests: livepatch: Add test for function conflict across provides
Date: Sun, 09 Aug 2026 09:49:44 +0000 [thread overview]
Message-ID: <20260809094945.4B4501F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260809091954.22930-10-laoar.shao@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] Malformed livepatch module missing `old_name` causes a kernel panic on load.
Pre-existing issues:
- [Medium] Race condition in sysfs polling causes flaky selftests.
--
--- Patch [9]: [PATCH v5 9/9] selftests: livepatch: Add test for function conflict across provides ---
commit eaca609db12a6842c4e94debcf9d9ef5049826db
Author: Yafang Shao <laoar.shao@gmail.com>
selftests: livepatch: Add test for function conflict across provides
This commit adds a new test module test_klp_provides.c and three new test
scenarios to test-provides-obsoletes.sh. These tests verify the behavior
of livepatch function conflicts and replacement when using different
provides IDs with and without obsoletes.
> diff --git a/tools/testing/selftests/livepatch/test-provides-obsoletes.sh b/tools/testing/selftests/livepatch/test-provides-obsoletes.sh
> index 1b2c73bdd50b0..32885625401d1 100755
> --- a/tools/testing/selftests/livepatch/test-provides-obsoletes.sh
> +++ b/tools/testing/selftests/livepatch/test-provides-obsoletes.sh
[ ... ]
> @@ -278,4 +279,123 @@ $MOD_STATE2: free_loglevel_state: freeing space for the stored console_loglevel
> livepatch: '$MOD_STATE2': unpatching complete
> % rmmod $MOD_STATE2"
>
> +
> +# - load a livepatch with provides=1 that modifies meminfo_proc_show
> +# - try to load another livepatch with provides=2 that modifies the
> +# same function. The second one must be rejected because livepatches
> +# with different provides ids and no obsoletes must not modify
> +# the same function.
> +# - disable and unload the remaining livepatch
> +
> +start_test "function conflict across provides"
> +
> +load_lp $MOD_ATOMIC provides=1
> +load_failing_mod $MOD_PROVIDES provides=2
> +
> +disable_lp $MOD_ATOMIC
> +unload_lp $MOD_ATOMIC
> +
> +check_result "% insmod test_modules/$MOD_ATOMIC.ko provides=1
> +livepatch: enabling patch '$MOD_ATOMIC'
> +livepatch: '$MOD_ATOMIC': initializing patching transition
> +livepatch: '$MOD_ATOMIC': starting patching transition
> +livepatch: '$MOD_ATOMIC': completing patching transition
> +livepatch: '$MOD_ATOMIC': patching complete
> +% insmod test_modules/$MOD_PROVIDES.ko provides=2
> +livepatch: Livepatch patch ($MOD_PROVIDES) is not compatible with the already installed livepatches.
> +insmod: ERROR: could not insert module test_modules/$MOD_PROVIDES.ko: Invalid parameters
> +% echo 0 > $SYSFS_KLP_DIR/$MOD_ATOMIC/enabled
> +livepatch: '$MOD_ATOMIC': initializing unpatching transition
> +livepatch: '$MOD_ATOMIC': starting unpatching transition
> +livepatch: '$MOD_ATOMIC': completing unpatching transition
> +livepatch: '$MOD_ATOMIC': unpatching complete
> +% rmmod $MOD_ATOMIC"
> +
> +
> +# - load a livepatch with provides=1 that modifies meminfo_proc_show
> +# - load another livepatch with provides=1 that modifies the same
> +# function. The second one loads successfully because livepatches
> +# with the same provides id replace each other.
> +# - disable and unload the remaining livepatch
> +
> +start_test "function replace within same provides"
> +
> +load_lp $MOD_ATOMIC provides=1
> +load_lp $MOD_PROVIDES provides=1
> +
> +mods=($SYSFS_KLP_DIR/*)
> +nmods=${#mods[@]}
> +if [[ "$nmods" -ne 1 ]]; then
[Severity: Medium]
This is a pre-existing issue, but does this pattern cause a regression in the
form of flaky selftests?
The script synchronously counts the directories in the sysfs path immediately
after a transition. However, the old patch's sysfs directory removal is
deferred to an asynchronous workqueue:
kernel/livepatch/core.c:klp_free_replaced_patches_async()
Because of this, the script may momentarily see 2 directories instead of 1
before the asynchronous cleanup completes.
> + die "Expecting one module listed, found $nmods"
> +fi
[ ... ]
> diff --git a/tools/testing/selftests/livepatch/test_modules/test_klp_provides.c b/tools/testing/selftests/livepatch/test_modules/test_klp_provides.c
> new file mode 100644
> index 0000000000000..9751a6f6c8518
> --- /dev/null
> +++ b/tools/testing/selftests/livepatch/test_modules/test_klp_provides.c
> @@ -0,0 +1,72 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
[ ... ]
> +static int test_klp_provides_init(void)
> +{
> +#ifdef KLP_HAS_REPLACE
> + patch.replace = replace;
> +#else
> + patch.provides = provides;
> + if (nr_obsoletes > 0) {
> + patch.obsoletes = obsoletes;
> + patch.nr_obsoletes = nr_obsoletes;
> + }
> +#endif
> + return klp_enable_patch(&patch);
[Severity: High]
Does klp_enable_patch() introduce a regression where a malformed livepatch
module missing old_name causes a kernel panic on load?
If a livepatch module defines a klp_func with .old_name = NULL but provides
.new_func, it bypasses the klp_for_each_func_static loop termination
condition.
Since klp_is_patch_compatible() executes before klp_init_patch():
kernel/livepatch/core.c:klp_enable_patch() {
...
if (!klp_is_patch_compatible(patch)) {
...
ret = klp_init_patch(patch);
...
}
klp_has_function_conflict() iterates over this malformed function, which then
passes the malformed func to klp_find_func():
kernel/livepatch/state.c:klp_has_function_conflict() {
...
if (klp_find_func(old_obj, func))
...
}
This then passes func->old_name to strcmp():
kernel/livepatch/core.c:klp_find_func() {
...
if ((strcmp(obj_func->old_name, func->old_name) == 0) &&
...
}
resulting in an immediate null pointer dereference.
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260809091954.22930-1-laoar.shao@gmail.com?part=9
prev parent reply other threads:[~2026-08-09 9:49 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-09 9:19 [PATCH v5 0/9] livepatch: Introduce replace set support Yafang Shao
2026-08-09 9:19 ` [PATCH v5 1/9] livepatch: Fix wrong index in funcs cleanup error path Yafang Shao
2026-08-09 9:28 ` sashiko-bot
2026-08-09 9:36 ` Yafang Shao
2026-08-09 9:19 ` [PATCH v5 2/9] livepatch: Make klp_find_func() non static Yafang Shao
2026-08-09 9:32 ` sashiko-bot
2026-08-09 9:39 ` Yafang Shao
2026-08-09 9:19 ` [PATCH v5 3/9] livepatch: Call klp_init_patch_early() earlier Yafang Shao
2026-08-09 9:40 ` sashiko-bot
2026-08-09 9:19 ` [PATCH v5 4/9] livepatch: Implement replace set for scoped atomic replace Yafang Shao
2026-08-09 9:33 ` sashiko-bot
2026-08-09 9:19 ` [PATCH v5 5/9] livepatch: Deprecate stack_order Yafang Shao
2026-08-09 9:19 ` [PATCH v5 6/9] selftests: livepatch: Adapt atomic replace tests to provides/obsoletes Yafang Shao
2026-08-09 9:33 ` sashiko-bot
2026-08-09 9:45 ` Yafang Shao
2026-08-09 9:19 ` [PATCH v5 7/9] selftests: livepatch: Add provides/obsoletes test scenarios Yafang Shao
2026-08-09 9:31 ` sashiko-bot
2026-08-09 9:19 ` [PATCH v5 8/9] selftests: livepatch: Add test for state ID conflict across provides Yafang Shao
2026-08-09 9:19 ` [PATCH v5 9/9] selftests: livepatch: Add test for function " Yafang Shao
2026-08-09 9:49 ` sashiko-bot [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=20260809094945.4B4501F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=jikos@kernel.org \
--cc=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=sashiko-reviews@lists.linux.dev \
--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