mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Srinivas Kandagatla <srini@kernel.org>
To: Pengpeng Hou <pengpeng@iscas.ac.cn>, srini@kernel.org
Cc: rafal@milecki.pl, linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] nvmem: brcm_nvram: validate cached NVRAM length
Date: Thu, 16 Jul 2026 22:50:35 +0100	[thread overview]
Message-ID: <082227b8-7df9-4d0e-8ec9-c0e3cb751a78@kernel.org> (raw)
In-Reply-To: <20260715084504.43774-1-pengpeng@iscas.ac.cn>



On 7/15/26 9:45 AM, Pengpeng Hou wrote:
> The cached-content conversion stops at the partition padding.  Therefore,
> data_len may be smaller than nvmem_size.  brcm_nvram_parse() checks
> header->len against nvmem_size, then passes that length to
> brcm_nvram_add_cells(), which temporarily writes data[len - 1] and parses
> NUL-separated entries.
> 
> A corrupted header can declare a length that fits the MMIO resource but
> exceeds the cached allocation.  Also reject a cached object that is too
> small for the header, and reject declared lengths shorter than the header.
> 
> Validate the declaration against data_len, which bounds the parsed object.
> 
> Fixes: 1e37bf84afac ("nvmem: brcm_nvram: store a copy of NVRAM content")
> Cc: stable@vger.kernel.org
> Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>

There are already few patches on the list which are doing pretty much
same changes, i have applied them which should appear in linux-next in a
day.

https://lkml.org/lkml/2026/7/3/2291

--srini
> ---
>  drivers/nvmem/brcm_nvram.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/nvmem/brcm_nvram.c b/drivers/nvmem/brcm_nvram.c
> index aaa6537798bf..4701772cfa47 100644
> --- a/drivers/nvmem/brcm_nvram.c
> +++ b/drivers/nvmem/brcm_nvram.c
> @@ -181,15 +181,21 @@ static int brcm_nvram_parse(struct brcm_nvram *priv)
>  	size_t len;
>  	int err;
>  
> +	if (priv->data_len < sizeof(*header)) {
> +		dev_err(dev, "NVRAM content (%zu) is smaller than header (%zu)\n",
> +			priv->data_len, sizeof(*header));
> +		return -EINVAL;
> +	}
> +
>  	if (memcmp(header->magic, NVRAM_MAGIC, 4)) {
>  		dev_err(dev, "Invalid NVRAM magic\n");
>  		return -EINVAL;
>  	}
>  
>  	len = le32_to_cpu(header->len);
> -	if (len > priv->nvmem_size) {
> -		dev_err(dev, "NVRAM length (%zd) exceeds mapped size (%zd)\n", len,
> -			priv->nvmem_size);
> +	if (len < sizeof(*header) || len > priv->data_len) {
> +		dev_err(dev, "NVRAM length (%zu) is outside cached content (%zu)\n",
> +			len, priv->data_len);
>  		return -EINVAL;
>  	}
>  


      reply	other threads:[~2026-07-16 21:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-15  8:45 Pengpeng Hou
2026-07-16 21:50 ` Srinivas Kandagatla [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=082227b8-7df9-4d0e-8ec9-c0e3cb751a78@kernel.org \
    --to=srini@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pengpeng@iscas.ac.cn \
    --cc=rafal@milecki.pl \
    --cc=stable@vger.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

Powered by JetHome