Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Jiri Olsa and committed by
Linus Torvalds
f5beeb18 d2ffb010

+14 -10
+14 -10
fs/proc/kcore.c
··· 430 430 static ssize_t 431 431 read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos) 432 432 { 433 + char *buf = file->private_data; 433 434 ssize_t acc = 0; 434 435 size_t size, tsz; 435 436 size_t elf_buflen; ··· 501 500 if (clear_user(buffer, tsz)) 502 501 return -EFAULT; 503 502 } else if (is_vmalloc_or_module_addr((void *)start)) { 504 - char * elf_buf; 505 - 506 - elf_buf = kzalloc(tsz, GFP_KERNEL); 507 - if (!elf_buf) 508 - return -ENOMEM; 509 - vread(elf_buf, (char *)start, tsz); 503 + vread(buf, (char *)start, tsz); 510 504 /* we have to zero-fill user buffer even if no read */ 511 - if (copy_to_user(buffer, elf_buf, tsz)) { 512 - kfree(elf_buf); 505 + if (copy_to_user(buffer, buf, tsz)) 513 506 return -EFAULT; 514 - } 515 - kfree(elf_buf); 516 507 } else { 517 508 if (kern_addr_valid(start)) { 518 509 unsigned long n; ··· 542 549 { 543 550 if (!capable(CAP_SYS_RAWIO)) 544 551 return -EPERM; 552 + 553 + filp->private_data = kmalloc(PAGE_SIZE, GFP_KERNEL); 554 + if (!filp->private_data) 555 + return -ENOMEM; 556 + 545 557 if (kcore_need_update) 546 558 kcore_update_ram(); 547 559 if (i_size_read(inode) != proc_root_kcore->size) { ··· 557 559 return 0; 558 560 } 559 561 562 + static int release_kcore(struct inode *inode, struct file *file) 563 + { 564 + kfree(file->private_data); 565 + return 0; 566 + } 560 567 561 568 static const struct file_operations proc_kcore_operations = { 562 569 .read = read_kcore, 563 570 .open = open_kcore, 571 + .release = release_kcore, 564 572 .llseek = default_llseek, 565 573 }; 566 574