All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yafang Shao" <laoar.shao@gmail.com>,
	jpoimboe@kernel.org, jikos@kernel.org, mbenes@suse.cz,
	pmladek@suse.com, joe.lawrence@redhat.com, song@kernel.org
Cc: live-patching@vger.kernel.org
Subject: Re: [PATCH v12 5/9] livepatch: Implement provides and obsoletes for scoped atomic replace
Date: Fri, 16 Oct 2026 05:48:13 +0000	[thread overview]
Message-ID: <sashiko-outbox-173837@kernel.org> (raw)
In-Reply-To: <20261016053708.47089-6-laoar.shao@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] livepatch: memory leak of dynamically allocated patch structures on klp_enable_patch failure
--

commit 160ccf1ed36fde593c80db0147adb4d9a0aa689f
Author: Yafang Shao <laoar.shao@gmail.com>

livepatch: Implement provides and obsoletes for scoped atomic replace

This commit replaces the boolean replace flag in klp_patch with provides
and obsoletes fields. It introduces a new flexible model to allow multiple
independent livepatch sets to coexist safely on the same system.

> diff --git a/scripts/livepatch/init.c b/scripts/livepatch/init.c
> index f14d8c8fb35fa..1eb124191cf22 100644
> --- a/scripts/livepatch/init.c
> +++ b/scripts/livepatch/init.c

[ ... ]

> @@ -72,15 +75,19 @@ static int __init livepatch_mod_init(void)
>  
>  	/* TODO patch->states */
>  
> -#ifdef KLP_NO_REPLACE
> -	patch->replace = false;
> -#else
> -	patch->replace = true;
> +#ifdef KLP_PROVIDES
> +	patch->provides = KLP_PROVIDES;
> +#endif
> +#ifdef KLP_OBSOLETES
> +	patch->obsoletes = klp_obsoletes;
> +	patch->nr_obsoletes = ARRAY_SIZE(klp_obsoletes);
>  #endif
>  
>  	return klp_enable_patch(patch);

[Severity: Medium]
If klp_enable_patch() fails (e.g., due to patch incompatibility or early
-ENODEV) and returns an error code, does this direct return bypass the 
err_free_objs cleanup path below?

The primary structures (patch, objs, and funcs) are allocated with kzalloc()
earlier in livepatch_mod_init(). Because the core livepatch error path inside
klp_enable_patch() treats these structures as statically provided by the module,
it will not kfree() them upon failure. 

Does this code permanently leak the patch, objs, and funcs structures? Would it
be better to save the return status and goto err_free_objs on failure?

>  
>  err_free_objs:
> +	for (int i = 0; i < nr_objs; i++)
> +		kfree(objs[i].funcs);
>  	kfree(objs);
>  err_free_patch:
>  	kfree(patch);

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

  reply	other threads:[~2026-10-16  5:48 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16  5:36 [PATCH v12 0/9] livepatch: Add support for scoped atomic replace Yafang Shao
2026-10-16  5:37 ` [PATCH v12 1/9] selftests/livepatch: Clarify test module file names Yafang Shao
2026-10-16  5:37 ` [PATCH v12 2/9] selftests/livepatch: Adapt atomic replace tests to provides/obsoletes Yafang Shao
2026-10-16  5:37 ` [PATCH v12 3/9] livepatch: Make klp_find_func() non static Yafang Shao
2026-10-16  5:37 ` [PATCH v12 4/9] livepatch: Call klp_init_patch_early() earlier Yafang Shao
2026-10-16  5:47   ` sashiko-bot
2026-10-16  7:49     ` Yafang Shao
2026-10-16  5:37 ` [PATCH v12 5/9] livepatch: Implement provides and obsoletes for scoped atomic replace Yafang Shao
2026-10-16  5:48   ` sashiko-bot [this message]
2026-10-16  7:46     ` Yafang Shao
2026-10-16  5:37 ` [PATCH v12 6/9] livepatch: Deprecate stack_order Yafang Shao
2026-10-16  5:37 ` [PATCH v12 7/9] selftests/livepatch: Add provides/obsoletes test scenarios Yafang Shao
2026-10-16  5:37 ` [PATCH v12 8/9] selftests/livepatch: Add state test for provides/obsoletes Yafang Shao
2026-10-16  5:37 ` [PATCH v12 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=sashiko-outbox-173837@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.