ima: use memdup_user_nul
authorGeliang Tang <geliangtang@gmail.com>
Sat, 6 May 2017 15:40:18 +0000 (23:40 +0800)
committerMimi Zohar <zohar@linux.vnet.ibm.com>
Wed, 21 Jun 2017 18:37:12 +0000 (14:37 -0400)
Use memdup_user_nul() helper instead of open-coding to simplify the
code.

Signed-off-by: Geliang Tang <geliangtang@gmail.com>
Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
security/integrity/ima/ima_fs.c

index ca303e5d2b9403d858c9df8f5512c80040b0f3f7..ad491c51e8339c8f497b218c7b007b7c12a98ce4 100644 (file)
@@ -323,16 +323,11 @@ static ssize_t ima_write_policy(struct file *file, const char __user *buf,
        if (*ppos != 0)
                goto out;
 
-       result = -ENOMEM;
-       data = kmalloc(datalen + 1, GFP_KERNEL);
-       if (!data)
+       data = memdup_user_nul(buf, datalen);
+       if (IS_ERR(data)) {
+               result = PTR_ERR(data);
                goto out;
-
-       *(data + datalen) = '\0';
-
-       result = -EFAULT;
-       if (copy_from_user(data, buf, datalen))
-               goto out_free;
+       }
 
        result = mutex_lock_interruptible(&ima_write_mutex);
        if (result < 0)