mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH V2 1/3] nvmem: u-boot-env: error if NVMEM device is too small
@ 2024-07-29  8:07 Rafał Miłecki
  2024-07-29  8:07 ` [PATCH V2 2/3] dt-bindings: nvmem: convert U-Boot env to a layout Rafał Miłecki
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Rafał Miłecki @ 2024-07-29  8:07 UTC (permalink / raw)
  To: Srinivas Kandagatla, Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: Greg Kroah-Hartman, Michael Walle, Miquel Raynal, devicetree,
	linux-mtd, linux-arm-kernel, u-boot, linux-kernel, John Thomson,
	Rafał Miłecki

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-08-07  9:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-29  8:07 [PATCH V2 1/3] nvmem: u-boot-env: error if NVMEM device is too small Rafał Miłecki
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

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®