Skip to content

Commit a0341fc

Browse files
thejhgregkh
authored andcommitted
ibmasm: don't write out of bounds in read handler
This read handler had a lot of custom logic and wrote outside the bounds of the provided buffer. This could lead to kernel and userspace memory corruption. Just use simple_read_from_buffer() with a stack buffer. Fixes: 1da177e ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Jann Horn <jannh@google.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e2a46a4 commit a0341fc

File tree

1 file changed

+3
-24
lines changed

1 file changed

+3
-24
lines changed

drivers/misc/ibmasm/ibmasmfs.c

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -507,35 +507,14 @@ static int remote_settings_file_close(struct inode *inode, struct file *file)
507507
static ssize_t remote_settings_file_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
508508
{
509509
void __iomem *address = (void __iomem *)file->private_data;
510-
unsigned char *page;
511-
int retval;
512510
int len = 0;
513511
unsigned int value;
514-
515-
if (*offset < 0)
516-
return -EINVAL;
517-
if (count == 0 || count > 1024)
518-
return 0;
519-
if (*offset != 0)
520-
return 0;
521-
522-
page = (unsigned char *)__get_free_page(GFP_KERNEL);
523-
if (!page)
524-
return -ENOMEM;
512+
char lbuf[20];
525513

526514
value = readl(address);
527-
len = sprintf(page, "%d\n", value);
528-
529-
if (copy_to_user(buf, page, len)) {
530-
retval = -EFAULT;
531-
goto exit;
532-
}
533-
*offset += len;
534-
retval = len;
515+
len = snprintf(lbuf, sizeof(lbuf), "%d\n", value);
535516

536-
exit:
537-
free_page((unsigned long)page);
538-
return retval;
517+
return simple_read_from_buffer(buf, count, offset, lbuf, len);
539518
}
540519

541520
static ssize_t remote_settings_file_write(struct file *file, const char __user *ubuff, size_t count, loff_t *offset)

0 commit comments

Comments
 (0)