1212#include <linux/cred.h>
1313#include <linux/namei.h>
1414#include <linux/mm.h>
15+ #include <linux/uio.h>
1516#include <linux/module.h>
1617#include <linux/bpf-cgroup.h>
1718#include <linux/mount.h>
@@ -540,13 +541,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
540541 return err ;
541542}
542543
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 )
545546{
546- struct inode * inode = file_inode (filp );
547+ struct inode * inode = file_inode (iocb -> ki_filp );
547548 struct ctl_table_header * head = grab_header (inode );
548549 struct ctl_table * table = PROC_I (inode )-> sysctl_entry ;
549- void * kbuf ;
550+ size_t count = iov_iter_count (iter );
551+ char * kbuf ;
550552 ssize_t error ;
551553
552554 if (IS_ERR (head ))
@@ -569,32 +571,30 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf,
569571 error = - ENOMEM ;
570572 if (count >= KMALLOC_MAX_SIZE )
571573 goto out ;
574+ kbuf = kzalloc (count + 1 , GFP_KERNEL );
575+ if (!kbuf )
576+ goto out ;
572577
573578 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' ;
583583 }
584584
585585 error = BPF_CGROUP_RUN_PROG_SYSCTL (head , table , write , & kbuf , & count ,
586- ppos );
586+ & iocb -> ki_pos );
587587 if (error )
588588 goto out_free_buf ;
589589
590590 /* 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 );
592592 if (error )
593593 goto out_free_buf ;
594594
595595 if (!write ) {
596596 error = - EFAULT ;
597- if (copy_to_user ( ubuf , kbuf , count ) )
597+ if (copy_to_iter ( kbuf , count , iter ) < count )
598598 goto out_free_buf ;
599599 }
600600
@@ -607,16 +607,14 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf,
607607 return error ;
608608}
609609
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 )
612611{
613- return proc_sys_call_handler (filp , ( void __user * ) buf , count , ppos , 0 );
612+ return proc_sys_call_handler (iocb , iter , 0 );
614613}
615614
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 )
618616{
619- return proc_sys_call_handler (filp , ( void __user * ) buf , count , ppos , 1 );
617+ return proc_sys_call_handler (iocb , iter , 1 );
620618}
621619
622620static 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,
853851static const struct file_operations proc_sys_file_operations = {
854852 .open = proc_sys_open ,
855853 .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 ,
858858 .llseek = default_llseek ,
859859};
860860
0 commit comments