* [PATCH v2] nvmem: brcm_nvram: don't cut NVRAM data shorter than its header length
@ 2026-11-29 21:55 Rosen Penev
2026-12-01 13:55 ` Srinivas Kandagatla
0 siblings, 1 reply; 6+ messages in thread
From: Rosen Penev @ 2026-11-29 21:55 UTC (permalink / raw)
To: linux-kernel; +Cc: Srinivas Kandagatla, egc112, Rosen Penev, Greg Kroah-Hartman
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")
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;
--
2.56.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2] nvmem: brcm_nvram: don't cut NVRAM data shorter than its header length
2026-11-29 21:55 [PATCH v2] nvmem: brcm_nvram: don't cut NVRAM data shorter than its header length Rosen Penev
@ 2026-12-01 13:55 ` Srinivas Kandagatla
2026-12-02 4:09 ` Rosen Penev
0 siblings, 1 reply; 6+ messages in thread
From: Srinivas Kandagatla @ 2026-12-01 13:55 UTC (permalink / raw)
To: Rosen Penev, linux-kernel; +Cc: Srinivas Kandagatla, egc112, Greg Kroah-Hartman
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;
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] nvmem: brcm_nvram: don't cut NVRAM data shorter than its header length
2026-12-01 13:55 ` Srinivas Kandagatla
@ 2026-12-02 4:09 ` Rosen Penev
2026-12-02 7:37 ` Greg Kroah-Hartman
0 siblings, 1 reply; 6+ messages in thread
From: Rosen Penev @ 2026-12-02 4:09 UTC (permalink / raw)
To: Srinivas Kandagatla; +Cc: linux-kernel, egc112, Greg Kroah-Hartman
On Tue, Dec 1, 2026 at 5:55 AM Srinivas Kandagatla <srini@kernel.org> wrote:
>
>
>
> 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.
Is that seriously it? The bots will backport it anyway.
>
>
> > 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;
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] nvmem: brcm_nvram: don't cut NVRAM data shorter than its header length
2026-12-02 4:09 ` Rosen Penev
@ 2026-12-02 7:37 ` Greg Kroah-Hartman
2026-12-02 9:52 ` Rosen Penev
0 siblings, 1 reply; 6+ messages in thread
From: Greg Kroah-Hartman @ 2026-12-02 7:37 UTC (permalink / raw)
To: Rosen Penev; +Cc: Srinivas Kandagatla, linux-kernel, egc112
On Tue, Dec 01, 2026 at 08:09:43PM -0800, Rosen Penev wrote:
> On Tue, Dec 1, 2026 at 5:55 AM Srinivas Kandagatla <srini@kernel.org> wrote:
> >
> >
> >
> > 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.
> Is that seriously it? The bots will backport it anyway.
Maybe, maybe not. You are taking a chance we will not do it unless cc:
stable is really there.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] nvmem: brcm_nvram: don't cut NVRAM data shorter than its header length
2026-12-02 7:37 ` Greg Kroah-Hartman
@ 2026-12-02 9:52 ` Rosen Penev
2026-12-02 9:58 ` Greg Kroah-Hartman
0 siblings, 1 reply; 6+ messages in thread
From: Rosen Penev @ 2026-12-02 9:52 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Srinivas Kandagatla, linux-kernel, egc112
On Tue, Dec 1, 2026 at 11:37 PM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> On Tue, Dec 01, 2026 at 08:09:43PM -0800, Rosen Penev wrote:
> > On Tue, Dec 1, 2026 at 5:55 AM Srinivas Kandagatla <srini@kernel.org> wrote:
> > >
> > >
> > >
> > > 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.
> > Is that seriously it? The bots will backport it anyway.
>
> Maybe, maybe not. You are taking a chance we will not do it unless cc:
> stable is really there.
I think all my commits with Fixes: tags have been backported. Even
some without. I'll resend just in case.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] nvmem: brcm_nvram: don't cut NVRAM data shorter than its header length
2026-12-02 9:52 ` Rosen Penev
@ 2026-12-02 9:58 ` Greg Kroah-Hartman
0 siblings, 0 replies; 6+ messages in thread
From: Greg Kroah-Hartman @ 2026-12-02 9:58 UTC (permalink / raw)
To: Rosen Penev; +Cc: Srinivas Kandagatla, linux-kernel, egc112
On Wed, Dec 02, 2026 at 01:52:34AM -0800, Rosen Penev wrote:
> On Tue, Dec 1, 2026 at 11:37 PM Greg Kroah-Hartman
> <gregkh@linuxfoundation.org> wrote:
> >
> > On Tue, Dec 01, 2026 at 08:09:43PM -0800, Rosen Penev wrote:
> > > On Tue, Dec 1, 2026 at 5:55 AM Srinivas Kandagatla <srini@kernel.org> wrote:
> > > >
> > > >
> > > >
> > > > 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.
> > > Is that seriously it? The bots will backport it anyway.
> >
> > Maybe, maybe not. You are taking a chance we will not do it unless cc:
> > stable is really there.
> I think all my commits with Fixes: tags have been backported. Even
> some without. I'll resend just in case.
You got lucky, AND you did not get any notification if things failed to
apply properly. That's why the documentation says you HAVE to put a cc:
stable if you want it backported.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-12-02 9:58 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 21:55 [PATCH v2] nvmem: brcm_nvram: don't cut NVRAM data shorter than its header length Rosen Penev
2026-12-01 13:55 ` Srinivas Kandagatla
2026-12-02 4:09 ` Rosen Penev
2026-12-02 7:37 ` Greg Kroah-Hartman
2026-12-02 9:52 ` Rosen Penev
2026-12-02 9:58 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox