aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/xtensa/platforms/iss/simdisk.c12
-rw-r--r--drivers/net/wireless/ath/wil6210/debugfs.c12
-rw-r--r--drivers/s390/char/vmcp.c11
-rw-r--r--drivers/sbus/char/openprom.c13
-rw-r--r--fs/afs/proc.c25
-rw-r--r--fs/cachefiles/daemon.c12
-rw-r--r--fs/dlm/user.c11
-rw-r--r--kernel/trace/blktrace.c12
-rw-r--r--lib/dynamic_debug.c11
-rw-r--r--net/rxrpc/ar-key.c24
-rw-r--r--security/smack/smackfs.c114
-rw-r--r--security/tomoyo/securityfs_if.c11
12 files changed, 71 insertions, 197 deletions
diff --git a/arch/xtensa/platforms/iss/simdisk.c b/arch/xtensa/platforms/iss/simdisk.c
index 3c3ace2c46b6..f58a4e6472cb 100644
--- a/arch/xtensa/platforms/iss/simdisk.c
+++ b/arch/xtensa/platforms/iss/simdisk.c
@@ -227,16 +227,12 @@ static ssize_t proc_read_simdisk(struct file *file, char __user *buf,
227static ssize_t proc_write_simdisk(struct file *file, const char __user *buf, 227static ssize_t proc_write_simdisk(struct file *file, const char __user *buf,
228 size_t count, loff_t *ppos) 228 size_t count, loff_t *ppos)
229{ 229{
230 char *tmp = kmalloc(count + 1, GFP_KERNEL); 230 char *tmp = memdup_user_nul(buf, count);
231 struct simdisk *dev = PDE_DATA(file_inode(file)); 231 struct simdisk *dev = PDE_DATA(file_inode(file));
232 int err; 232 int err;
233 233
234 if (tmp == NULL) 234 if (IS_ERR(tmp))
235 return -ENOMEM; 235 return PTR_ERR(tmp);
236 if (copy_from_user(tmp, buf, count)) {
237 err = -EFAULT;
238 goto out_free;
239 }
240 236
241 err = simdisk_detach(dev); 237 err = simdisk_detach(dev);
242 if (err != 0) 238 if (err != 0)
@@ -244,8 +240,6 @@ static ssize_t proc_write_simdisk(struct file *file, const char __user *buf,
244 240
245 if (count > 0 && tmp[count - 1] == '\n') 241 if (count > 0 && tmp[count - 1] == '\n')
246 tmp[count - 1] = 0; 242 tmp[count - 1] = 0;
247 else
248 tmp[count] = 0;
249 243
250 if (tmp[0]) 244 if (tmp[0])
251 err = simdisk_attach(dev, tmp); 245 err = simdisk_attach(dev, tmp);
diff --git a/drivers/net/wireless/ath/wil6210/debugfs.c b/drivers/net/wireless/ath/wil6210/debugfs.c
index 97bc186f9728..a1d10b85989f 100644
--- a/drivers/net/wireless/ath/wil6210/debugfs.c
+++ b/drivers/net/wireless/ath/wil6210/debugfs.c
@@ -580,16 +580,10 @@ static ssize_t wil_write_file_rxon(struct file *file, const char __user *buf,
580 long channel; 580 long channel;
581 bool on; 581 bool on;
582 582
583 char *kbuf = kmalloc(len + 1, GFP_KERNEL); 583 char *kbuf = memdup_user_nul(buf, len);
584
585 if (!kbuf)
586 return -ENOMEM;
587 if (copy_from_user(kbuf, buf, len)) {
588 kfree(kbuf);
589 return -EIO;
590 }
591 584
592 kbuf[len] = '\0'; 585 if (IS_ERR(kbuf))
586 return PTR_ERR(kbuf);
593 rc = kstrtol(kbuf, 0, &channel); 587 rc = kstrtol(kbuf, 0, &channel);
594 kfree(kbuf); 588 kfree(kbuf);
595 if (rc) 589 if (rc)
diff --git a/drivers/s390/char/vmcp.c b/drivers/s390/char/vmcp.c
index 0fdedadff7bc..2a67b496a9e2 100644
--- a/drivers/s390/char/vmcp.c
+++ b/drivers/s390/char/vmcp.c
@@ -88,14 +88,9 @@ vmcp_write(struct file *file, const char __user *buff, size_t count,
88 88
89 if (count > 240) 89 if (count > 240)
90 return -EINVAL; 90 return -EINVAL;
91 cmd = kmalloc(count + 1, GFP_KERNEL); 91 cmd = memdup_user_nul(buff, count);
92 if (!cmd) 92 if (IS_ERR(cmd))
93 return -ENOMEM; 93 return PTR_ERR(cmd);
94 if (copy_from_user(cmd, buff, count)) {
95 kfree(cmd);
96 return -EFAULT;
97 }
98 cmd[count] = '\0';
99 session = file->private_data; 94 session = file->private_data;
100 if (mutex_lock_interruptible(&session->mutex)) { 95 if (mutex_lock_interruptible(&session->mutex)) {
101 kfree(cmd); 96 kfree(cmd);
diff --git a/drivers/sbus/char/openprom.c b/drivers/sbus/char/openprom.c
index 5843288f64bc..e077ebd89319 100644
--- a/drivers/sbus/char/openprom.c
+++ b/drivers/sbus/char/openprom.c
@@ -390,16 +390,9 @@ static int copyin_string(char __user *user, size_t len, char **ptr)
390 if ((ssize_t)len < 0 || (ssize_t)(len + 1) < 0) 390 if ((ssize_t)len < 0 || (ssize_t)(len + 1) < 0)
391 return -EINVAL; 391 return -EINVAL;
392 392
393 tmp = kmalloc(len + 1, GFP_KERNEL); 393 tmp = memdup_user_nul(user, len);
394 if (!tmp) 394 if (IS_ERR(tmp))
395 return -ENOMEM; 395 return PTR_ERR(tmp);
396
397 if (copy_from_user(tmp, user, len)) {
398 kfree(tmp);
399 return -EFAULT;
400 }
401
402 tmp[len] = '\0';
403 396
404 *ptr = tmp; 397 *ptr = tmp;
405 398
diff --git a/fs/afs/proc.c b/fs/afs/proc.c
index 24a905b076fd..2853b4095344 100644
--- a/fs/afs/proc.c
+++ b/fs/afs/proc.c
@@ -230,14 +230,9 @@ static ssize_t afs_proc_cells_write(struct file *file, const char __user *buf,
230 if (size <= 1 || size >= PAGE_SIZE) 230 if (size <= 1 || size >= PAGE_SIZE)
231 return -EINVAL; 231 return -EINVAL;
232 232
233 kbuf = kmalloc(size + 1, GFP_KERNEL); 233 kbuf = memdup_user_nul(buf, size);
234 if (!kbuf) 234 if (IS_ERR(kbuf))
235 return -ENOMEM; 235 return PTR_ERR(kbuf);
236
237 ret = -EFAULT;
238 if (copy_from_user(kbuf, buf, size) != 0)
239 goto done;
240 kbuf[size] = 0;
241 236
242 /* trim to first NL */ 237 /* trim to first NL */
243 name = memchr(kbuf, '\n', size); 238 name = memchr(kbuf, '\n', size);
@@ -315,15 +310,9 @@ static ssize_t afs_proc_rootcell_write(struct file *file,
315 if (size <= 1 || size >= PAGE_SIZE) 310 if (size <= 1 || size >= PAGE_SIZE)
316 return -EINVAL; 311 return -EINVAL;
317 312
318 ret = -ENOMEM; 313 kbuf = memdup_user_nul(buf, size);
319 kbuf = kmalloc(size + 1, GFP_KERNEL); 314 if (IS_ERR(kbuf))
320 if (!kbuf) 315 return PTR_ERR(kbuf);
321 goto nomem;
322
323 ret = -EFAULT;
324 if (copy_from_user(kbuf, buf, size) != 0)
325 goto infault;
326 kbuf[size] = 0;
327 316
328 /* trim to first NL */ 317 /* trim to first NL */
329 s = memchr(kbuf, '\n', size); 318 s = memchr(kbuf, '\n', size);
@@ -337,9 +326,7 @@ static ssize_t afs_proc_rootcell_write(struct file *file,
337 if (ret >= 0) 326 if (ret >= 0)
338 ret = size; /* consume everything, always */ 327 ret = size; /* consume everything, always */
339 328
340infault:
341 kfree(kbuf); 329 kfree(kbuf);
342nomem:
343 _leave(" = %d", ret); 330 _leave(" = %d", ret);
344 return ret; 331 return ret;
345} 332}
diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
index f601def05bdf..452e98dd7560 100644
--- a/fs/cachefiles/daemon.c
+++ b/fs/cachefiles/daemon.c
@@ -226,15 +226,9 @@ static ssize_t cachefiles_daemon_write(struct file *file,
226 return -EOPNOTSUPP; 226 return -EOPNOTSUPP;
227 227
228 /* drag the command string into the kernel so we can parse it */ 228 /* drag the command string into the kernel so we can parse it */
229 data = kmalloc(datalen + 1, GFP_KERNEL); 229 data = memdup_user_nul(_data, datalen);
230 if (!data) 230 if (IS_ERR(data))
231 return -ENOMEM; 231 return PTR_ERR(data);
232
233 ret = -EFAULT;
234 if (copy_from_user(data, _data, datalen) != 0)
235 goto error;
236
237 data[datalen] = '\0';
238 232
239 ret = -EINVAL; 233 ret = -EINVAL;
240 if (memchr(data, '\0', datalen)) 234 if (memchr(data, '\0', datalen))
diff --git a/fs/dlm/user.c b/fs/dlm/user.c
index 173b3873a4f4..1925d6d222b8 100644
--- a/fs/dlm/user.c
+++ b/fs/dlm/user.c
@@ -515,14 +515,9 @@ static ssize_t device_write(struct file *file, const char __user *buf,
515 if (count > sizeof(struct dlm_write_request) + DLM_RESNAME_MAXLEN) 515 if (count > sizeof(struct dlm_write_request) + DLM_RESNAME_MAXLEN)
516 return -EINVAL; 516 return -EINVAL;
517 517
518 kbuf = kzalloc(count + 1, GFP_NOFS); 518 kbuf = memdup_user_nul(buf, count);
519 if (!kbuf) 519 if (!IS_ERR(kbuf))
520 return -ENOMEM; 520 return PTR_ERR(kbuf);
521
522 if (copy_from_user(kbuf, buf, count)) {
523 error = -EFAULT;
524 goto out_free;
525 }
526 521
527 if (check_version(kbuf)) { 522 if (check_version(kbuf)) {
528 error = -EBADE; 523 error = -EBADE;
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index a990824c8604..2aeb6ffc0a1e 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -349,16 +349,10 @@ static ssize_t blk_msg_write(struct file *filp, const char __user *buffer,
349 if (count >= BLK_TN_MAX_MSG) 349 if (count >= BLK_TN_MAX_MSG)
350 return -EINVAL; 350 return -EINVAL;
351 351
352 msg = kmalloc(count + 1, GFP_KERNEL); 352 msg = memdup_user_nul(buffer, count);
353 if (msg == NULL) 353 if (IS_ERR(msg))
354 return -ENOMEM; 354 return PTR_ERR(msg);
355
356 if (copy_from_user(msg, buffer, count)) {
357 kfree(msg);
358 return -EFAULT;
359 }
360 355
361 msg[count] = '\0';
362 bt = filp->private_data; 356 bt = filp->private_data;
363 __trace_note_message(bt, "%s", msg); 357 __trace_note_message(bt, "%s", msg);
364 kfree(msg); 358 kfree(msg);
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index e3952e9c8ec0..fe42b6ec3f0c 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -657,14 +657,9 @@ static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf,
657 pr_warn("expected <%d bytes into control\n", USER_BUF_PAGE); 657 pr_warn("expected <%d bytes into control\n", USER_BUF_PAGE);
658 return -E2BIG; 658 return -E2BIG;
659 } 659 }
660 tmpbuf = kmalloc(len + 1, GFP_KERNEL); 660 tmpbuf = memdup_user_nul(ubuf, len);
661 if (!tmpbuf) 661 if (IS_ERR(tmpbuf))
662 return -ENOMEM; 662 return PTR_ERR(tmpbuf);
663 if (copy_from_user(tmpbuf, ubuf, len)) {
664 kfree(tmpbuf);
665 return -EFAULT;
666 }
667 tmpbuf[len] = '\0';
668 vpr_info("read %d bytes from userspace\n", (int)len); 663 vpr_info("read %d bytes from userspace\n", (int)len);
669 664
670 ret = ddebug_exec_queries(tmpbuf, NULL); 665 ret = ddebug_exec_queries(tmpbuf, NULL);
diff --git a/net/rxrpc/ar-key.c b/net/rxrpc/ar-key.c
index da3cc09f683e..3f6571651d32 100644
--- a/net/rxrpc/ar-key.c
+++ b/net/rxrpc/ar-key.c
@@ -896,15 +896,9 @@ int rxrpc_request_key(struct rxrpc_sock *rx, char __user *optval, int optlen)
896 if (optlen <= 0 || optlen > PAGE_SIZE - 1) 896 if (optlen <= 0 || optlen > PAGE_SIZE - 1)
897 return -EINVAL; 897 return -EINVAL;
898 898
899 description = kmalloc(optlen + 1, GFP_KERNEL); 899 description = memdup_user_nul(optval, optlen);
900 if (!description) 900 if (IS_ERR(description))
901 return -ENOMEM; 901 return PTR_ERR(description);
902
903 if (copy_from_user(description, optval, optlen)) {
904 kfree(description);
905 return -EFAULT;
906 }
907 description[optlen] = 0;
908 902
909 key = request_key(&key_type_rxrpc, description, NULL); 903 key = request_key(&key_type_rxrpc, description, NULL);
910 if (IS_ERR(key)) { 904 if (IS_ERR(key)) {
@@ -933,15 +927,9 @@ int rxrpc_server_keyring(struct rxrpc_sock *rx, char __user *optval,
933 if (optlen <= 0 || optlen > PAGE_SIZE - 1) 927 if (optlen <= 0 || optlen > PAGE_SIZE - 1)
934 return -EINVAL; 928 return -EINVAL;
935 929
936 description = kmalloc(optlen + 1, GFP_KERNEL); 930 description = memdup_user_nul(optval, optlen);
937 if (!description) 931 if (IS_ERR(description))
938 return -ENOMEM; 932 return PTR_ERR(description);
939
940 if (copy_from_user(description, optval, optlen)) {
941 kfree(description);
942 return -EFAULT;
943 }
944 description[optlen] = 0;
945 933
946 key = request_key(&key_type_keyring, description, NULL); 934 key = request_key(&key_type_keyring, description, NULL);
947 if (IS_ERR(key)) { 935 if (IS_ERR(key)) {
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
947out: 936out:
948 mutex_unlock(&smack_cipso_lock); 937 mutex_unlock(&smack_cipso_lock);
949unlockedout:
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;
90out:
91 kfree(data); 86 kfree(data);
92 return error ? error : count; 87 return error ? error : count;
93} 88}