public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rtl8723bs/ioctl_linux: Add a security check to copy_from_user()
@ 2018-12-24  0:13 Aditya Pakki
  2019-01-02  9:10 ` Dan Carpenter
  0 siblings, 1 reply; 2+ messages in thread
From: Aditya Pakki @ 2018-12-24  0:13 UTC (permalink / raw)
  To: pakki001
  Cc: kjlu, Greg Kroah-Hartman, Quytelda Kahja, Michael Straube,
	Mamta Shukla, Nathan Chancellor, Arushi Singhal, Jia-Ju Bai,
	devel, linux-kernel

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

Signed-off-by: Aditya Pakki <pakki001@umn.edu>
---
 drivers/staging/rtl8723bs/os_dep/ioctl_linux.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
index b8631baf128d..9992caa8c839 100644
--- a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
+++ b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
@@ -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;
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] rtl8723bs/ioctl_linux: Add a security check to copy_from_user()
  2018-12-24  0:13 [PATCH] rtl8723bs/ioctl_linux: Add a security check to copy_from_user() Aditya Pakki
@ 2019-01-02  9:10 ` Dan Carpenter
  0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2019-01-02  9:10 UTC (permalink / raw)
  To: Aditya Pakki
  Cc: Arushi Singhal, devel, Greg Kroah-Hartman, kjlu, linux-kernel,
	Mamta Shukla, Jia-Ju Bai, Nathan Chancellor, Quytelda Kahja

On Sun, Dec 23, 2018 at 06:13:02PM -0600, Aditya Pakki wrote:
> diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
> index b8631baf128d..9992caa8c839 100644
> --- a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
> +++ b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
> @@ -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;

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-01-02  9:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-24  0:13 [PATCH] rtl8723bs/ioctl_linux: Add a security check to copy_from_user() Aditya Pakki
2019-01-02  9:10 ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox