Skip to content

Commit 8679e8b

Browse files
john-thogregkh
authored andcommitted
nvmem: u-boot-env: error if NVMEM device is too small
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 <[email protected]> Cc: stable <[email protected]> Fixes: d554292 ("nvmem: add driver handling U-Boot environment variables") [rmilecki: simplify commit description & rebase] Signed-off-by: Rafał Miłecki <[email protected]> Signed-off-by: Srinivas Kandagatla <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e8c276d commit 8679e8b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

drivers/nvmem/u-boot-env.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ static int u_boot_env_parse(struct u_boot_env *priv)
176176
data_offset = offsetof(struct u_boot_env_image_broadcom, data);
177177
break;
178178
}
179+
180+
if (dev_size < data_offset) {
181+
dev_err(dev, "Device too small for u-boot-env\n");
182+
err = -EIO;
183+
goto err_kfree;
184+
}
185+
179186
crc32_addr = (__le32 *)(buf + crc32_offset);
180187
crc32 = le32_to_cpu(*crc32_addr);
181188
crc32_data_len = dev_size - crc32_data_offset;

0 commit comments

Comments
 (0)