Skip to content

Commit

Permalink
/dev/mem: Avoid overwriting "err" in read_mem()
Browse files Browse the repository at this point in the history
Successes in probe_kernel_read() would mask failures in copy_to_user()
during read_mem().

Reported-by: Brad Spengler <spender@grsecurity.net>
Fixes: 22ec1a2 ("/dev/mem: Add bounce buffer for copy-out")
Cc: stable@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Kees Cook authored and Greg Kroah-Hartman committed Mar 28, 2018
1 parent b24d0d5 commit b5b3820
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/char/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,

while (count > 0) {
unsigned long remaining;
int allowed;
int allowed, probe;

sz = size_inside_page(p, count);

Expand All @@ -160,9 +160,9 @@ static ssize_t read_mem(struct file *file, char __user *buf,
if (!ptr)
goto failed;

err = probe_kernel_read(bounce, ptr, sz);
probe = probe_kernel_read(bounce, ptr, sz);
unxlate_dev_mem_ptr(p, ptr);
if (err)
if (probe)
goto failed;

remaining = copy_to_user(buf, bounce, sz);
Expand Down

0 comments on commit b5b3820

Please sign in to comment.