Skip to content

Commit

Permalink
nvmem: check for NULL reg_read and reg_write before dereferencing
Browse files Browse the repository at this point in the history
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
03cd45d ("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]>
  • Loading branch information
Nicholas-Johnson-opensource authored and gregkh committed Mar 19, 2020
1 parent 061a320 commit 3c91ef6
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions drivers/nvmem/nvmem-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3c91ef6

Please sign in to comment.