From: Srinivas Kandagatla <srini@kernel.org>
To: Rosen Penev <rosenp@gmail.com>, linux-kernel@vger.kernel.org
Cc: Srinivas Kandagatla <srini@kernel.org>,
egc112@msn.com, Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [PATCH v2] nvmem: brcm_nvram: don't cut NVRAM data shorter than its header length
Date: Tue, 1 Dec 2026 13:55:31 +0000 [thread overview]
Message-ID: <b5ecfda4-4cf1-43c0-9e90-81a1fa8c9906@kernel.org> (raw)
In-Reply-To: <20261129215551.20747-1-rosenp@gmail.com>
On 11/29/26 9:55 PM, Rosen Penev wrote:
> brcm_nvram_copy_data() sizes the data by stripping trailing bytes that
> equal the last byte of the region. NVRAM content itself ends with NUL
> bytes, so when the region is padded with 0x00 instead of erased 0xff,
> the loop also strips the end of the content. Since
> commit a67e2c323a47 ("nvmem: brcm_nvram: fix out-of-bounds access on malformed flash data")
> the header length is checked against that size, and such NVRAM is now
> rejected. On an ASUS RT-N16, whose CFE pads NVRAM with zeros:
>
> brcm_nvram 1dff8000.nvram: NVRAM length (2600) exceeds data size (2596)
>
> Extend the data to the length in the header when that fits in the
> mapped region. The buffer still covers every byte the parser reads,
> so the out-of-bounds protection is kept.
>
> Fixes: a67e2c323a47 ("nvmem: brcm_nvram: fix out-of-bounds access on malformed flash data")
CC Stable missing.
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
> v2: remove Assisted-By tag
> drivers/nvmem/brcm_nvram.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/drivers/nvmem/brcm_nvram.c b/drivers/nvmem/brcm_nvram.c
> index 1935fe64e7ae..e0ed18890f83 100644
> --- a/drivers/nvmem/brcm_nvram.c
> +++ b/drivers/nvmem/brcm_nvram.c
> @@ -66,8 +66,10 @@ static int brcm_nvram_read(void *context, unsigned int offset, void *val,
>
> static int brcm_nvram_copy_data(struct brcm_nvram *priv, struct platform_device *pdev)
> {
> + struct brcm_nvram_header header;
> struct resource *res;
> void __iomem *base;
> + size_t len;
>
> base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
> if (IS_ERR(base))
> @@ -89,6 +91,16 @@ static int brcm_nvram_copy_data(struct brcm_nvram *priv, struct platform_device
> return -EINVAL;
> }
>
> + /*
> + * NVRAM content ends with NUL bytes, so when the padding is 0x00 (as
> + * written by CFE) the loop above also strips the end of the content.
> + * Don't cut the data shorter than the length in its header.
> + */
> + memcpy_fromio(&header, base, sizeof(header));
> + len = le32_to_cpu(header.len);
> + if (len > priv->data_len && len <= priv->nvmem_size)
> + priv->data_len = len;
> +
> priv->data = devm_kzalloc(priv->dev, priv->data_len, GFP_KERNEL);
> if (!priv->data)
> return -ENOMEM;
prev parent reply other threads:[~2026-12-01 13:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 21:55 Rosen Penev
2026-12-01 13:55 ` 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=b5ecfda4-4cf1-43c0-9e90-81a1fa8c9906@kernel.org \
--to=srini@kernel.org \
--cc=egc112@msn.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rosenp@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®