aboutsummaryrefslogtreecommitdiffstats
path: root/fs/proc
diff options
context:
space:
mode:
authorAlexey Dobriyan <adobriyan@gmail.com>2015-09-09 18:36:59 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-09-10 16:29:01 -0400
commit774636e19ed514cdf560006813c0473409616de8 (patch)
tree1b25c96cca1035d1fc45d758bb17e966d4cadf12 /fs/proc
parent2d2e4715a65ca7e81b292d01ae009a03ccedb9b5 (diff)
proc: convert to kstrto*()/kstrto*_from_user()
Convert from manual allocation/copy_from_user/... to kstrto*() family which were designed for exactly that. One case can not be converted to kstrto*_from_user() to make code even more simpler because of whitespace stripping, oh well... Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/proc')
-rw-r--r--fs/proc/base.c70
1 files changed, 21 insertions, 49 deletions
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 60c71b10eaee..b25eee4cead5 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1230,10 +1230,9 @@ static ssize_t proc_loginuid_write(struct file * file, const char __user * buf,
1230 size_t count, loff_t *ppos) 1230 size_t count, loff_t *ppos)
1231{ 1231{
1232 struct inode * inode = file_inode(file); 1232 struct inode * inode = file_inode(file);
1233 char *page, *tmp;
1234 ssize_t length;
1235 uid_t loginuid; 1233 uid_t loginuid;
1236 kuid_t kloginuid; 1234 kuid_t kloginuid;
1235 int rv;
1237 1236
1238 rcu_read_lock(); 1237 rcu_read_lock();
1239 if (current != pid_task(proc_pid(inode), PIDTYPE_PID)) { 1238 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,
1242 } 1241 }
1243 rcu_read_unlock(); 1242 rcu_read_unlock();
1244 1243
1245 if (count >= PAGE_SIZE)
1246 count = PAGE_SIZE - 1;
1247
1248 if (*ppos != 0) { 1244 if (*ppos != 0) {
1249 /* No partial writes. */ 1245 /* No partial writes. */
1250 return -EINVAL; 1246 return -EINVAL;
1251 } 1247 }
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;
1258 1248
1259 page[count] = '\0'; 1249 rv = kstrtou32_from_user(buf, count, 10, &loginuid);
1260 loginuid = simple_strtoul(page, &tmp, 10); 1250 if (rv < 0)
1261 if (tmp == page) { 1251 return rv;
1262 length = -EINVAL;
1263 goto out_free_page;
1264
1265 }
1266 1252
1267 /* is userspace tring to explicitly UNSET the loginuid? */ 1253 /* is userspace tring to explicitly UNSET the loginuid? */
1268 if (loginuid == AUDIT_UID_UNSET) { 1254 if (loginuid == AUDIT_UID_UNSET) {
1269 kloginuid = INVALID_UID; 1255 kloginuid = INVALID_UID;
1270 } else { 1256 } else {
1271 kloginuid = make_kuid(file->f_cred->user_ns, loginuid); 1257 kloginuid = make_kuid(file->f_cred->user_ns, loginuid);
1272 if (!uid_valid(kloginuid)) { 1258 if (!uid_valid(kloginuid))
1273 length = -EINVAL; 1259 return -EINVAL;
1274 goto out_free_page;
1275 }
1276 } 1260 }
1277 1261
1278 length = audit_set_loginuid(kloginuid); 1262 rv = audit_set_loginuid(kloginuid);
1279 if (likely(length == 0)) 1263 if (rv < 0)
1280 length = count; 1264 return rv;
1281 1265 return count;
1282out_free_page:
1283 free_page((unsigned long) page);
1284 return length;
1285} 1266}
1286 1267
1287static const struct file_operations proc_loginuid_operations = { 1268static const struct file_operations proc_loginuid_operations = {
@@ -1335,8 +1316,9 @@ static ssize_t proc_fault_inject_write(struct file * file,
1335 const char __user * buf, size_t count, loff_t *ppos) 1316 const char __user * buf, size_t count, loff_t *ppos)
1336{ 1317{
1337 struct task_struct *task; 1318 struct task_struct *task;
1338 char buffer[PROC_NUMBUF], *end; 1319 char buffer[PROC_NUMBUF];
1339 int make_it_fail; 1320 int make_it_fail;
1321 int rv;
1340 1322
1341 if (!capable(CAP_SYS_RESOURCE)) 1323 if (!capable(CAP_SYS_RESOURCE))
1342 return -EPERM; 1324 return -EPERM;
@@ -1345,9 +1327,9 @@ static ssize_t proc_fault_inject_write(struct file * file,
1345 count = sizeof(buffer) - 1; 1327 count = sizeof(buffer) - 1;
1346 if (copy_from_user(buffer, buf, count)) 1328 if (copy_from_user(buffer, buf, count))
1347 return -EFAULT; 1329 return -EFAULT;
1348 make_it_fail = simple_strtol(strstrip(buffer), &end, 0); 1330 rv = kstrtoint(strstrip(buffer), 0, &make_it_fail);
1349 if (*end) 1331 if (rv < 0)
1350 return -EINVAL; 1332 return rv;
1351 if (make_it_fail < 0 || make_it_fail > 1) 1333 if (make_it_fail < 0 || make_it_fail > 1)
1352 return -EINVAL; 1334 return -EINVAL;
1353 1335
@@ -2488,32 +2470,20 @@ static ssize_t proc_coredump_filter_write(struct file *file,
2488{ 2470{
2489 struct task_struct *task; 2471 struct task_struct *task;
2490 struct mm_struct *mm; 2472 struct mm_struct *mm;
2491 char buffer[PROC_NUMBUF], *end;
2492 unsigned int val; 2473 unsigned int val;
2493 int ret; 2474 int ret;
2494 int i; 2475 int i;
2495 unsigned long mask; 2476 unsigned long mask;
2496 2477
2497 ret = -EFAULT; 2478 ret = kstrtouint_from_user(buf, count, 0, &val);
2498 memset(buffer, 0, sizeof(buffer)); 2479 if (ret < 0)
2499 if (count > sizeof(buffer) - 1) 2480 return ret;
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;
2510 2481
2511 ret = -ESRCH; 2482 ret = -ESRCH;
2512 task = get_proc_task(file_inode(file)); 2483 task = get_proc_task(file_inode(file));
2513 if (!task) 2484 if (!task)
2514 goto out_no_task; 2485 goto out_no_task;
2515 2486
2516 ret = end - buffer;
2517 mm = get_task_mm(task); 2487 mm = get_task_mm(task);
2518 if (!mm) 2488 if (!mm)
2519 goto out_no_mm; 2489 goto out_no_mm;
@@ -2529,7 +2499,9 @@ static ssize_t proc_coredump_filter_write(struct file *file,
2529 out_no_mm: 2499 out_no_mm:
2530 put_task_struct(task); 2500 put_task_struct(task);
2531 out_no_task: 2501 out_no_task:
2532 return ret; 2502 if (ret < 0)
2503 return ret;
2504 return count;
2533} 2505}
2534 2506
2535static const struct file_operations proc_coredump_filter_operations = { 2507static const struct file_operations proc_coredump_filter_operations = {