mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Marinela Tatiana Selseth <marinela.selseth@firmwaredesign.org>
Cc: vaibhav.sr@gmail.com, mgreer@animalcreek.com, elder@kernel.org,
	gregkh@linuxfoundation.org, greybus-dev@lists.linaro.org,
	linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] staging: greybus: audio: fix use-after-free in gbcodec_hw_params
Date: Mon, 5 Oct 2026 10:34:52 +0200	[thread overview]
Message-ID: <asNhLGdigxSqU5Op@hovoldconsulting.com> (raw)
In-Reply-To: <20261005060126.93732-1-marinela.selseth@firmwaredesign.org>

On Mon, Oct 05, 2026 at 01:01:26AM -0500, Marinela Tatiana Selseth wrote:
> Automated semantic analysis via Coccinelle uncovered a use-after-free
> vulnerability in gbcodec_hw_params() caused by accessing a list
> iterator variable outside the loop boundary.
> 
> The routine walks through the codec module list using
> 'list_for_each_entry' to locate a matching data connection.
> After the loop exits, the iterator pointer 'module' becomes
> out-of-bounds. Attempting to pass this unmapped reference into
> 'to_gb_bundle()' down the line triggers a critical kernel panic.
> 
> Fix this flaw by introducing a dedicated copy 'allocated_module'.
> Cache the matched pointer inside the loop block only when
> 'find_data()' returns a valid reference, and route the subsequent
> power management execution steps safely through this verified object
> tracking reference.
> 
> Assisted-by: Gemini
> Signed-off-by: Marinela Tatiana Selseth <marinela.selseth@firmwaredesign.org>
> ---
>  drivers/staging/greybus/audio_codec.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/greybus/audio_codec.c b/drivers/staging/greybus/audio_codec.c
> index 6daa4e706792..a0645bf83097 100644
> --- a/drivers/staging/greybus/audio_codec.c
> +++ b/drivers/staging/greybus/audio_codec.c
> @@ -396,6 +396,7 @@ static int gbcodec_hw_params(struct snd_pcm_substream *substream,
>  	u8 sig_bits, channels;
>  	u32 format, rate;
>  	struct gbaudio_module_info *module;
> +	struct gbaudio_module_info *allocated_module = NULL;
>  	struct gbaudio_data_connection *data;
>  	struct gb_bundle *bundle;
>  	struct gbaudio_codec_info *codec = dev_get_drvdata(dai->dev);
> @@ -439,8 +440,10 @@ static int gbcodec_hw_params(struct snd_pcm_substream *substream,
>  	/* find the data connection */
>  	list_for_each_entry(module, &codec->module_list, list) {
>  		data = find_data(module, dai->id);
> -		if (data)
> +		if (data) {
> +			allocated_module = module;
>  			break;
> +		}
>  	}
>  
>  	if (!data) {

The code bails out here when no data is found (and the function bails
out early when there are no modules), so how could module be out of
bounds below?

Again, don't send LLM assisted patches to staging which is used for people
to learn.

> @@ -456,7 +459,7 @@ static int gbcodec_hw_params(struct snd_pcm_substream *substream,
>  		return -EINVAL;
>  	}
>  
> -	bundle = to_gb_bundle(module->dev);
> +	bundle = to_gb_bundle(allocated_module->dev);
>  	ret = gb_pm_runtime_get_sync(bundle);
>  	if (ret) {
>  		mutex_unlock(&codec->lock);

Johan

      reply	other threads:[~2026-10-05  8:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-05  6:01 Marinela Tatiana Selseth
2026-10-05  8:34 ` Johan Hovold [this message]

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=asNhLGdigxSqU5Op@hovoldconsulting.com \
    --to=johan@kernel.org \
    --cc=elder@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=greybus-dev@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=marinela.selseth@firmwaredesign.org \
    --cc=mgreer@animalcreek.com \
    --cc=vaibhav.sr@gmail.com \
    /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

all inboxes | Powered by JetHome®