From: Thorsten Blum <thorsten.blum@toblux.com>
To: arnd@arndb.de
Cc: amahesh@qti.qualcomm.com, gregkh@linuxfoundation.org,
linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
srinivas.kandagatla@linaro.org, thorsten.blum@toblux.com
Subject: [PATCH v2] misc: fastrpc: Use memdup_user()
Date: Wed, 8 May 2024 00:22:27 +0200 [thread overview]
Message-ID: <20240507222226.288074-2-thorsten.blum@toblux.com> (raw)
In-Reply-To: <29b33c18-f123-4656-8507-406c87a12ec8@app.fastmail.com>
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>
---
Changes in v2:
- Use u64_to_user_ptr() as suggested by Arnd Bergmann (thanks!)
- Preserve Acked-by: tag
---
drivers/misc/fastrpc.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 4c67e2c5a82e..694fc083b1bd 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -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);
--
2.45.0
next prev parent reply other threads:[~2024-05-07 22:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-07 20:12 [PATCH] misc: fastrpc: Use memdup_user() Thorsten Blum
2024-05-07 20:48 ` Arnd Bergmann
2024-05-07 22:22 ` Thorsten Blum [this message]
2024-05-27 8:44 ` [RESEND PATCH v2] " Thorsten Blum
2024-05-28 11:45 ` Srinivas Kandagatla
2024-05-28 11:45 ` [PATCH " Srinivas Kandagatla
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240507222226.288074-2-thorsten.blum@toblux.com \
--to=thorsten.blum@toblux.com \
--cc=amahesh@qti.qualcomm.com \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=srinivas.kandagatla@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).