]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
misc: fastrpc: Use memdup_user()
authorThorsten Blum <thorsten.blum@toblux.com>
Fri, 5 Jul 2024 07:58:55 +0000 (08:58 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 5 Jul 2024 08:01:42 +0000 (10:01 +0200)
Switching to memdup_user() overwrites the allocated memory only once,
whereas kzalloc() followed by copy_from_user() initializes the allocated
memory to zero and then immediately overwrites it.

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>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20240705075900.424100-2-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/misc/fastrpc.c

index 4c67e2c5a82e1f85f3e6e07e20b22d14b25f3051..694fc083b1bd3af616feb4dd09e5bc3fc93e055b 100644 (file)
@@ -1259,17 +1259,12 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl,
                goto err;
        }
 
-       name = kzalloc(init.namelen, GFP_KERNEL);
-       if (!name) {
-               err = -ENOMEM;
+       name = memdup_user(u64_to_user_ptr(init.name), init.namelen);
+       if (IS_ERR(name)) {
+               err = PTR_ERR(name);
                goto err;
        }
 
-       if (copy_from_user(name, (void __user *)(uintptr_t)init.name, init.namelen)) {
-               err = -EFAULT;
-               goto err_name;
-       }
-
        if (!fl->cctx->remote_heap) {
                err = fastrpc_remote_heap_alloc(fl, fl->sctx->dev, init.memlen,
                                                &fl->cctx->remote_heap);