All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: r8188eu: fix a potential NULL pointer dereference
@ 2022-04-23 18:47 Vihas Makwana
  2022-04-23 23:47 ` Fabio M. De Francesco
  2022-04-25  8:22 ` Dan Carpenter
  0 siblings, 2 replies; 5+ messages in thread
From: Vihas Makwana @ 2022-04-23 18:47 UTC (permalink / raw)
  To: Larry Finger, Phillip Potter, Greg Kroah-Hartman, Michael Straube
  Cc: linux-staging, linux-kernel, Dan Carpenter, Pavel Skripkin,
	Vihas Makwana

recvframe_chk_defrag() performs a NULL check on psta, but if that check
fails then it dereferences it, which it shouldn't do as psta is NULL.

Set pdefrag_q to NULL if above check fails and let the code after it handle
that case.

Fixes: 1cc18a22b96b ("staging: r8188eu: Add files for new driver - part 5")
Signed-off-by: Vihas Makwana <makvihas@gmail.com>
---
 drivers/staging/r8188eu/core/rtw_recv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/r8188eu/core/rtw_recv.c b/drivers/staging/r8188eu/core/rtw_recv.c
index c1005ddaa..db54bceff 100644
--- a/drivers/staging/r8188eu/core/rtw_recv.c
+++ b/drivers/staging/r8188eu/core/rtw_recv.c
@@ -1244,7 +1244,7 @@ struct recv_frame *recvframe_chk_defrag(struct adapter *padapter, struct recv_fr
 			pdefrag_q = NULL;
 		}
 	} else {
-		pdefrag_q = &psta->sta_recvpriv.defrag_q;
+		pdefrag_q = NULL;
 	}
 
 	if ((ismfrag == 0) && (fragnum == 0))
-- 
2.30.2


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

* Re: [PATCH] staging: r8188eu: fix a potential NULL pointer dereference
  2022-04-23 18:47 [PATCH] staging: r8188eu: fix a potential NULL pointer dereference Vihas Makwana
@ 2022-04-23 23:47 ` Fabio M. De Francesco
  2022-04-24  9:27   ` Vihas Makwana
  2022-04-25  8:22 ` Dan Carpenter
  1 sibling, 1 reply; 5+ messages in thread
From: Fabio M. De Francesco @ 2022-04-23 23:47 UTC (permalink / raw)
  To: Larry Finger, Phillip Potter, Greg Kroah-Hartman,
	Michael Straube, Vihas Makwana
  Cc: linux-staging, linux-kernel, Dan Carpenter, Pavel Skripkin,
	Vihas Makwana

On sabato 23 aprile 2022 20:47:48 CEST Vihas Makwana wrote:
> recvframe_chk_defrag() performs a NULL check on psta, but if that check
> fails then it dereferences it, which it shouldn't do as psta is NULL.
> 
> Set pdefrag_q to NULL if above check fails and let the code after it 
handle
> that case.
> 
> Fixes: 1cc18a22b96b ("staging: r8188eu: Add files for new driver - part 
5")
> Signed-off-by: Vihas Makwana <makvihas@gmail.com>
> ---
>  drivers/staging/r8188eu/core/rtw_recv.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/r8188eu/core/rtw_recv.c b/drivers/staging/
r8188eu/core/rtw_recv.c
> index c1005ddaa..db54bceff 100644
> --- a/drivers/staging/r8188eu/core/rtw_recv.c
> +++ b/drivers/staging/r8188eu/core/rtw_recv.c
> @@ -1244,7 +1244,7 @@ struct recv_frame *recvframe_chk_defrag(struct 
adapter *padapter, struct recv_fr
>  			pdefrag_q = NULL;
>  		}
>  	} else {
> -		pdefrag_q = &psta->sta_recvpriv.defrag_q;
> +		pdefrag_q = NULL;

Hi Vihas,

To me the code looks like this...

	struct sta_info *psta;
	...
	psta = rtw_get_stainfo(pstapriv, psta_addr);
	/* The code is about to test if "psta" is a valid pointer */
	if (!psta) {
		/* "psta" is NULL */		
		...
	} else {
		/* "psta" is not NULL */
		...

>  	}
>  

Also, even if "psta" were NULL (but it isn't), your change would still be 
no good.

Please be very careful with these types of changes next time :)

Thanks,

Fabio M. De Francesco

>  	if ((ismfrag == 0) && (fragnum == 0))
> -- 
> 2.30.2
>  




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

* Re: [PATCH] staging: r8188eu: fix a potential NULL pointer dereference
  2022-04-23 23:47 ` Fabio M. De Francesco
@ 2022-04-24  9:27   ` Vihas Makwana
  2022-04-24  9:47     ` Vihas Makwana
  0 siblings, 1 reply; 5+ messages in thread
From: Vihas Makwana @ 2022-04-24  9:27 UTC (permalink / raw)
  To: Fabio M. De Francesco
  Cc: Larry Finger, Phillip Potter, Greg Kroah-Hartman,
	Michael Straube, linux-staging, linux-kernel, Dan Carpenter,
	Pavel Skripkin

