12
12
#include <linux/cred.h>
13
13
#include <linux/namei.h>
14
14
#include <linux/mm.h>
15
+ #include <linux/uio.h>
15
16
#include <linux/module.h>
16
17
#include <linux/bpf-cgroup.h>
17
18
#include <linux/mount.h>
@@ -540,13 +541,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
540
541
return err ;
541
542
}
542
543
543
- static ssize_t proc_sys_call_handler (struct file * filp , void __user * ubuf ,
544
- size_t count , loff_t * ppos , int write )
544
+ static ssize_t proc_sys_call_handler (struct kiocb * iocb , struct iov_iter * iter ,
545
+ int write )
545
546
{
546
- struct inode * inode = file_inode (filp );
547
+ struct inode * inode = file_inode (iocb -> ki_filp );
547
548
struct ctl_table_header * head = grab_header (inode );
548
549
struct ctl_table * table = PROC_I (inode )-> sysctl_entry ;
549
- void * kbuf ;
550
+ size_t count = iov_iter_count (iter );
551
+ char * kbuf ;
550
552
ssize_t error ;
551
553
552
554
if (IS_ERR (head ))
@@ -569,32 +571,30 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf,
569
571
error = - ENOMEM ;
570
572
if (count >= KMALLOC_MAX_SIZE )
571
573
goto out ;
574
+ kbuf = kzalloc (count + 1 , GFP_KERNEL );
575
+ if (!kbuf )
576
+ goto out ;
572
577
573
578
if (write ) {
574
- kbuf = memdup_user_nul (ubuf , count );
575
- if (IS_ERR (kbuf )) {
576
- error = PTR_ERR (kbuf );
577
- goto out ;
578
- }
579
- } else {
580
- kbuf = kzalloc (count , GFP_KERNEL );
581
- if (!kbuf )
582
- goto out ;
579
+ error = - EFAULT ;
580
+ if (!copy_from_iter_full (kbuf , count , iter ))
581
+ goto out_free_buf ;
582
+ kbuf [count ] = '\0' ;
583
583
}
584
584
585
585
error = BPF_CGROUP_RUN_PROG_SYSCTL (head , table , write , & kbuf , & count ,
586
- ppos );
586
+ & iocb -> ki_pos );
587
587
if (error )
588
588
goto out_free_buf ;
589
589
590
590
/* careful: calling conventions are nasty here */
591
- error = table -> proc_handler (table , write , kbuf , & count , ppos );
591
+ error = table -> proc_handler (table , write , kbuf , & count , & iocb -> ki_pos );
592
592
if (error )
593
593
goto out_free_buf ;
594
594
595
595
if (!write ) {
596
596
error = - EFAULT ;
597
- if (copy_to_user ( ubuf , kbuf , count ) )
597
+ if (copy_to_iter ( kbuf , count , iter ) < count )
598
598
goto out_free_buf ;
599
599
}
600
600
@@ -607,16 +607,14 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf,
607
607
return error ;
608
608
}
609
609
610
- static ssize_t proc_sys_read (struct file * filp , char __user * buf ,
611
- size_t count , loff_t * ppos )
610
+ static ssize_t proc_sys_read (struct kiocb * iocb , struct iov_iter * iter )
612
611
{
613
- return proc_sys_call_handler (filp , ( void __user * ) buf , count , ppos , 0 );
612
+ return proc_sys_call_handler (iocb , iter , 0 );
614
613
}
615
614
616
- static ssize_t proc_sys_write (struct file * filp , const char __user * buf ,
617
- size_t count , loff_t * ppos )
615
+ static ssize_t proc_sys_write (struct kiocb * iocb , struct iov_iter * iter )
618
616
{
619
- return proc_sys_call_handler (filp , ( void __user * ) buf , count , ppos , 1 );
617
+ return proc_sys_call_handler (iocb , iter , 1 );
620
618
}
621
619
622
620
static int proc_sys_open (struct inode * inode , struct file * filp )
@@ -853,8 +851,10 @@ static int proc_sys_getattr(const struct path *path, struct kstat *stat,
853
851
static const struct file_operations proc_sys_file_operations = {
854
852
.open = proc_sys_open ,
855
853
.poll = proc_sys_poll ,
856
- .read = proc_sys_read ,
857
- .write = proc_sys_write ,
854
+ .read_iter = proc_sys_read ,
855
+ .write_iter = proc_sys_write ,
856
+ .splice_read = generic_file_splice_read ,
857
+ .splice_write = iter_file_splice_write ,
858
858
.llseek = default_llseek ,
859
859
};
860
860
0 commit comments