aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/drivers/nvmem
diff options
context:
space:
mode:
authorNicholas Johnson <[email protected]>2020-03-10 13:22:52 +0000
committerGreg Kroah-Hartman <[email protected]>2020-03-19 07:41:03 +0100
commit3c91ef69a3e94f78546b246225ed573fbf1735b4 (patch)
tree3251acb10ce8c6a59de3426fa5810b002a730114 /drivers/nvmem
parentnvmem: core: validate nvmem config before parsing (diff)
downloadwireguard-linux-3c91ef69a3e94f78546b246225ed573fbf1735b4.tar.xz
wireguard-linux-3c91ef69a3e94f78546b246225ed573fbf1735b4.zip
nvmem: check for NULL reg_read and reg_write before dereferencing
Return -EPERM if reg_read is NULL in bin_attr_nvmem_read() or if reg_write is NULL in bin_attr_nvmem_write(). This prevents NULL dereferences such as the one described in 03cd45d2e219 ("thunderbolt: Prevent crash if non-active NVMem file is read") Signed-off-by: Nicholas Johnson <[email protected]> Cc: stable <[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]>
Diffstat (limited to 'drivers/nvmem')
-rw-r--r--drivers/nvmem/nvmem-sysfs.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/drivers/nvmem/nvmem-sysfs.c b/drivers/nvmem/nvmem-sysfs.c
index 9e0c429cd08a..8759c4470012 100644
--- a/drivers/nvmem/nvmem-sysfs.c
+++ b/drivers/nvmem/nvmem-sysfs.c
@@ -56,6 +56,9 @@ static ssize_t bin_attr_nvmem_read(struct file *filp, struct kobject *kobj,
count = round_down(count, nvmem->word_size);
+ if (!nvmem->reg_read)
+ return -EPERM;
+
rc = nvmem->reg_read(nvmem->priv, pos, buf, count);
if (rc)
@@ -90,6 +93,9 @@ static ssize_t bin_attr_nvmem_write(struct file *filp, struct kobject *kobj,
count = round_down(count, nvmem->word_size);
+ if (!nvmem->reg_write)
+ return -EPERM;
+
rc = nvmem->reg_write(nvmem->priv, pos, buf, count);
if (rc)
OSZAR »