/dev/mem: Avoid overwriting "err" in read_mem()

Successes in probe_kernel_read() would mask failures in copy_to_user()
during read_mem().

Reported-by: Brad Spengler <spender@grsecurity.net>
Fixes: 22ec1a2aea ("/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>
This commit is contained in:
Kees Cook 2018-03-27 14:06:14 -07:00 коммит произвёл Greg Kroah-Hartman
Родитель b24d0d5b12
Коммит b5b38200eb
1 изменённых файлов: 3 добавлений и 3 удалений

Просмотреть файл

@ -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);
@ -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);