Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1682299 > unrolled thread

[PATCH] usb: storage: return on error to avoid a null pointer dereference

Started byColin King <colin.king@canonical.com>
First post2017-07-06 12:10 +0200
Last post2017-07-06 16:50 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] usb: storage: return on error to avoid a null pointer dereference Colin King <colin.king@canonical.com> - 2017-07-06 12:10 +0200
    Re: [PATCH] usb: storage: return on error to avoid a null pointer  dereference Alan Stern <stern@rowland.harvard.edu> - 2017-07-06 16:50 +0200

#1682299 — [PATCH] usb: storage: return on error to avoid a null pointer dereference

FromColin King <colin.king@canonical.com>
Date2017-07-06 12:10 +0200
Subject[PATCH] usb: storage: return on error to avoid a null pointer dereference
Message-ID<u0bTr-2TC-1@gated-at.bofh.it>
From: Colin Ian King <colin.king@canonical.com>

When us->extra is null the driver is not initialized, however, a
later call to osd200_scsi_to_ata is made that dereferences
us->extra, causing a null pointer dereference.  The code
currently detects and reports that the driver is not initialized;
add a return to avoid the subsequent dereference issue in this
check.

Detected by CoverityScan, CID#100308 ("Dereference after null check")

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/usb/storage/isd200.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/storage/isd200.c b/drivers/usb/storage/isd200.c
index fba4005dd737..174ad60679e7 100644
--- a/drivers/usb/storage/isd200.c
+++ b/drivers/usb/storage/isd200.c
@@ -1529,8 +1529,10 @@ static void isd200_ata_command(struct scsi_cmnd *srb, struct us_data *us)
 
 	/* Make sure driver was initialized */
 
-	if (us->extra == NULL)
+	if (us->extra == NULL) {
 		usb_stor_dbg(us, "ERROR Driver not initialized\n");
+		return;
+	}
 
 	scsi_set_resid(srb, 0);
 	/* scsi_bufflen might change in protocol translation to ata */
-- 
2.11.0

[toc] | [next] | [standalone]


#1682486 — Re: [PATCH] usb: storage: return on error to avoid a null pointer dereference

FromAlan Stern <stern@rowland.harvard.edu>
Date2017-07-06 16:50 +0200
SubjectRe: [PATCH] usb: storage: return on error to avoid a null pointer dereference
Message-ID<u0ggq-67f-17@gated-at.bofh.it>
In reply to#1682299
On Thu, 6 Jul 2017, Colin King wrote:

> From: Colin Ian King <colin.king@canonical.com>
> 
> When us->extra is null the driver is not initialized, however, a
> later call to osd200_scsi_to_ata is made that dereferences
> us->extra, causing a null pointer dereference.  The code
> currently detects and reports that the driver is not initialized;
> add a return to avoid the subsequent dereference issue in this
> check.
> 
> Detected by CoverityScan, CID#100308 ("Dereference after null check")
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/usb/storage/isd200.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/storage/isd200.c b/drivers/usb/storage/isd200.c
> index fba4005dd737..174ad60679e7 100644
> --- a/drivers/usb/storage/isd200.c
> +++ b/drivers/usb/storage/isd200.c
> @@ -1529,8 +1529,10 @@ static void isd200_ata_command(struct scsi_cmnd *srb, struct us_data *us)
>  
>  	/* Make sure driver was initialized */
>  
> -	if (us->extra == NULL)
> +	if (us->extra == NULL) {
>  		usb_stor_dbg(us, "ERROR Driver not initialized\n");
> +		return;
> +	}

Good catch, but before returning you need to set

	srb->result = DID_ERROR << 16;

so that the SCSI layer will realize the command wasn't handled.

Alan Stern

>  
>  	scsi_set_resid(srb, 0);
>  	/* scsi_bufflen might change in protocol translation to ata */
> 

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web