lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Tue,  4 Aug 2020 17:13:56 +0800
From:   Bingbu Cao <bingbu.cao@...el.com>
To:     srinivas.kandagatla@...aro.org, linux-kernel@...r.kernel.org
Cc:     sakari.ailus@...ux.intel.com, bingbu.cao@...el.com,
        bingbu.cao@...ux.intel.com
Subject: [PATCH] nvmem: core: add sanity check in nvmem_device_read()

nvmem_device_read() could be called directly once nvmem device
registered, the sanity check should be done before call
nvmem_reg_read() as cell and sysfs read did now.

Signed-off-by: Bingbu Cao <bingbu.cao@...el.com>
---
 drivers/nvmem/core.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 927eb5f6003f..c9a77993f008 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -1491,6 +1491,13 @@ int nvmem_device_read(struct nvmem_device *nvmem,
 	if (!nvmem)
 		return -EINVAL;
 
+	if (offset >= nvmem->size || bytes < nvmem->word_size)
+		return 0;
+
+	if (bytes + offset > nvmem->size)
+		bytes = nvmem->size - offset;
+
+	bytes = round_down(bytes, nvmem->word_size);
 	rc = nvmem_reg_read(nvmem, offset, buf, bytes);
 
 	if (rc)
-- 
2.7.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