@@ -1230,10 +1230,9 @@ static ssize_t proc_loginuid_write(struct file * file, const char __user * buf,
12301230 size_t count , loff_t * ppos )
12311231{
12321232 struct inode * inode = file_inode (file );
1233- char * page , * tmp ;
1234- ssize_t length ;
12351233 uid_t loginuid ;
12361234 kuid_t kloginuid ;
1235+ int rv ;
12371236
12381237 rcu_read_lock ();
12391238 if (current != pid_task (proc_pid (inode ), PIDTYPE_PID )) {
@@ -1242,46 +1241,28 @@ static ssize_t proc_loginuid_write(struct file * file, const char __user * buf,
12421241 }
12431242 rcu_read_unlock ();
12441243
1245- if (count >= PAGE_SIZE )
1246- count = PAGE_SIZE - 1 ;
1247-
12481244 if (* ppos != 0 ) {
12491245 /* No partial writes. */
12501246 return - EINVAL ;
12511247 }
1252- page = (char * )__get_free_page (GFP_TEMPORARY );
1253- if (!page )
1254- return - ENOMEM ;
1255- length = - EFAULT ;
1256- if (copy_from_user (page , buf , count ))
1257- goto out_free_page ;
12581248
1259- page [count ] = '\0' ;
1260- loginuid = simple_strtoul (page , & tmp , 10 );
1261- if (tmp == page ) {
1262- length = - EINVAL ;
1263- goto out_free_page ;
1264-
1265- }
1249+ rv = kstrtou32_from_user (buf , count , 10 , & loginuid );
1250+ if (rv < 0 )
1251+ return rv ;
12661252
12671253 /* is userspace tring to explicitly UNSET the loginuid? */
12681254 if (loginuid == AUDIT_UID_UNSET ) {
12691255 kloginuid = INVALID_UID ;
12701256 } else {
12711257 kloginuid = make_kuid (file -> f_cred -> user_ns , loginuid );
1272- if (!uid_valid (kloginuid )) {
1273- length = - EINVAL ;
1274- goto out_free_page ;
1275- }
1258+ if (!uid_valid (kloginuid ))
1259+ return - EINVAL ;
12761260 }
12771261
1278- length = audit_set_loginuid (kloginuid );
1279- if (likely (length == 0 ))
1280- length = count ;
1281-
1282- out_free_page :
1283- free_page ((unsigned long ) page );
1284- return length ;
1262+ rv = audit_set_loginuid (kloginuid );
1263+ if (rv < 0 )
1264+ return rv ;
1265+ return count ;
12851266}
12861267
12871268static const struct file_operations proc_loginuid_operations = {
@@ -1335,8 +1316,9 @@ static ssize_t proc_fault_inject_write(struct file * file,
13351316 const char __user * buf , size_t count , loff_t * ppos )
13361317{
13371318 struct task_struct * task ;
1338- char buffer [PROC_NUMBUF ], * end ;
1319+ char buffer [PROC_NUMBUF ];
13391320 int make_it_fail ;
1321+ int rv ;
13401322
13411323 if (!capable (CAP_SYS_RESOURCE ))
13421324 return - EPERM ;
@@ -1345,9 +1327,9 @@ static ssize_t proc_fault_inject_write(struct file * file,
13451327 count = sizeof (buffer ) - 1 ;
13461328 if (copy_from_user (buffer , buf , count ))
13471329 return - EFAULT ;
1348- make_it_fail = simple_strtol (strstrip (buffer ), & end , 0 );
1349- if (* end )
1350- return - EINVAL ;
1330+ rv = kstrtoint (strstrip (buffer ), 0 , & make_it_fail );
1331+ if (rv < 0 )
1332+ return rv ;
13511333 if (make_it_fail < 0 || make_it_fail > 1 )
13521334 return - EINVAL ;
13531335
@@ -2488,32 +2470,20 @@ static ssize_t proc_coredump_filter_write(struct file *file,
24882470{
24892471 struct task_struct * task ;
24902472 struct mm_struct * mm ;
2491- char buffer [PROC_NUMBUF ], * end ;
24922473 unsigned int val ;
24932474 int ret ;
24942475 int i ;
24952476 unsigned long mask ;
24962477
2497- ret = - EFAULT ;
2498- memset (buffer , 0 , sizeof (buffer ));
2499- if (count > sizeof (buffer ) - 1 )
2500- count = sizeof (buffer ) - 1 ;
2501- if (copy_from_user (buffer , buf , count ))
2502- goto out_no_task ;
2503-
2504- ret = - EINVAL ;
2505- val = (unsigned int )simple_strtoul (buffer , & end , 0 );
2506- if (* end == '\n' )
2507- end ++ ;
2508- if (end - buffer == 0 )
2509- goto out_no_task ;
2478+ ret = kstrtouint_from_user (buf , count , 0 , & val );
2479+ if (ret < 0 )
2480+ return ret ;
25102481
25112482 ret = - ESRCH ;
25122483 task = get_proc_task (file_inode (file ));
25132484 if (!task )
25142485 goto out_no_task ;
25152486
2516- ret = end - buffer ;
25172487 mm = get_task_mm (task );
25182488 if (!mm )
25192489 goto out_no_mm ;
@@ -2529,7 +2499,9 @@ static ssize_t proc_coredump_filter_write(struct file *file,
25292499 out_no_mm :
25302500 put_task_struct (task );
25312501 out_no_task :
2532- return ret ;
2502+ if (ret < 0 )
2503+ return ret ;
2504+ return count ;
25332505}
25342506
25352507static const struct file_operations proc_coredump_filter_operations = {
0 commit comments