All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Dawei Feng" <dawei.feng@seu.edu.cn>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2] nouveau/firmware: fix memory leak on BL load failure
Date: Wed, 10 Jun 2026 03:01:53 +0000	[thread overview]
Message-ID: <20260610030154.4E2DF1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260610025037.4115412-1-dawei.feng@seu.edu.cn>

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

Pre-existing issues:
- [High] Missing bounds checking when parsing firmware headers allows out-of-bounds memory accesses.
--

commit 72846afc6e077321cb6e56447e8430295e342e68
Author: Dawei Feng <dawei.feng@seu.edu.cn>

nouveau/firmware: fix memory leak on BL load failure

This patch addresses a memory leak when loading the HS bootloader blob
fails. It routes the failure to the done label so that the partially
initialized firmware state can be properly cleaned up rather than returning
immediately.

> diff --git a/drivers/gpu/drm/nouveau/nvkm/falcon/fw.c b/drivers/gpu/drm/nouveau/nvkm/falcon/fw.c
> --- a/drivers/gpu/drm/nouveau/nvkm/falcon/fw.c
> +++ b/drivers/gpu/drm/nouveau/nvkm/falcon/fw.c

[ ... ]

> @@ -277,19 +277,20 @@ nvkm_falcon_fw_ctor_hs(const struct nvkm_falcon_fw_func *func, const char *name,
>  	fw->dmem_sign = loc - lhdr->data_dma_base;
>  
>  	if (bl) {
> -		nvkm_firmware_put(blob);
> +		const struct firmware *blob_bl;
>  
> -		ret = nvkm_firmware_load_name(subdev, bl, "", ver, &blob);
> +		ret = nvkm_firmware_load_name(subdev, bl, "", ver, &blob_bl);
>  		if (ret)
> -			return ret;
> +			goto done;
>  
> -		hdr = nvfw_bin_hdr(subdev, blob->data);
> -		desc = nvfw_bl_desc(subdev, blob->data + hdr->header_offset);
> +		hdr = nvfw_bin_hdr(subdev, blob_bl->data);
> +		desc = nvfw_bl_desc(subdev, blob_bl->data + hdr->header_offset);
>  
>  		fw->boot_addr = desc->start_tag << 8;
>  		fw->boot_size = desc->code_size;
> -		fw->boot = kmemdup(blob->data + hdr->data_offset + desc->code_off,
> +		fw->boot = kmemdup(blob_bl->data + hdr->data_offset + desc->code_off,
>  				   fw->boot_size, GFP_KERNEL);

[Severity: High]
This isn't a bug introduced by this patch, but does the firmware parsing
code in nvkm_falcon_fw_ctor_hs() lack bounds checking?

The offsets (such as hdr->header_offset, hdr->data_offset, and
desc->code_off) and sizes (like desc->code_size) are read directly from the
firmware blob. Because functions like nvfw_bin_hdr() and nvfw_bl_desc() do
not take the buffer size as an argument, they cannot perform structural
validation.

Could a malformed or corrupted firmware file cause an out-of-bounds memory
access when kmemdup() tries to copy data, or trigger an unusually large
allocation if desc->code_size is excessively large without being validated
against the total firmware size (blob_bl->size)?

> +		nvkm_firmware_put(blob_bl);
>  		if (!fw->boot)
>  			ret = -ENOMEM;
>  	} else {

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260610025037.4115412-1-dawei.feng@seu.edu.cn?part=1

      reply	other threads:[~2026-06-10  3:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-10  2:50 [PATCH v2] nouveau/firmware: fix memory leak on BL load failure Dawei Feng
2026-06-10  2:50 ` Dawei Feng
2026-06-10  3:01 ` sashiko-bot [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=20260610030154.4E2DF1F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dawei.feng@seu.edu.cn \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.