Live Patching
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: pmladek@suse.com, jpoimboe@kernel.org, joe.lawrence@redhat.com,
	jikos@kernel.org, mbenes@suse.cz, song@kernel.org
Cc: live-patching@vger.kernel.org, "Yafang Shao" <laoar.shao@gmail.com>
Subject: Re: [RFC PATCH v4 3/4] livepatch: Implement replace set for scoped atomic replace
Date: Tue, 04 Aug 2026 07:03:09 +0000	[thread overview]
Message-ID: <20260804070310.4EBB21F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260804065010.44922-4-laoar.shao@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Dynamically allocated `funcs` arrays are leaked on KLP_OBSOLETES parsing failure.
--

--- Patch [3]: [RFC PATCH v4 3/4] livepatch: Implement replace set for scoped atomic replace ---
commit d186609c1a3dbe210857d0040f657fa918504faf
Author: Yafang Shao <laoar.shao@gmail.com>
Subject: livepatch: Implement replace set for scoped atomic replace

This commit introduces a more flexible atomic replace model for livepatches
using provides and obsoletes fields. A new patch will replace any existing
patch with a matching provides ID or any ID listed in its obsoletes array.
The klp-build script and init code are updated to parse and validate these
new fields.

> diff --git a/scripts/livepatch/init.c b/scripts/livepatch/init.c
> --- a/scripts/livepatch/init.c
> +++ b/scripts/livepatch/init.c
[ ... ]
> @@ -72,10 +73,73 @@ static int __init livepatch_mod_init(void)
[ ... ]
> +#ifdef KLP_OBSOLETES
> +	/*
> +	 * Parse KLP_OBSOLETES string (format: "0,1,2" or "0" or empty)
> +	 * and convert to unsigned int array for patch->obsoletes
> +	 *
> +	 * Note: KLP_OBSOLETES is always defined and includes at least the
> +	 * provides ID, ensuring the patch replaces old patches with same ID.
> +	 */
> +	{
> +		unsigned int *obs_array;
> +		unsigned int count = 1;
> +		char *obsoletes_str;
> +		char *token, *str;
> +		int i = 0;
> +
> +		for (str = (char *)KLP_OBSOLETES; *str; str++) {
> +			if (*str == ',')
> +				count++;
> +		}
> +
> +		obsoletes_str = kstrdup(KLP_OBSOLETES, GFP_KERNEL);
> +		if (!obsoletes_str) {
> +			ret = -ENOMEM;
> +			goto err_free_objs;
> +		}
> +
> +		obs_array = kmalloc_array(count, sizeof(unsigned int), GFP_KERNEL);
> +		if (!obs_array) {
> +			kfree(obsoletes_str);
> +			ret = -ENOMEM;
> +			goto err_free_objs;
> +		}
> +
> +		str = obsoletes_str;
> +		while ((token = strsep(&str, ",")) != NULL) {
> +			unsigned int val;
> +
> +			ret = kstrtouint(token, 10, &val);
> +			if (ret) {
> +				kfree(obsoletes_str);
> +				kfree(obs_array);
> +				goto err_free_objs;
> +			}
> +			obs_array[i++] = val;
> +		}

[Severity: Medium]
Does this code leak the funcs arrays on error?

Earlier in livepatch_mod_init(), the funcs arrays are dynamically allocated 
for each object in a loop:

	funcs = kzalloc(sizeof(struct klp_func) * (nr_funcs + 1), GFP_KERNEL);
	...
	obj->funcs = funcs;

If KLP_OBSOLETES parsing fails during string duplication, array allocation, 
or integer conversion, the error paths jump to err_free_objs. It appears 
that the cleanup label only frees the objs array itself but leaves the 
individual obj->funcs arrays allocated:

err_free_objs:
	kfree(objs);
err_free_patch:
	kfree(patch);

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

  reply	other threads:[~2026-08-04  7:03 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-04  6:50 [RFC PATCH v4 0/4] livepatch: Introduce replace set support Yafang Shao
2026-08-04  6:50 ` [RFC PATCH v4 1/4] livepatch: Make klp_find_func() non static Yafang Shao
2026-08-04  6:56   ` sashiko-bot
2026-08-04  8:04     ` Yafang Shao
2026-08-04  6:50 ` [RFC PATCH v4 2/4] livepatch: Call klp_init_patch_early() earlier Yafang Shao
2026-08-04  7:03   ` sashiko-bot
2026-08-04  8:00     ` Yafang Shao
2026-08-04  6:50 ` [RFC PATCH v4 3/4] livepatch: Implement replace set for scoped atomic replace Yafang Shao
2026-08-04  7:03   ` sashiko-bot [this message]
2026-08-04  7:15     ` Yafang Shao
2026-08-04 23:05   ` Song Liu
2026-08-05  2:54     ` Yafang Shao
2026-08-04  6:50 ` [RFC PATCH v4 4/4] livepatch: Deprecate stack_order 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=20260804070310.4EBB21F000E9@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