]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
platform/x86/amd/pmf: Use memdup_user()
authorThorsten Blum <thorsten.blum@toblux.com>
Mon, 27 May 2024 08:36:29 +0000 (10:36 +0200)
committerIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Mon, 27 May 2024 10:11:21 +0000 (13:11 +0300)
Switch to memdup_user() to overwrite the allocated memory only once
instead of initializing the allocated memory to zero with kzalloc() and
then immediately overwriting it with copy_from_user().

Fixes the following Coccinelle/coccicheck warning reported by
memdup_user.cocci:

WARNING opportunity for memdup_user

Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
Link: https://lore.kernel.org/r/20240527083628.210491-2-thorsten.blum@toblux.com
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
drivers/platform/x86/amd/pmf/tee-if.c

index b438de4d6bfcea2bd8f7b2c39a4df3bea438ddc2..1b53cabc9aa2c6bf777c059327d545dbb33d74a2 100644 (file)
@@ -301,14 +301,9 @@ static ssize_t amd_pmf_get_pb_data(struct file *filp, const char __user *buf,
                return -EINVAL;
 
        /* re-alloc to the new buffer length of the policy binary */
-       new_policy_buf = kzalloc(length, GFP_KERNEL);
-       if (!new_policy_buf)
-               return -ENOMEM;
-
-       if (copy_from_user(new_policy_buf, buf, length)) {
-               kfree(new_policy_buf);
-               return -EFAULT;
-       }
+       new_policy_buf = memdup_user(buf, length);
+       if (IS_ERR(new_policy_buf))
+               return PTR_ERR(new_policy_buf);
 
        kfree(dev->policy_buf);
        dev->policy_buf = new_policy_buf;