On Sun, Apr 24, 2022 at 5:17 AM Fabio M. De Francesco
<fmdefrancesco@gmail.com> wrote:
>
> On sabato 23 aprile 2022 20:47:48 CEST Vihas Makwana wrote:
> > recvframe_chk_defrag() performs a NULL check on psta, but if that check
> > fails then it dereferences it, which it shouldn't do as psta is NULL.
> >
> > Set pdefrag_q to NULL if above check fails and let the code after it
> handle
> > that case.
> >
> > Fixes: 1cc18a22b96b ("staging: r8188eu: Add files for new driver - part
> 5")
> > Signed-off-by: Vihas Makwana <makvihas@gmail.com>
> > ---
> >  drivers/staging/r8188eu/core/rtw_recv.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/staging/r8188eu/core/rtw_recv.c b/drivers/staging/
> r8188eu/core/rtw_recv.c
> > index c1005ddaa..db54bceff 100644
> > --- a/drivers/staging/r8188eu/core/rtw_recv.c
> > +++ b/drivers/staging/r8188eu/core/rtw_recv.c
> > @@ -1244,7 +1244,7 @@ struct recv_frame *recvframe_chk_defrag(struct
> adapter *padapter, struct recv_fr
> >                       pdefrag_q = NULL;
> >               }
> >       } else {
> > -             pdefrag_q = &psta->sta_recvpriv.defrag_q;
> > +             pdefrag_q = NULL;
>
> Hi Vihas,
>
> To me the code looks like this...
>
>         struct sta_info *psta;
>         ...
>         psta = rtw_get_stainfo(pstapriv, psta_addr);
>         /* The code is about to test if "psta" is a valid pointer */
>         if (!psta) {
>                 /* "psta" is NULL */
>                 ...
>         } else {
>                 /* "psta" is not NULL */
>                 ...
>
> >       }
> >
>
> Also, even if "psta" were NULL (but it isn't), your change would still be
> no good.
>
> Please be very careful with these types of changes next time :)
>
> Thanks,
>
> Fabio M. De Francesco
>
> >       if ((ismfrag == 0) && (fragnum == 0))
> > --
Oh yea, sorry about this. I don't know how I missed this.
Thanks for clarification Fabio. Will take care next time.


-- 
Thanks,
Vihas

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

* Re: [PATCH] staging: r8188eu: fix a potential NULL pointer dereference
  2022-04-24  9:27   ` Vihas Makwana
@ 2022-04-24  9:47     ` Vihas Makwana
  0 siblings, 0 replies; 5+ messages in thread
From: Vihas Makwana @ 2022-04-24  9:47 UTC (permalink / raw)
  To: Fabio M. De Francesco
  Cc: Larry Finger, Phillip Potter, Greg Kroah-Hartman,
	Michael Straube, linux-staging, linux-kernel, Dan Carpenter,
	Pavel Skripkin

Please ignore this patch, Greg.

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

* Re: [PATCH] staging: r8188eu: fix a potential NULL pointer dereference
  2022-04-23 18:47 [PATCH] staging: r8188eu: fix a potential NULL pointer dereference Vihas Makwana
  2022-04-23 23:47 ` Fabio M. De Francesco
@ 2022-04-25  8:22 ` Dan Carpenter
  1 sibling, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2022-04-25  8:22 UTC (permalink / raw)
  To: Vihas Makwana
  Cc: Larry Finger, Phillip Potter, Greg Kroah-Hartman,
	Michael Straube, linux-staging, linux-kernel, Pavel Skripkin

On Sun, Apr 24, 2022 at 12:17:48AM +0530, Vihas Makwana wrote:
> recvframe_chk_defrag() performs a NULL check on psta, but if that check
> fails then it dereferences it, which it shouldn't do as psta is NULL.
> 
> Set pdefrag_q to NULL if above check fails and let the code after it handle
> that case.
> 
> Fixes: 1cc18a22b96b ("staging: r8188eu: Add files for new driver - part 5")
> Signed-off-by: Vihas Makwana <makvihas@gmail.com>
> ---
>  drivers/staging/r8188eu/core/rtw_recv.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/r8188eu/core/rtw_recv.c b/drivers/staging/r8188eu/core/rtw_recv.c
> index c1005ddaa..db54bceff 100644
> --- a/drivers/staging/r8188eu/core/rtw_recv.c
> +++ b/drivers/staging/r8188eu/core/rtw_recv.c
> @@ -1244,7 +1244,7 @@ struct recv_frame *recvframe_chk_defrag(struct adapter *padapter, struct recv_fr
>  			pdefrag_q = NULL;
>  		}
>  	} else {
> -		pdefrag_q = &psta->sta_recvpriv.defrag_q;
> +		pdefrag_q = NULL;

What?  "psta" is valid pointer on the else path.

(Also this isn't really a dereference, this is just pointer math.  It's
taking the address.  The Oops would happen later if psta were NULL.)

regards,
dan carpenter


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

end of thread, other threads:[~2022-04-25  8:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-23 18:47 [PATCH] staging: r8188eu: fix a potential NULL pointer dereference Vihas Makwana
2022-04-23 23:47 ` Fabio M. De Francesco
2022-04-24  9:27   ` Vihas Makwana
2022-04-24  9:47     ` Vihas Makwana
2022-04-25  8:22 ` Dan Carpenter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.