@@ -430,6 +430,7 @@ static void elf_kcore_store_hdr(char *bufp, int nphdr, int dataoff)
430430static ssize_t
431431read_kcore (struct file * file , char __user * buffer , size_t buflen , loff_t * fpos )
432432{
433+ char * buf = file -> private_data ;
433434 ssize_t acc = 0 ;
434435 size_t size , tsz ;
435436 size_t elf_buflen ;
@@ -500,18 +501,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
500501 if (clear_user (buffer , tsz ))
501502 return - EFAULT ;
502503 } else if (is_vmalloc_or_module_addr ((void * )start )) {
503- char * elf_buf ;
504-
505- elf_buf = kzalloc (tsz , GFP_KERNEL );
506- if (!elf_buf )
507- return - ENOMEM ;
508- vread (elf_buf , (char * )start , tsz );
504+ vread (buf , (char * )start , tsz );
509505 /* we have to zero-fill user buffer even if no read */
510- if (copy_to_user (buffer , elf_buf , tsz )) {
511- kfree (elf_buf );
506+ if (copy_to_user (buffer , buf , tsz ))
512507 return - EFAULT ;
513- }
514- kfree (elf_buf );
515508 } else {
516509 if (kern_addr_valid (start )) {
517510 unsigned long n ;
@@ -554,6 +547,11 @@ static int open_kcore(struct inode *inode, struct file *filp)
554547{
555548 if (!capable (CAP_SYS_RAWIO ))
556549 return - EPERM ;
550+
551+ filp -> private_data = kmalloc (PAGE_SIZE , GFP_KERNEL );
552+ if (!filp -> private_data )
553+ return - ENOMEM ;
554+
557555 if (kcore_need_update )
558556 kcore_update_ram ();
559557 if (i_size_read (inode ) != proc_root_kcore -> size ) {
@@ -564,10 +562,16 @@ static int open_kcore(struct inode *inode, struct file *filp)
564562 return 0 ;
565563}
566564
565+ static int release_kcore (struct inode * inode , struct file * file )
566+ {
567+ kfree (file -> private_data );
568+ return 0 ;
569+ }
567570
568571static const struct file_operations proc_kcore_operations = {
569572 .read = read_kcore ,
570573 .open = open_kcore ,
574+ .release = release_kcore ,
571575 .llseek = default_llseek ,
572576};
573577
0 commit comments