aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/user_namespace.c
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2015-12-24 00:13:10 -0500
committerAl Viro <viro@zeniv.linux.org.uk>2016-01-04 10:27:55 -0500
commit70f6cbb6f9c95535acd327d1ac1ce5fd078cff1e (patch)
treef92ea2549bcdf2e69ccdef737cef0e7a14dc0292 /kernel/user_namespace.c
parente4e85bb091d13afef7b1a10b4bd209b442be8863 (diff)
kernel/*: switch to memdup_user_nul()
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'kernel/user_namespace.c')
-rw-r--r--kernel/user_namespace.c21
1 files changed, 7 insertions, 14 deletions
diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
index 88fefa68c516..9bafc211930c 100644
--- a/kernel/user_namespace.c
+++ b/kernel/user_namespace.c
@@ -602,8 +602,7 @@ static ssize_t map_write(struct file *file, const char __user *buf,
602 struct uid_gid_map new_map; 602 struct uid_gid_map new_map;
603 unsigned idx; 603 unsigned idx;
604 struct uid_gid_extent *extent = NULL; 604 struct uid_gid_extent *extent = NULL;
605 unsigned long page = 0; 605 char *kbuf = NULL, *pos, *next_line;
606 char *kbuf, *pos, *next_line;
607 ssize_t ret = -EINVAL; 606 ssize_t ret = -EINVAL;
608 607
609 /* 608 /*
@@ -638,23 +637,18 @@ static ssize_t map_write(struct file *file, const char __user *buf,
638 if (cap_valid(cap_setid) && !file_ns_capable(file, ns, CAP_SYS_ADMIN)) 637 if (cap_valid(cap_setid) && !file_ns_capable(file, ns, CAP_SYS_ADMIN))
639 goto out; 638 goto out;
640 639
641 /* Get a buffer */
642 ret = -ENOMEM;
643 page = __get_free_page(GFP_TEMPORARY);
644 kbuf = (char *) page;
645 if (!page)
646 goto out;
647
648 /* Only allow < page size writes at the beginning of the file */ 640 /* Only allow < page size writes at the beginning of the file */
649 ret = -EINVAL; 641 ret = -EINVAL;
650 if ((*ppos != 0) || (count >= PAGE_SIZE)) 642 if ((*ppos != 0) || (count >= PAGE_SIZE))
651 goto out; 643 goto out;
652 644
653 /* Slurp in the user data */ 645 /* Slurp in the user data */
654 ret = -EFAULT; 646 kbuf = memdup_user_nul(buf, count);
655 if (copy_from_user(kbuf, buf, count)) 647 if (IS_ERR(kbuf)) {
648 ret = PTR_ERR(kbuf);
649 kbuf = NULL;
656 goto out; 650 goto out;
657 kbuf[count] = '\0'; 651 }
658 652
659 /* Parse the user data */ 653 /* Parse the user data */
660 ret = -EINVAL; 654 ret = -EINVAL;
@@ -756,8 +750,7 @@ static ssize_t map_write(struct file *file, const char __user *buf,
756 ret = count; 750 ret = count;
757out: 751out:
758 mutex_unlock(&userns_state_mutex); 752 mutex_unlock(&userns_state_mutex);
759 if (page) 753 kfree(kbuf);
760 free_page(page);
761 return ret; 754 return ret;
762} 755}
763 756