lkml.org 
[lkml]   [2021]   [Dec]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] staging: r8188eu: Use memdup_user instead of kmalloc/copy_from_user
On Fri, Dec 10, 2021 at 11:38:32AM +0800, Jiapeng Chong wrote:
> Fix following coccicheck warning:
>
> ./drivers/staging/r8188eu/os_dep/ioctl_linux.c:4253:8-15: WARNING
> opportunity for memdup_user.
>
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> ---
> drivers/staging/r8188eu/os_dep/ioctl_linux.c | 13 ++++---------
> 1 file changed, 4 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/staging/r8188eu/os_dep/ioctl_linux.c b/drivers/staging/r8188eu/os_dep/ioctl_linux.c
> index 56adfe4087a8..c6a2fbfe8f26 100644
> --- a/drivers/staging/r8188eu/os_dep/ioctl_linux.c
> +++ b/drivers/staging/r8188eu/os_dep/ioctl_linux.c
> @@ -4250,17 +4250,12 @@ static int rtw_test(
> DBG_88E("+%s\n", __func__);
> len = wrqu->data.length;
>
> - pbuf = kzalloc(len, GFP_KERNEL);
> - if (!pbuf) {
> - DBG_88E("%s: no memory!\n", __func__);
> - return -ENOMEM;
> - }
> -
> - if (copy_from_user(pbuf, wrqu->data.pointer, len)) {
> - kfree(pbuf);
> + pbuf = memdup_user(wrqu->data.pointer, len);

This code assumes that the user is going to give us a NUL terminated
string which is not necessarily true. The original code was buggy too.
Anyway, please fix it. Use strndup_user() and mention that it is a bug
fix in the commit message:

pbuf = strndup_user(wrqu->data.pointer, len);

Add a Fixes tag.

regards,
dan carpenter

\
 
 \ /
  Last update: 2021-12-10 09:30    [W:0.054 / U:0.232 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site