From: Petr Mladek <pmladek@suse.com>
To: Yafang Shao <laoar.shao@gmail.com>
Cc: jpoimboe@kernel.org, jikos@kernel.org, mbenes@suse.cz,
joe.lawrence@redhat.com, song@kernel.org,
live-patching@vger.kernel.org,
sashiko-bot <sashiko-bot@kernel.org>
Subject: Re: [PATCH v3 1/7] livepatch: Fix NULL pointer dereference in klp_find_func()
Date: Tue, 9 Jun 2026 15:27:18 +0200 [thread overview]
Message-ID: <aigUttsudeR9ps0p@pathway.suse.cz> (raw)
In-Reply-To: <20260607131659.29281-2-laoar.shao@gmail.com>
On Sun 2026-06-07 21:16:53, Yafang Shao wrote:
> If a newly loaded livepatch provides a function entry with a NULL old_name,
> func->old_name will be NULL when evaluated in strcmp():
>
> klp_init_patch()
> klp_add_nops()
> klp_find_func()
> strcmp(old_func->old_name, func->old_name)
>
> --- a/kernel/livepatch/core.c
> +++ b/kernel/livepatch/core.c
> @@ -92,7 +92,7 @@ static struct klp_func *klp_find_func(struct klp_object *obj,
> * Besides identical old_sympos, also consider old_sympos
> * of 0 and 1 are identical.
> */
> - if ((strcmp(old_func->old_name, func->old_name) == 0) &&
> + if ((func->old_name && strcmp(old_func->old_name, func->old_name) == 0) &&
I do not have a good feeling about this solution because it quietly
ignores a problem. As a result, klp_add_object_nops() would
call klp_alloc_func_nop() even though it does not make much sense.
A livepatch where any func->oldname is not defined should get
rejected. It will actually happen but _later_ in:
+ klp_init_patch()
+ klp_init_object()
+ klp_init_func()
I see three better possibilities.
1. We could move/add the sanity checks into klp_init_patch_early()
and return broken livepatches earlier.
2. We could move/add the sanity check into a new klp_check_patch()
which will be called even before klp_init_patch_early().
3. We could allow klp_find_func() to return ERR_PTR(-EINVAL).
klp_add_object_nops() should then return the error as well.
My preference:
I would do the 3rd variant because it is much easier than
adding/moving all consistency checks between klp_init_*() and
klp_init_*_early() or klp_check_*() functions.
> ((old_func->old_sympos == func->old_sympos) ||
> (old_func->old_sympos == 0 && func->old_sympos == 1) ||
> (old_func->old_sympos == 1 && func->old_sympos == 0))) {
Best Regards,
Petr
next prev parent reply other threads:[~2026-06-09 13:27 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-07 13:16 [PATCH v3 0/7] livepatch: Introduce replace set support Yafang Shao
2026-06-07 13:16 ` [PATCH v3 1/7] livepatch: Fix NULL pointer dereference in klp_find_func() Yafang Shao
2026-06-09 13:27 ` Petr Mladek [this message]
2026-06-07 13:16 ` [PATCH v3 2/7] livepatch: Move klp_find_func() into core.h Yafang Shao
2026-06-09 15:28 ` Petr Mladek
2026-06-07 13:16 ` [PATCH v3 3/7] livepatch: Support scoped atomic replace using replace_set Yafang Shao
2026-06-07 13:33 ` sashiko-bot
2026-06-07 14:00 ` Yafang Shao
2026-06-09 16:00 ` Petr Mladek
2026-06-07 13:16 ` [PATCH v3 4/7] livepatch: Deprecate stack_order Yafang Shao
2026-06-07 13:31 ` sashiko-bot
2026-06-07 13:16 ` [PATCH v3 5/7] selftests/livepatch: Update tests for replace_set Yafang Shao
2026-06-07 13:29 ` sashiko-bot
2026-06-07 13:16 ` [PATCH v3 6/7] selftests/livepatch: Add test for state ID conflict across replace_sets Yafang Shao
2026-06-07 13:16 ` [PATCH v3 7/7] selftests/livepatch: Add test for function " Yafang Shao
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=aigUttsudeR9ps0p@pathway.suse.cz \
--to=pmladek@suse.com \
--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=sashiko-bot@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