Skip to content

Commit f0f5336

Browse files
tobluxgregkh
authored andcommitted
misc: fastrpc: Use memdup_user()
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 <[email protected]> Acked-by: Arnd Bergmann <[email protected]> Signed-off-by: Srinivas Kandagatla <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 9d7eb23 commit f0f5336

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

drivers/misc/fastrpc.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,17 +1259,12 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl,
12591259
goto err;
12601260
}
12611261

1262-
name = kzalloc(init.namelen, GFP_KERNEL);
1263-
if (!name) {
1264-
err = -ENOMEM;
1262+
name = memdup_user(u64_to_user_ptr(init.name), init.namelen);
1263+
if (IS_ERR(name)) {
1264+
err = PTR_ERR(name);
12651265
goto err;
12661266
}
12671267

1268-
if (copy_from_user(name, (void __user *)(uintptr_t)init.name, init.namelen)) {
1269-
err = -EFAULT;
1270-
goto err_name;
1271-
}
1272-
12731268
if (!fl->cctx->remote_heap) {
12741269
err = fastrpc_remote_heap_alloc(fl, fl->sctx->dev, init.memlen,
12751270
&fl->cctx->remote_heap);

0 commit comments

Comments
 (0)