diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2015-12-24 00:06:05 -0500 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2016-01-04 10:26:58 -0500 |
commit | 16e5c1fc36040e592128a164499bc25eb138a80f (patch) | |
tree | a080bd2eea306d5815c5a9eefb46180e2bedffb2 /security | |
parent | 7e935c7ca1e6c398f11edac5beabfc4348e3b3a4 (diff) |
convert a bunch of open-coded instances of memdup_user_nul()
A _lot_ of ->write() instances were open-coding it; some are
converted to memdup_user_nul(), a lot more remain...
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'security')
-rw-r--r-- | security/smack/smackfs.c | 114 | ||||
-rw-r--r-- | security/tomoyo/securityfs_if.c | 11 |
2 files changed, 35 insertions, 90 deletions
diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c index 94bd9e41c9ec..e249a66db533 100644 --- a/security/smack/smackfs.c +++ b/security/smack/smackfs.c | |||
@@ -497,14 +497,9 @@ static ssize_t smk_write_rules_list(struct file *file, const char __user *buf, | |||
497 | } | 497 | } |
498 | } | 498 | } |
499 | 499 | ||
500 | data = kmalloc(count + 1, GFP_KERNEL); | 500 | data = memdup_user_nul(buf, count); |
501 | if (data == NULL) | 501 | if (IS_ERR(data)) |
502 | return -ENOMEM; | 502 | return PTR_ERR(data); |
503 | |||
504 | if (copy_from_user(data, buf, count) != 0) { | ||
505 | rc = -EFAULT; | ||
506 | goto out; | ||
507 | } | ||
508 | 503 | ||
509 | /* | 504 | /* |
510 | * In case of parsing only part of user buf, | 505 | * In case of parsing only part of user buf, |
@@ -884,16 +879,10 @@ static ssize_t smk_set_cipso(struct file *file, const char __user *buf, | |||
884 | (count < SMK_CIPSOMIN || count > SMK_CIPSOMAX)) | 879 | (count < SMK_CIPSOMIN || count > SMK_CIPSOMAX)) |
885 | return -EINVAL; | 880 | return -EINVAL; |
886 | 881 | ||
887 | data = kzalloc(count + 1, GFP_KERNEL); | 882 | data = memdup_user_nul(buf, count); |
888 | if (data == NULL) | 883 | if (IS_ERR(data)) |
889 | return -ENOMEM; | 884 | return PTR_ERR(data); |
890 | |||
891 | if (copy_from_user(data, buf, count) != 0) { | ||
892 | rc = -EFAULT; | ||
893 | goto unlockedout; | ||
894 | } | ||
895 | 885 | ||
896 | data[count] = '\0'; | ||
897 | rule = data; | 886 | rule = data; |
898 | /* | 887 | /* |
899 | * Only allow one writer at a time. Writes should be | 888 | * Only allow one writer at a time. Writes should be |
@@ -946,7 +935,6 @@ static ssize_t smk_set_cipso(struct file *file, const char __user *buf, | |||
946 | 935 | ||
947 | out: | 936 | out: |
948 | mutex_unlock(&smack_cipso_lock); | 937 | mutex_unlock(&smack_cipso_lock); |
949 | unlockedout: | ||
950 | kfree(data); | 938 | kfree(data); |
951 | return rc; | 939 | return rc; |
952 | } | 940 | } |
@@ -1187,14 +1175,9 @@ static ssize_t smk_write_net4addr(struct file *file, const char __user *buf, | |||
1187 | if (count < SMK_NETLBLADDRMIN) | 1175 | if (count < SMK_NETLBLADDRMIN) |
1188 | return -EINVAL; | 1176 | return -EINVAL; |
1189 | 1177 | ||
1190 | data = kzalloc(count + 1, GFP_KERNEL); | 1178 | data = memdup_user_nul(buf, count); |
1191 | if (data == NULL) | 1179 | if (IS_ERR(data)) |
1192 | return -ENOMEM; | 1180 | return PTR_ERR(data); |
1193 | |||
1194 | if (copy_from_user(data, buf, count) != 0) { | ||
1195 | rc = -EFAULT; | ||
1196 | goto free_data_out; | ||
1197 | } | ||
1198 | 1181 | ||
1199 | smack = kzalloc(count + 1, GFP_KERNEL); | 1182 | smack = kzalloc(count + 1, GFP_KERNEL); |
1200 | if (smack == NULL) { | 1183 | if (smack == NULL) { |
@@ -1202,8 +1185,6 @@ static ssize_t smk_write_net4addr(struct file *file, const char __user *buf, | |||
1202 | goto free_data_out; | 1185 | goto free_data_out; |
1203 | } | 1186 | } |
1204 | 1187 | ||
1205 | data[count] = '\0'; | ||
1206 | |||
1207 | rc = sscanf(data, "%hhd.%hhd.%hhd.%hhd/%u %s", | 1188 | rc = sscanf(data, "%hhd.%hhd.%hhd.%hhd/%u %s", |
1208 | &host[0], &host[1], &host[2], &host[3], &masks, smack); | 1189 | &host[0], &host[1], &host[2], &host[3], &masks, smack); |
1209 | if (rc != 6) { | 1190 | if (rc != 6) { |
@@ -1454,14 +1435,9 @@ static ssize_t smk_write_net6addr(struct file *file, const char __user *buf, | |||
1454 | if (count < SMK_NETLBLADDRMIN) | 1435 | if (count < SMK_NETLBLADDRMIN) |
1455 | return -EINVAL; | 1436 | return -EINVAL; |
1456 | 1437 | ||
1457 | data = kzalloc(count + 1, GFP_KERNEL); | 1438 | data = memdup_user_nul(buf, count); |
1458 | if (data == NULL) | 1439 | if (IS_ERR(data)) |
1459 | return -ENOMEM; | 1440 | return PTR_ERR(data); |
1460 | |||
1461 | if (copy_from_user(data, buf, count) != 0) { | ||
1462 | rc = -EFAULT; | ||
1463 | goto free_data_out; | ||
1464 | } | ||
1465 | 1441 | ||
1466 | smack = kzalloc(count + 1, GFP_KERNEL); | 1442 | smack = kzalloc(count + 1, GFP_KERNEL); |
1467 | if (smack == NULL) { | 1443 | if (smack == NULL) { |
@@ -1469,8 +1445,6 @@ static ssize_t smk_write_net6addr(struct file *file, const char __user *buf, | |||
1469 | goto free_data_out; | 1445 | goto free_data_out; |
1470 | } | 1446 | } |
1471 | 1447 | ||
1472 | data[count] = '\0'; | ||
1473 | |||
1474 | i = sscanf(data, "%x:%x:%x:%x:%x:%x:%x:%x/%u %s", | 1448 | i = sscanf(data, "%x:%x:%x:%x:%x:%x:%x:%x/%u %s", |
1475 | &scanned[0], &scanned[1], &scanned[2], &scanned[3], | 1449 | &scanned[0], &scanned[1], &scanned[2], &scanned[3], |
1476 | &scanned[4], &scanned[5], &scanned[6], &scanned[7], | 1450 | &scanned[4], &scanned[5], &scanned[6], &scanned[7], |
@@ -1865,14 +1839,9 @@ static ssize_t smk_write_ambient(struct file *file, const char __user *buf, | |||
1865 | if (!smack_privileged(CAP_MAC_ADMIN)) | 1839 | if (!smack_privileged(CAP_MAC_ADMIN)) |
1866 | return -EPERM; | 1840 | return -EPERM; |
1867 | 1841 | ||
1868 | data = kzalloc(count + 1, GFP_KERNEL); | 1842 | data = memdup_user_nul(buf, count); |
1869 | if (data == NULL) | 1843 | if (IS_ERR(data)) |
1870 | return -ENOMEM; | 1844 | return PTR_ERR(data); |
1871 | |||
1872 | if (copy_from_user(data, buf, count) != 0) { | ||
1873 | rc = -EFAULT; | ||
1874 | goto out; | ||
1875 | } | ||
1876 | 1845 | ||
1877 | skp = smk_import_entry(data, count); | 1846 | skp = smk_import_entry(data, count); |
1878 | if (IS_ERR(skp)) { | 1847 | if (IS_ERR(skp)) { |
@@ -2041,14 +2010,9 @@ static ssize_t smk_write_onlycap(struct file *file, const char __user *buf, | |||
2041 | if (!smack_privileged(CAP_MAC_ADMIN)) | 2010 | if (!smack_privileged(CAP_MAC_ADMIN)) |
2042 | return -EPERM; | 2011 | return -EPERM; |
2043 | 2012 | ||
2044 | data = kzalloc(count + 1, GFP_KERNEL); | 2013 | data = memdup_user_nul(buf, count); |
2045 | if (data == NULL) | 2014 | if (IS_ERR(data)) |
2046 | return -ENOMEM; | 2015 | return PTR_ERR(data); |
2047 | |||
2048 | if (copy_from_user(data, buf, count) != 0) { | ||
2049 | kfree(data); | ||
2050 | return -EFAULT; | ||
2051 | } | ||
2052 | 2016 | ||
2053 | rc = smk_parse_label_list(data, &list_tmp); | 2017 | rc = smk_parse_label_list(data, &list_tmp); |
2054 | kfree(data); | 2018 | kfree(data); |
@@ -2133,14 +2097,9 @@ static ssize_t smk_write_unconfined(struct file *file, const char __user *buf, | |||
2133 | if (!smack_privileged(CAP_MAC_ADMIN)) | 2097 | if (!smack_privileged(CAP_MAC_ADMIN)) |
2134 | return -EPERM; | 2098 | return -EPERM; |
2135 | 2099 | ||
2136 | data = kzalloc(count + 1, GFP_KERNEL); | 2100 | data = memdup_user_nul(buf, count); |
2137 | if (data == NULL) | 2101 | if (IS_ERR(data)) |
2138 | return -ENOMEM; | 2102 | return PTR_ERR(data); |
2139 | |||
2140 | if (copy_from_user(data, buf, count) != 0) { | ||
2141 | rc = -EFAULT; | ||
2142 | goto freeout; | ||
2143 | } | ||
2144 | 2103 | ||
2145 | /* | 2104 | /* |
2146 | * Clear the smack_unconfined on invalid label errors. This means | 2105 | * Clear the smack_unconfined on invalid label errors. This means |
@@ -2696,19 +2655,15 @@ static ssize_t smk_write_syslog(struct file *file, const char __user *buf, | |||
2696 | if (!smack_privileged(CAP_MAC_ADMIN)) | 2655 | if (!smack_privileged(CAP_MAC_ADMIN)) |
2697 | return -EPERM; | 2656 | return -EPERM; |
2698 | 2657 | ||
2699 | data = kzalloc(count + 1, GFP_KERNEL); | 2658 | data = memdup_user_nul(buf, count); |
2700 | if (data == NULL) | 2659 | if (IS_ERR(data)) |
2701 | return -ENOMEM; | 2660 | return PTR_ERR(data); |
2702 | 2661 | ||
2703 | if (copy_from_user(data, buf, count) != 0) | 2662 | skp = smk_import_entry(data, count); |
2704 | rc = -EFAULT; | 2663 | if (IS_ERR(skp)) |
2705 | else { | 2664 | rc = PTR_ERR(skp); |
2706 | skp = smk_import_entry(data, count); | 2665 | else |
2707 | if (IS_ERR(skp)) | 2666 | smack_syslog_label = skp; |
2708 | rc = PTR_ERR(skp); | ||
2709 | else | ||
2710 | smack_syslog_label = skp; | ||
2711 | } | ||
2712 | 2667 | ||
2713 | kfree(data); | 2668 | kfree(data); |
2714 | return rc; | 2669 | return rc; |
@@ -2798,14 +2753,9 @@ static ssize_t smk_write_relabel_self(struct file *file, const char __user *buf, | |||
2798 | if (*ppos != 0) | 2753 | if (*ppos != 0) |
2799 | return -EINVAL; | 2754 | return -EINVAL; |
2800 | 2755 | ||
2801 | data = kzalloc(count + 1, GFP_KERNEL); | 2756 | data = memdup_user_nul(buf, count); |
2802 | if (data == NULL) | 2757 | if (IS_ERR(data)) |
2803 | return -ENOMEM; | 2758 | return PTR_ERR(data); |
2804 | |||
2805 | if (copy_from_user(data, buf, count) != 0) { | ||
2806 | kfree(data); | ||
2807 | return -EFAULT; | ||
2808 | } | ||
2809 | 2759 | ||
2810 | rc = smk_parse_label_list(data, &list_tmp); | 2760 | rc = smk_parse_label_list(data, &list_tmp); |
2811 | kfree(data); | 2761 | kfree(data); |
diff --git a/security/tomoyo/securityfs_if.c b/security/tomoyo/securityfs_if.c index 179a955b319d..06ab41b1ff28 100644 --- a/security/tomoyo/securityfs_if.c +++ b/security/tomoyo/securityfs_if.c | |||
@@ -43,13 +43,9 @@ static ssize_t tomoyo_write_self(struct file *file, const char __user *buf, | |||
43 | int error; | 43 | int error; |
44 | if (!count || count >= TOMOYO_EXEC_TMPSIZE - 10) | 44 | if (!count || count >= TOMOYO_EXEC_TMPSIZE - 10) |
45 | return -ENOMEM; | 45 | return -ENOMEM; |
46 | data = kzalloc(count + 1, GFP_NOFS); | 46 | data = memdup_user_nul(buf, count); |
47 | if (!data) | 47 | if (IS_ERR(data)) |
48 | return -ENOMEM; | 48 | return PTR_ERR(data); |
49 | if (copy_from_user(data, buf, count)) { | ||
50 | error = -EFAULT; | ||
51 | goto out; | ||
52 | } | ||
53 | tomoyo_normalize_line(data); | 49 | tomoyo_normalize_line(data); |
54 | if (tomoyo_correct_domain(data)) { | 50 | if (tomoyo_correct_domain(data)) { |
55 | const int idx = tomoyo_read_lock(); | 51 | const int idx = tomoyo_read_lock(); |
@@ -87,7 +83,6 @@ static ssize_t tomoyo_write_self(struct file *file, const char __user *buf, | |||
87 | tomoyo_read_unlock(idx); | 83 | tomoyo_read_unlock(idx); |
88 | } else | 84 | } else |
89 | error = -EINVAL; | 85 | error = -EINVAL; |
90 | out: | ||
91 | kfree(data); | 86 | kfree(data); |
92 | return error ? error : count; | 87 | return error ? error : count; |
93 | } | 88 | } |