Skip to contentSkip to conversation

rtl8723bs/ioctl_linux: Add a security check to copy_from_user()

PATCH In review Aditya Pakki 2 participants 2 messages Dec 24, 2018 – Jan 2, 2019 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rtl8723bs/ioctl_linux: Add a security check to copy_from_user()

Currently, the return value of copy_from_user is not checked. extra is assigned to u32wps_start irrespective of these failures.

---
 drivers/staging/rtl8723bs/os_dep/ioctl_linux.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/staging/rtl8723bs/os_dep/ioctl_linux.c +7 -2
index b8631baf128d..9992caa8c839 100644
@@ -2577,14 +2577,19 @@ static int rtw_wps_start(struct net_device *dev,
 	struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
 	struct iw_point *pdata = &wrqu->data;
 	u32   u32wps_start = 0;
-        unsigned int uintRet = 0;
 
 	if ((true == padapter->bDriverStopped) ||(true ==padapter->bSurpriseRemoved) || (NULL == pdata)) {
 		ret = -EINVAL;
 		goto exit;
 	}
 
-	uintRet = copy_from_user((void*)&u32wps_start, pdata->pointer, 4);
+	ret = copy_from_user((void *)&u32wps_start, pdata->pointer, 4);
+
+	if (ret) {
+		ret = -EINVAL;
+		goto exit;
+	}
+
 	if (u32wps_start == 0)
 		u32wps_start = *extra;
 
Signature · 1 line
2.17.1
#1 lore raw
Quoted 11 lines · Aditya Pakki
drivers/staging/rtl8723bs/os_dep/ioctl_linux.c +0 -1
index b8631baf128d..9992caa8c839 100644
@@ -2577,14 +2577,19 @@ static int rtw_wps_start(struct net_device *dev,
 	struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
 	struct iw_point *pdata = &wrqu->data;
 	u32   u32wps_start = 0;
-        unsigned int uintRet = 0;
 
 	if ((true == padapter->bDriverStopped) ||(true ==padapter->bSurpriseRemoved) || (NULL == pdata)) {

drivers/staging/rtl8723bs/os_dep/ioctl_linux.c static int rtw_wps_start(struct net_device *dev, · line 2590

Quoted 10 lines
drivers/staging/rtl8723bs/os_dep/ioctl_linux.c +5 -1
 		ret = -EINVAL;
 		goto exit;
 	}
 
-	uintRet = copy_from_user((void*)&u32wps_start, pdata->pointer, 4);
+	ret = copy_from_user((void *)&u32wps_start, pdata->pointer, 4);
+
+	if (ret) {
+		ret = -EINVAL;
+		goto exit;

Good eye for spotting this bug. :)

Really this function is not useful though so we should just delete it. All the CONFIG_INTEL_WIDI stuff is dead code.

Also if copy_from_user() the correct error code is -EFAULT. And we would normally write it like this:

	if (copy_from_user((void *)&u32wps_start, pdata->pointer, 4)) {
		ret = -EFAULT;
		goto exit;
	}

But in this case, since this is dead code we should just delete rtw_wps_start() and put a NULL in the rtw_private_handler[] array where it used to be.

regards,
dan carpenter