Commit f5beeb18 authored by Jiri Olsa's avatar Jiri Olsa Committed by Linus Torvalds

fs/proc/kcore.c: Make bounce buffer global for read

Next patch adds bounce buffer for ktext area, so it's
convenient to have single bounce buffer for both
vmalloc/module and ktext cases.
Suggested-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
Acked-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent d2ffb010
...@@ -430,6 +430,7 @@ static void elf_kcore_store_hdr(char *bufp, int nphdr, int dataoff) ...@@ -430,6 +430,7 @@ static void elf_kcore_store_hdr(char *bufp, int nphdr, int dataoff)
static ssize_t static ssize_t
read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos) read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
{ {
char *buf = file->private_data;
ssize_t acc = 0; ssize_t acc = 0;
size_t size, tsz; size_t size, tsz;
size_t elf_buflen; size_t elf_buflen;
...@@ -500,18 +501,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos) ...@@ -500,18 +501,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
if (clear_user(buffer, tsz)) if (clear_user(buffer, tsz))
return -EFAULT; return -EFAULT;
} else if (is_vmalloc_or_module_addr((void *)start)) { } else if (is_vmalloc_or_module_addr((void *)start)) {
char * elf_buf; vread(buf, (char *)start, tsz);
elf_buf = kzalloc(tsz, GFP_KERNEL);
if (!elf_buf)
return -ENOMEM;
vread(elf_buf, (char *)start, tsz);
/* we have to zero-fill user buffer even if no read */ /* we have to zero-fill user buffer even if no read */
if (copy_to_user(buffer, elf_buf, tsz)) { if (copy_to_user(buffer, buf, tsz))
kfree(elf_buf);
return -EFAULT; return -EFAULT;
}
kfree(elf_buf);
} else { } else {
if (kern_addr_valid(start)) { if (kern_addr_valid(start)) {
unsigned long n; unsigned long n;
...@@ -549,6 +542,11 @@ static int open_kcore(struct inode *inode, struct file *filp) ...@@ -549,6 +542,11 @@ static int open_kcore(struct inode *inode, struct file *filp)
{ {
if (!capable(CAP_SYS_RAWIO)) if (!capable(CAP_SYS_RAWIO))
return -EPERM; return -EPERM;
filp->private_data = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (!filp->private_data)
return -ENOMEM;
if (kcore_need_update) if (kcore_need_update)
kcore_update_ram(); kcore_update_ram();
if (i_size_read(inode) != proc_root_kcore->size) { if (i_size_read(inode) != proc_root_kcore->size) {
...@@ -559,10 +557,16 @@ static int open_kcore(struct inode *inode, struct file *filp) ...@@ -559,10 +557,16 @@ static int open_kcore(struct inode *inode, struct file *filp)
return 0; return 0;
} }
static int release_kcore(struct inode *inode, struct file *file)
{
kfree(file->private_data);
return 0;
}
static const struct file_operations proc_kcore_operations = { static const struct file_operations proc_kcore_operations = {
.read = read_kcore, .read = read_kcore,
.open = open_kcore, .open = open_kcore,
.release = release_kcore,
.llseek = default_llseek, .llseek = default_llseek,
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment