linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] USB: storage: Fix potential NULL pointer derefernce
@ 2019-03-13 17:48 Aditya Pakki
  2019-03-13 18:01 ` Alan Stern
  0 siblings, 1 reply; 2+ messages in thread
From: Aditya Pakki @ 2019-03-13 17:48 UTC (permalink / raw)
  To: pakki001
  Cc: kjlu, Alan Stern, Greg Kroah-Hartman, linux-usb, usb-storage,
	linux-kernel

Allocating memory via kcalloc for pba_to_lba and lba_to_pba can
fail. The fix avoids a potential NULL pointer dereference.

Signed-off-by: Aditya Pakki <pakki001@umn.edu>
---
 drivers/usb/storage/alauda.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/usb/storage/alauda.c b/drivers/usb/storage/alauda.c
index 6b8edf6178df..41d979e70784 100644
--- a/drivers/usb/storage/alauda.c
+++ b/drivers/usb/storage/alauda.c
@@ -438,6 +438,11 @@ static int alauda_init_media(struct us_data *us)
 	MEDIA_INFO(us).pba_to_lba = kcalloc(num_zones, sizeof(u16*), GFP_NOIO);
 	MEDIA_INFO(us).lba_to_pba = kcalloc(num_zones, sizeof(u16*), GFP_NOIO);
 
+	if (!MEDIA_INFO(us).pba_to_lba || !MEDIA_INFO(us).lba_to_pba) {
+		pr_warn("%s: Failed to allocate memory\n", __func__);
+		return USB_STOR_TRANSPORT_ERROR;
+	}
+
 	if (alauda_reset_media(us) != USB_STOR_XFER_GOOD)
 		return USB_STOR_TRANSPORT_ERROR;
 
-- 
2.17.1


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

* Re: [PATCH] USB: storage: Fix potential NULL pointer derefernce
  2019-03-13 17:48 [PATCH] USB: storage: Fix potential NULL pointer derefernce Aditya Pakki
@ 2019-03-13 18:01 ` Alan Stern
  0 siblings, 0 replies; 2+ messages in thread
From: Alan Stern @ 2019-03-13 18:01 UTC (permalink / raw)
  To: Aditya Pakki
  Cc: kjlu, Greg Kroah-Hartman, linux-usb, usb-storage, linux-kernel

On Wed, 13 Mar 2019, Aditya Pakki wrote:

> Allocating memory via kcalloc for pba_to_lba and lba_to_pba can
> fail. The fix avoids a potential NULL pointer dereference.
> 
> Signed-off-by: Aditya Pakki <pakki001@umn.edu>
> ---
>  drivers/usb/storage/alauda.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/usb/storage/alauda.c b/drivers/usb/storage/alauda.c
> index 6b8edf6178df..41d979e70784 100644
> --- a/drivers/usb/storage/alauda.c
> +++ b/drivers/usb/storage/alauda.c
> @@ -438,6 +438,11 @@ static int alauda_init_media(struct us_data *us)
>  	MEDIA_INFO(us).pba_to_lba = kcalloc(num_zones, sizeof(u16*), GFP_NOIO);
>  	MEDIA_INFO(us).lba_to_pba = kcalloc(num_zones, sizeof(u16*), GFP_NOIO);
>  
> +	if (!MEDIA_INFO(us).pba_to_lba || !MEDIA_INFO(us).lba_to_pba) {
> +		pr_warn("%s: Failed to allocate memory\n", __func__);
> +		return USB_STOR_TRANSPORT_ERROR;
> +	}
> +
>  	if (alauda_reset_media(us) != USB_STOR_XFER_GOOD)
>  		return USB_STOR_TRANSPORT_ERROR;

In fact this won't accomplish anything, because the return value from 
alauda_init_media() isn't used.  The driver appears to need more than 
a single change.

Alan Stern


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

end of thread, other threads:[~2019-03-13 18:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-13 17:48 [PATCH] USB: storage: Fix potential NULL pointer derefernce Aditya Pakki
2019-03-13 18:01 ` Alan Stern

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).