BACKPORT: Smack: Use memdup_user() rather than duplicating its implementation
authorMarkus Elfring <elfring@users.sourceforge.net>
Sun, 21 Aug 2016 18:17:36 +0000 (20:17 +0200)
committerRafal Krypa <r.krypa@samsung.com>
Mon, 21 Nov 2016 14:37:05 +0000 (15:37 +0100)
Reuse existing functionality from memdup_user() instead of keeping
duplicate source code.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Acked-by: Casey Schaufler <casey@schaufler-ca.com>
(cherry-picked from upstream 63e24c497158c066583b9c06378d89ace694265a)

security/smack/smackfs.c

index 94bd9e41c9ecb39ce3d432f9c3734a5db7e1b353..8ab5290fb8f37af1cfd07ba8dbec441c26f89289 100644 (file)
@@ -2564,14 +2564,9 @@ static ssize_t smk_write_revoke_subj(struct file *file, const char __user *buf,
        if (count == 0 || count > SMK_LONGLABEL)
                return -EINVAL;
 
-       data = kzalloc(count, GFP_KERNEL);
-       if (data == NULL)
-               return -ENOMEM;
-
-       if (copy_from_user(data, buf, count) != 0) {
-               rc = -EFAULT;
-               goto out_data;
-       }
+       data = memdup_user(buf, count);
+       if (IS_ERR(data))
+               return PTR_ERR(data);
 
        cp = smk_parse_smack(data, count);
        if (IS_ERR(cp)) {