staging: r8188eu: Use memdup_user instead of kmalloc/copy_from_user
PATCH 1/1 staging: r8188eu: Use memdup_user instead of kmalloc/copy_from_user
Fix following coccicheck warning:
./drivers/staging/r8188eu/os_dep/ioctl_linux.c:4253:8-15: WARNING opportunity for memdup_user.
Reported-by Abaci Robot <[email protected]>
Signed-off-by Jiapeng Chong <[email protected]>
--- drivers/staging/r8188eu/os_dep/ioctl_linux.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/staging/r8188eu/os_dep/ioctl_linux.c +4 -9
@@ -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); +if (IS_ERR (pbuf)) {DBG_88E ("%s: copy from user fail!\n" , __func__); -return -EFAULT ; +return PTR_ERR (pbuf); } +DBG_88E ("%s: string =\"%s\"\n" , __func__, pbuf); ptmp = (char *)pbuf;
Signature · 1 line
2.34.0
Quoted 18 lines · Jiapeng Chong
Fix following coccicheck warning:
./drivers/staging/r8188eu/os_dep/ioctl_linux.c:4253:8-15: WARNING opportunity for
memdup_user.Reported-by Abaci Robot <[email protected]>Signed-off-by Jiapeng Chong <[email protected]>--- drivers/staging/r8188eu/os_dep/ioctl_linux.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)drivers/staging/r8188eu/os_dep/ioctl_linux.c +0
-0@@ -4250,17 +4250,12 @@ static int rtw_test(DBG_88E ("+%s\n" , __func__); len = wrqu->data.length;
drivers/staging/r8188eu/os_dep/ioctl_linux.c static int rtw_test( · line 4253
Quoted 10 lines
drivers/staging/r8188eu/os_dep/ioctl_linux.c +1
-8- 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