From: "Rafał Miłecki" <zajec5@gmail.com>
To: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Michael Walle" <michael@walle.cc>,
"Miquel Raynal" <miquel.raynal@bootlin.com>,
devicetree@vger.kernel.org, linux-mtd@lists.infradead.org,
linux-arm-kernel@lists.infradead.org, u-boot@lists.denx.de,
linux-kernel@vger.kernel.org,
"John Thomson" <git@johnthomson.fastmail.com.au>,
"Rafał Miłecki" <rafal@milecki.pl>
Subject: [PATCH V2 1/3] nvmem: u-boot-env: error if NVMEM device is too small
Date: Mon, 29 Jul 2024 10:07:31 +0200 [thread overview]
Message-ID: <20240729080733.16839-1-zajec5@gmail.com> (raw)
From: John Thomson <git@johnthomson.fastmail.com.au>
Verify data size before trying to parse it to avoid reading out of
buffer. This could happen in case of problems at MTD level or invalid DT
bindings.
Signed-off-by: John Thomson <git@johnthomson.fastmail.com.au>
Fixes: d5542923f200 ("nvmem: add driver handling U-Boot environment variables")
[rmilecki: simplify commit description & rebase]
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
V2: New patch in the series
drivers/nvmem/u-boot-env.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/nvmem/u-boot-env.c b/drivers/nvmem/u-boot-env.c
index 936e39b20b38..593f0bf4a395 100644
--- a/drivers/nvmem/u-boot-env.c
+++ b/drivers/nvmem/u-boot-env.c
@@ -176,6 +176,13 @@ static int u_boot_env_parse(struct u_boot_env *priv)
data_offset = offsetof(struct u_boot_env_image_broadcom, data);
break;
}
+
+ if (dev_size < data_offset) {
+ dev_err(dev, "Device too small for u-boot-env\n");
+ err = -EIO;
+ goto err_kfree;
+ }
+
crc32_addr = (__le32 *)(buf + crc32_offset);
crc32 = le32_to_cpu(*crc32_addr);
crc32_data_len = dev_size - crc32_data_offset;
--
2.35.3
next reply other threads:[~2024-07-29 8:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-29 8:07 Rafał Miłecki [this message]
2024-07-29 8:07 ` [PATCH V2 2/3] dt-bindings: nvmem: convert U-Boot env to a layout Rafał Miłecki
2024-07-29 8:07 ` [PATCH V2 3/3] nvmem: layouts: add U-Boot env layout Rafał Miłecki
2024-08-07 9:55 ` [PATCH V2 1/3] nvmem: u-boot-env: error if NVMEM device is too small Srinivas Kandagatla
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=20240729080733.16839-1-zajec5@gmail.com \
--to=zajec5@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=git@johnthomson.fastmail.com.au \
--cc=gregkh@linuxfoundation.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=michael@walle.cc \
--cc=miquel.raynal@bootlin.com \
--cc=rafal@milecki.pl \
--cc=robh@kernel.org \
--cc=srinivas.kandagatla@linaro.org \
--cc=u-boot@lists.denx.de \
/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;
as well as URLs for NNTP newsgroup(s).