Live Patching
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: pmladek@suse.com, jpoimboe@kernel.org, song@kernel.org,
	jikos@kernel.org, mbenes@suse.cz, joe.lawrence@redhat.com,
	"Yafang Shao" <laoar.shao@gmail.com>
Cc: live-patching@vger.kernel.org
Subject: Re: [PATCH v7 for-next 2/8] livepatch: Call klp_init_patch_early() earlier
Date: Tue, 25 Aug 2026 12:06:08 +0000	[thread overview]
Message-ID: <20260825120608.BAB401F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260825114641.80452-3-laoar.shao@gmail.com>

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

Pre-existing issues:
- [High] Potential use-after-free of kobject delayed work structs during error cleanup if CONFIG_DEBUG_KOBJECT_RELEASE is enabled.
--

--- Patch [2]: [PATCH v7 for-next 2/8] livepatch: Call klp_init_patch_early() earlier ---
commit b5f9135d749ffc4d6ea6c6a68a0fc6489e7a1cbf
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
> --- a/kernel/livepatch/core.c
> +++ b/kernel/livepatch/core.c
[ ... ]
> @@ -1152,6 +1152,14 @@ 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 does this error path expose a use-after-free
of kobject delayed work structs when CONFIG_DEBUG_KOBJECT_RELEASE is enabled?

Because kobject_add() has not yet run (it runs later in klp_init_patch()), the
child kobjects (obj and func) do not have their parent pointers set to
patch->kobj during this cleanup path.

When the error path jumps to err and calls klp_free_patch_start(), it drops
references to the child kobjects. Since their parent pointers aren't set,
putting the child kobjects does not elevate or pin the parent patch->kobj. 

Consequently, the wait_for_completion() in klp_free_patch_finish() only waits
for the patch kobject to finish releasing, but not the child kobjects:

kernel/livepatch/core.c:klp_free_patch_finish() {
	...
	kobject_put(&patch->kobj);
	wait_for_completion(&patch->finish);

	/* Put the module after the last access to struct klp_patch. */
	if (!patch->forced)
		module_put(patch->mod);
}

This allows the module memory to be completely freed while the delayed work
for the child obj and func kobjects (which reside in the now-freed module
memory) might still be queued. When the workqueue executes them, it results in
a use-after-free.

While this issue already existed for klp_init_patch() failures, moving
klp_is_patch_compatible() after klp_init_patch_early() makes it trivially
reachable by simply providing an incompatible livepatch.

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

  reply	other threads:[~2026-08-25 12:06 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-25 11:46 [PATCH v7 for-next 0/8] livepatch: Introduce replace set support Yafang Shao
2026-08-25 11:46 ` [PATCH v7 for-next 1/8] livepatch: Make klp_find_func() non static Yafang Shao
2026-08-25 11:46 ` [PATCH v7 for-next 2/8] livepatch: Call klp_init_patch_early() earlier Yafang Shao
2026-08-25 12:06   ` sashiko-bot [this message]
2026-08-25 12:11     ` Yafang Shao
2026-08-27 23:57   ` Josh Poimboeuf
2026-08-28  2:24     ` Yafang Shao
2026-08-25 11:46 ` [PATCH v7 for-next 3/8] livepatch: Implement replace set for scoped atomic replace Yafang Shao
2026-08-25 11:59   ` sashiko-bot
2026-08-25 12:10     ` Yafang Shao
2026-08-28  0:26   ` Josh Poimboeuf
2026-08-28  3:03     ` Yafang Shao
2026-08-28  3:39       ` Josh Poimboeuf
2026-08-28  5:42         ` Yafang Shao
2026-09-02  7:31   ` Replace rules: was: " Petr Mladek
2026-09-02  9:40     ` Yafang Shao
2026-09-02 11:50       ` Yafang Shao
2026-09-03 10:01         ` Petr Mladek
2026-09-06  2:58           ` Yafang Shao
2026-09-03  9:27       ` Petr Mladek
2026-09-03 21:18         ` Song Liu
2026-09-06  8:34           ` Yafang Shao
2026-09-02  7:34   ` documentation: " Petr Mladek
2026-09-02  9:50     ` Yafang Shao
2026-09-03  7:30       ` Petr Mladek
2026-09-02  7:37   ` code cleanup: " Petr Mladek
2026-09-02  9:52     ` Yafang Shao
2026-08-25 11:46 ` [PATCH v7 for-next 4/8] livepatch: Deprecate stack_order Yafang Shao
2026-08-28  0:29   ` Josh Poimboeuf
2026-08-28  3:14     ` Yafang Shao
2026-09-02 12:01   ` Petr Mladek
2026-09-02 12:20     ` Yafang Shao
2026-08-25 11:46 ` [PATCH v7 for-next 5/8] selftests/livepatch: Adapt atomic replace tests to provides/obsoletes Yafang Shao
2026-08-28  0:31   ` Josh Poimboeuf
2026-08-28  3:56     ` Yafang Shao
2026-09-02 13:45   ` Petr Mladek
2026-09-03  3:23     ` Yafang Shao
2026-08-25 11:46 ` [PATCH v7 for-next 6/8] selftests/livepatch: Add provides/obsoletes test scenarios Yafang Shao
2026-09-02 15:15   ` Petr Mladek
2026-09-03  5:43     ` Yafang Shao
2026-08-25 11:46 ` [PATCH v7 for-next 7/8] selftests/livepatch: Add test for state ID conflict across provides Yafang Shao
2026-09-02 15:25   ` Petr Mladek
2026-09-03  5:44     ` Yafang Shao
2026-08-25 11:46 ` [PATCH v7 for-next 8/8] selftests/livepatch: Add test for function " Yafang Shao
2026-09-02 15:51   ` Petr Mladek
2026-09-03  5:48     ` 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=20260825120608.BAB401F00A3A@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