All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: song@kernel.org, "Yafang Shao" <laoar.shao@gmail.com>,
	jikos@kernel.org, jpoimboe@kernel.org, mbenes@suse.cz,
	pmladek@suse.com, joe.lawrence@redhat.com
Cc: live-patching@vger.kernel.org
Subject: Re: [PATCH v9 4/9] livepatch: Call klp_init_patch_early() earlier
Date: Sun, 13 Sep 2026 02:55:05 +0000	[thread overview]
Message-ID: <20260913025505.D1F501F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260913024228.72317-5-laoar.shao@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Use-after-free on statically allocated kobjects when CONFIG_DEBUG_KOBJECT_RELEASE is enabled
--

commit 482a331678a5995d891ae6ebde80245198dd0aba
Author: Yafang Shao <laoar.shao@gmail.com>

livepatch: Call klp_init_patch_early() earlier

Invoke klp_init_patch_early() during early initialization to avoid
mixing for_each_() and for_each_*_static() variants later in the code.

> diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
> index c34306ecfb0bb..f088955de8557 100644
> --- a/kernel/livepatch/core.c
> +++ b/kernel/livepatch/core.c

[ ... ]

> @@ -1159,6 +1152,13 @@ int klp_enable_patch(struct klp_patch *patch)
>  
>  	klp_init_patch_early(patch);
>  
> +	if (!klp_is_patch_compatible(patch)) {
> +		pr_err("Livepatch patch (%s) is not compatible with the already installed livepatches.\n",
> +			patch->mod->name);
> +		ret = -EINVAL;
> +		goto err;

[Severity: High]
This is a pre-existing issue, but could jumping to the error path here
cause a use-after-free when CONFIG_DEBUG_KOBJECT_RELEASE is enabled?

If klp_enable_patch() fails here due to patch incompatibility, the error
path calls klp_free_patch_start(), which eventually invokes kobject_put()
on the statically allocated obj and func structures:

kernel/livepatch/core.c:__klp_free_objects() {
    ...
    kobject_put(&obj->kobj);
    ...
}

When CONFIG_DEBUG_KOBJECT_RELEASE is enabled, kobject_put() schedules
delayed release works for these kobjects, which are embedded within the
livepatch module's memory.

Since klp_enable_patch() only waits for the patch kobject's completion and
ignores the obj and func kobjects, module_init() returns an error. This
leads the kernel to unload the module and free its memory while the delayed
release works are still pending.

Is there a way to ensure the module memory isn't freed before these
delayed works complete?

> +	}
> +
>  	ret = klp_init_patch(patch);
>  	if (ret)
>  		goto err;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260913024228.72317-1-laoar.shao@gmail.com?part=4

  reply	other threads:[~2026-09-13  2:55 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-13  2:42 [PATCH v9 0/9] livepatch: Add support for scoped atomic replace Yafang Shao
2026-09-13  2:42 ` [PATCH v9 1/9] selftests/livepatch: Clarify test module file names Yafang Shao
2026-09-13  2:42 ` [PATCH v9 2/9] selftests/livepatch: Adapt atomic replace tests to provides/obsoletes Yafang Shao
2026-09-13  2:42 ` [PATCH v9 3/9] livepatch: Make klp_find_func() non static Yafang Shao
2026-09-13  2:42 ` [PATCH v9 4/9] livepatch: Call klp_init_patch_early() earlier Yafang Shao
2026-09-13  2:55   ` sashiko-bot [this message]
2026-09-13  2:57     ` Yafang Shao
2026-09-13  2:42 ` [PATCH v9 5/9] livepatch: Implement provides and obsoletes for scoped atomic replace Yafang Shao
2026-09-13  2:42 ` [PATCH v9 6/9] livepatch: Deprecate stack_order Yafang Shao
2026-09-13  2:48   ` sashiko-bot
2026-09-13  2:55     ` Yafang Shao
2026-09-13  2:42 ` [PATCH v9 7/9] selftests/livepatch: Add provides/obsoletes test scenarios Yafang Shao
2026-09-13  2:42 ` [PATCH v9 8/9] selftests/livepatch: Add state test for provides/obsoletes Yafang Shao
2026-09-13  2:42 ` [PATCH v9 9/9] selftests/livepatch: Add 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=20260913025505.D1F501F000FF@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.