Skip to contentSkip to conversation

staging: r8188eu: Use strndup_user instead of kmalloc/copy_from_user

PATCH Superseded Jiapeng Chong 2 participants 2 messages Dec 13, 2021 – Dec 21, 2021 Staging

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 staging: r8188eu: Use strndup_user instead of kmalloc/copy_from_user

This code assumes that the user is going to give us a NUL terminated string which is not necessarily true.

Fix following coccicheck warning:

./drivers/staging/r8188eu/os_dep/ioctl_linux.c:4253:8-15: WARNING opportunity for memdup_user.

Fixes 2b42bd58b321 ("staging: r8188eu: introduce new os_dep dir for RTL8188eu driver")

---
Changes in v3:
-Delete useless printk, modified the commit message and fixes tag.

 drivers/staging/r8188eu/os_dep/ioctl_linux.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
drivers/staging/r8188eu/os_dep/ioctl_linux.c +3 -11
index 77728ba78d76..d8c28f279aa0 100644
@@ -4247,18 +4247,10 @@ static int rtw_test(
 
 	DBG_88E("+%s\n", __func__);
 	len = wrqu->data.length;
+	pbuf = strndup_user(wrqu->data.pointer, len);
+	if (IS_ERR(pbuf))
+		return PTR_ERR(pbuf);
 
-	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);
-		DBG_88E("%s: copy from user fail!\n", __func__);
-		return -EFAULT;
-	}
 	DBG_88E("%s: string =\"%s\"\n", __func__, pbuf);
 
 	ptmp = (char *)pbuf;
Signature · 1 line
2.20.1.7.g153144c
maintainer
#1 lore raw
Quoted 48 lines · Jiapeng Chong

This code assumes that the user is going to give us a NUL terminated string which is not necessarily true.

Fix following coccicheck warning:

./drivers/staging/r8188eu/os_dep/ioctl_linux.c:4253:8-15: WARNING opportunity for memdup_user.

Fixes 2b42bd58b321 ("staging: r8188eu: introduce new os_dep dir for RTL8188eu driver")

---
Changes in v3:
-Delete useless printk, modified the commit message and fixes tag.

 drivers/staging/r8188eu/os_dep/ioctl_linux.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
drivers/staging/r8188eu/os_dep/ioctl_linux.c +3 -11
index 77728ba78d76..d8c28f279aa0 100644
@@ -4247,18 +4247,10 @@ static int rtw_test(
 
 	DBG_88E("+%s\n", __func__);
 	len = wrqu->data.length;
+	pbuf = strndup_user(wrqu->data.pointer, len);
+	if (IS_ERR(pbuf))
+		return PTR_ERR(pbuf);
 
-	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);
-		DBG_88E("%s: copy from user fail!\n", __func__);
-		return -EFAULT;
-	}
 	DBG_88E("%s: string =\"%s\"\n", __func__, pbuf);
 
 	ptmp = (char *)pbuf;
Signature · 1 line
2.20.1.7.g153144c

This function does nothing, so it should just be deleted entirely. Please let's not have odd custom ioctls hanging around that can do nothing but cause problems.

Also, this function looks like a lovely way to crash a kernel, even with your fix, so the sooner we get it removed the better.

thanks,

greg k-h