public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] scsi: aacraid: reading out of bounds
@ 2017-07-25 19:49 Dan Carpenter
  2017-07-25 19:51 ` [PATCH 2/2] scsi: aacraid: Off by one NUL terminator Dan Carpenter
  2017-07-27  2:10 ` [PATCH 1/2] scsi: aacraid: reading out of bounds Martin K. Petersen
  0 siblings, 2 replies; 11+ messages in thread
From: Dan Carpenter @ 2017-07-25 19:49 UTC (permalink / raw)
  To: Adaptec OEM Raid Solutions
  Cc: James E.J. Bottomley, Martin K. Petersen, linux-scsi,
	kernel-janitors

"qd.id" comes directly from the copy_from_user() on the line before so
we should verify that it's within bounds.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
This bug predates git.

diff --git a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c
index 707ee2f5954d..4591113c49de 100644
--- a/drivers/scsi/aacraid/aachba.c
+++ b/drivers/scsi/aacraid/aachba.c
@@ -3198,10 +3198,11 @@ static int query_disk(struct aac_dev *dev, void __user *arg)
 		return -EBUSY;
 	if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
 		return -EFAULT;
-	if (qd.cnum == -1)
+	if (qd.cnum == -1) {
+		if (qd.id < 0 || qd.id >= dev->maximum_num_containers)
+			return -EINVAL;
 		qd.cnum = qd.id;
-	else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
-	{
+	} else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1)) {
 		if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
 			return -EINVAL;
 		qd.instance = dev->scsi_host_ptr->host_no;

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

* [PATCH 2/2] scsi: aacraid: Off by one NUL terminator
  2017-07-25 19:49 [PATCH 1/2] scsi: aacraid: reading out of bounds Dan Carpenter
@ 2017-07-25 19:51 ` Dan Carpenter
  2017-07-25 21:19   ` Bart Van Assche
  2017-07-27  3:08   ` Martin K. Petersen
  2017-07-27  2:10 ` [PATCH 1/2] scsi: aacraid: reading out of bounds Martin K. Petersen
  1 sibling, 2 replies; 11+ messages in thread
From: Dan Carpenter @ 2017-07-25 19:51 UTC (permalink / raw)
  To: Adaptec OEM Raid Solutions, Mahesh Rajashekhara
  Cc: James E.J. Bottomley, Martin K. Petersen, linux-scsi,
	kernel-janitors

We're putting a NUL terminator one character beyond the end of the
struct and that's obviously wrong.  On the other hand, I'm not positive
this is the correct fix.  This change was added deliberately and was
mentioned in the changlog of commit b836439faf04 ("aacraid: 4KB sector
support").  The relevant section is "Also fix up a name truncation
problem".  Can someone review this code and figure out the right thing
to do?

Fixes: b836439faf04 ("aacraid: 4KB sector support")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c
index 4591113c49de..22c7461f65c9 100644
--- a/drivers/scsi/aacraid/aachba.c
+++ b/drivers/scsi/aacraid/aachba.c
@@ -549,7 +549,7 @@ static void get_container_name_callback(void *context, struct fib * fibptr)
 	if ((le32_to_cpu(get_name_reply->status) == CT_OK)
 	 && (get_name_reply->data[0] != '\0')) {
 		char *sp = get_name_reply->data;
-		sp[sizeof(((struct aac_get_name_resp *)NULL)->data)] = '\0';
+		sp[sizeof(((struct aac_get_name_resp *)NULL)->data) - 1] = '\0';
 		while (*sp == ' ')
 			++sp;
 		if (*sp) {

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

* Re: [PATCH 2/2] scsi: aacraid: Off by one NUL terminator
  2017-07-25 19:51 ` [PATCH 2/2] scsi: aacraid: Off by one NUL terminator Dan Carpenter
@ 2017-07-25 21:19   ` Bart Van Assche
  2017-07-27  3:08   ` Martin K. Petersen
  1 sibling, 0 replies; 11+ messages in thread
From: Bart Van Assche @ 2017-07-25 21:19 UTC (permalink / raw)
  To: aacraid@microsemi.com, Mahesh.Rajashekhara@pmcs.com,
	dan.carpenter@oracle.com
  Cc: jejb@linux.vnet.ibm.com, linux-scsi@vger.kernel.org,
	martin.petersen@oracle.com, kernel-janitors@vger.kernel.org

On Tue, 2017-07-25 at 22:51 +0300, Dan Carpenter wrote:
> We're putting a NUL terminator one character beyond the end of the
> struct and that's obviously wrong.  On the other hand, I'm not positive
> this is the correct fix.  This change was added deliberately and was
> mentioned in the changlog of commit b836439faf04 ("aacraid: 4KB sector
> support").  The relevant section is "Also fix up a name truncation
> problem".  Can someone review this code and figure out the right thing
> to do?
> 
> Fixes: b836439faf04 ("aacraid: 4KB sector support")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c
> index 4591113c49de..22c7461f65c9 100644
> --- a/drivers/scsi/aacraid/aachba.c
> +++ b/drivers/scsi/aacraid/aachba.c
> @@ -549,7 +549,7 @@ static void get_container_name_callback(void *context, struct fib * fibptr)
>  	if ((le32_to_cpu(get_name_reply->status) == CT_OK)
>  	 && (get_name_reply->data[0] != '\0')) {
>  		char *sp = get_name_reply->data;
> -		sp[sizeof(((struct aac_get_name_resp *)NULL)->data)] = '\0';
> +		sp[sizeof(((struct aac_get_name_resp *)NULL)->data) - 1] = '\0';
>  		while (*sp == ' ')
>  			++sp;
>  		if (*sp) {

Hello Dan,

If others agree with the approach of this patch, please use FIELD_SIZEOF()
instead of leaving it open-coded.

Thanks,

Bart.

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

* Re: [PATCH 1/2] scsi: aacraid: reading out of bounds
  2017-07-25 19:49 [PATCH 1/2] scsi: aacraid: reading out of bounds Dan Carpenter
  2017-07-25 19:51 ` [PATCH 2/2] scsi: aacraid: Off by one NUL terminator Dan Carpenter
@ 2017-07-27  2:10 ` Martin K. Petersen
  2017-07-27 16:12   ` Dave Carroll
  1 sibling, 1 reply; 11+ messages in thread
From: Martin K. Petersen @ 2017-07-27  2:10 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Adaptec OEM Raid Solutions, James E.J. Bottomley,
	Martin K. Petersen, linux-scsi, kernel-janitors


Dan,

> "qd.id" comes directly from the copy_from_user() on the line before so
> we should verify that it's within bounds.

Applied to 4.13/scsi-fixes. Thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

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

* Re: [PATCH 2/2] scsi: aacraid: Off by one NUL terminator
  2017-07-25 19:51 ` [PATCH 2/2] scsi: aacraid: Off by one NUL terminator Dan Carpenter
  2017-07-25 21:19   ` Bart Van Assche
@ 2017-07-27  3:08   ` Martin K. Petersen
  2017-07-27  9:00     ` Dan Carpenter
  2017-07-27 16:26     ` Dave Carroll
  1 sibling, 2 replies; 11+ messages in thread
From: Martin K. Petersen @ 2017-07-27  3:08 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Adaptec OEM Raid Solutions, Mahesh Rajashekhara,
	James E.J. Bottomley, Martin K. Petersen, linux-scsi,
	kernel-janitors


Dan,

> We're putting a NUL terminator one character beyond the end of the
> struct and that's obviously wrong.  On the other hand, I'm not positive
> this is the correct fix.  This change was added deliberately and was
> mentioned in the changlog of commit b836439faf04 ("aacraid: 4KB sector
> support").  The relevant section is "Also fix up a name truncation
> problem".  Can someone review this code and figure out the right thing
> to do?

I guess that's a feeble attempt to compensate for the fact it's not a C
string. The string coming from the controller firmware appears to be a
fixed 16-byte length. And so is the inquiry buffer that it's being
copied to.

If the code would just use the inquiry string verbatim instead of
removing leading spaces and padding it. But there was probably some
crappy device out there that broke something for someone...

Anyway. Terminating the string is not the right fix.

-- 
Martin K. Petersen	Oracle Linux Engineering

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

* Re: [PATCH 2/2] scsi: aacraid: Off by one NUL terminator
  2017-07-27  3:08   ` Martin K. Petersen
@ 2017-07-27  9:00     ` Dan Carpenter
  2017-07-27 12:55       ` Martin K. Petersen
  2017-07-27 16:26     ` Dave Carroll
  1 sibling, 1 reply; 11+ messages in thread
From: Dan Carpenter @ 2017-07-27  9:00 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Adaptec OEM Raid Solutions, Mahesh Rajashekhara,
	James E.J. Bottomley, linux-scsi, kernel-janitors

It would be simple enough to write it like you say, but it probably
should be done by someone who is able to test it.

regards,
dan carpenter


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

* Re: [PATCH 2/2] scsi: aacraid: Off by one NUL terminator
  2017-07-27  9:00     ` Dan Carpenter
@ 2017-07-27 12:55       ` Martin K. Petersen
  0 siblings, 0 replies; 11+ messages in thread
From: Martin K. Petersen @ 2017-07-27 12:55 UTC (permalink / raw)
  To: Raghava Aditya Renukunta
  Cc: Martin K. Petersen, Adaptec OEM Raid Solutions,
	Mahesh Rajashekhara, James E.J. Bottomley, linux-scsi,
	kernel-janitors, Dan Carpenter


Dan,

> It would be simple enough to write it like you say, but it probably
> should be done by someone who is able to test it.

Indeed, I don't have any aacraid hw.

Raghava, could you please take a look at this issue?

	https://patchwork.kernel.org/patch/9863105/

Thank you!

-- 
Martin K. Petersen	Oracle Linux Engineering

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

* RE: [PATCH 1/2] scsi: aacraid: reading out of bounds
  2017-07-27  2:10 ` [PATCH 1/2] scsi: aacraid: reading out of bounds Martin K. Petersen
@ 2017-07-27 16:12   ` Dave Carroll
  0 siblings, 0 replies; 11+ messages in thread
From: Dave Carroll @ 2017-07-27 16:12 UTC (permalink / raw)
  To: Martin K. Petersen, Dan Carpenter
  Cc: dl-esc-Aacraid Linux Driver, James E.J. Bottomley,
	linux-scsi@vger.kernel.org, kernel-janitors@vger.kernel.org

> 
> Dan,
> 
> > "qd.id" comes directly from the copy_from_user() on the line before so
> > we should verify that it's within bounds.
> 
> Applied to 4.13/scsi-fixes. Thanks!
> 
> --
> Martin K. Petersen      Oracle Linux Engineering

Acked-by: Dave Carroll <david.carroll@microsemi.com>

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

* RE: [PATCH 2/2] scsi: aacraid: Off by one NUL terminator
  2017-07-27  3:08   ` Martin K. Petersen
  2017-07-27  9:00     ` Dan Carpenter
@ 2017-07-27 16:26     ` Dave Carroll
  2017-07-27 16:30       ` Martin K. Petersen
  1 sibling, 1 reply; 11+ messages in thread
From: Dave Carroll @ 2017-07-27 16:26 UTC (permalink / raw)
  To: Martin K. Petersen, Dan Carpenter
  Cc: dl-esc-Aacraid Linux Driver, Mahesh Rajashekhara,
	James E.J. Bottomley, linux-scsi@vger.kernel.org,
	kernel-janitors@vger.kernel.org


> 
> Dan,
> 
> > We're putting a NUL terminator one character beyond the end of the
> > struct and that's obviously wrong.  On the other hand, I'm not
> > positive this is the correct fix.  This change was added deliberately
> > and was mentioned in the changlog of commit b836439faf04 ("aacraid:
> > 4KB sector support").  The relevant section is "Also fix up a name
> > truncation problem".  Can someone review this code and figure out the
> > right thing to do?
> 
> I guess that's a feeble attempt to compensate for the fact it's not a C string. The
> string coming from the controller firmware appears to be a fixed 16-byte length.
> And so is the inquiry buffer that it's being copied to.
> 
> If the code would just use the inquiry string verbatim instead of removing
> leading spaces and padding it. But there was probably some crappy device out
> there that broke something for someone...

Hi Martin, Dan,

The issue is that we are making an inquiry response from container/RAID info. We could also have included a "pad" byte to terminate the string, as the fib data is 512 bytes. My assumption is that somehow back in the day, someone managed to get odd characters into the name.

Terminating the string early would truncate the name ...

-Dave
> 
> Anyway. Terminating the string is not the right fix.
> 
> --
> Martin K. Petersen      Oracle Linux Engineering

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

* Re: [PATCH 2/2] scsi: aacraid: Off by one NUL terminator
  2017-07-27 16:26     ` Dave Carroll
@ 2017-07-27 16:30       ` Martin K. Petersen
  2017-07-27 16:51         ` Dave Carroll
  0 siblings, 1 reply; 11+ messages in thread
From: Martin K. Petersen @ 2017-07-27 16:30 UTC (permalink / raw)
  To: Dave Carroll
  Cc: Martin K. Petersen, Dan Carpenter, dl-esc-Aacraid Linux Driver,
	Mahesh Rajashekhara, James E.J. Bottomley,
	linux-scsi@vger.kernel.org, kernel-janitors@vger.kernel.org


Dave,

> The issue is that we are making an inquiry response from
> container/RAID info. We could also have included a "pad" byte to
> terminate the string, as the fib data is 512 bytes. My assumption is
> that somehow back in the day, someone managed to get odd characters
> into the name.
>
> Terminating the string early would truncate the name ...

So what do you propose as a fix?

-- 
Martin K. Petersen	Oracle Linux Engineering

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

* RE: [PATCH 2/2] scsi: aacraid: Off by one NUL terminator
  2017-07-27 16:30       ` Martin K. Petersen
@ 2017-07-27 16:51         ` Dave Carroll
  0 siblings, 0 replies; 11+ messages in thread
From: Dave Carroll @ 2017-07-27 16:51 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Dan Carpenter, dl-esc-Aacraid Linux Driver, Mahesh Rajashekhara,
	James E.J. Bottomley, linux-scsi@vger.kernel.org,
	kernel-janitors@vger.kernel.org

> Dave,
> 
> > The issue is that we are making an inquiry response from
> > container/RAID info. We could also have included a "pad" byte to
> > terminate the string, as the fib data is 512 bytes. My assumption is
> > that somehow back in the day, someone managed to get odd characters
> > into the name.
> >
> > Terminating the string early would truncate the name ...
> 
> So what do you propose as a fix?

We can add the pad byte to the struct, and terminate the string there. I'm out the office now, but Raghava or I will send up a patch ... That way, folks won't need to contemplate what appears to be a blatant out of bounds reference.

-Dave
> 
> --
> Martin K. Petersen      Oracle Linux Engineering

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

end of thread, other threads:[~2017-07-27 16:51 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-25 19:49 [PATCH 1/2] scsi: aacraid: reading out of bounds Dan Carpenter
2017-07-25 19:51 ` [PATCH 2/2] scsi: aacraid: Off by one NUL terminator Dan Carpenter
2017-07-25 21:19   ` Bart Van Assche
2017-07-27  3:08   ` Martin K. Petersen
2017-07-27  9:00     ` Dan Carpenter
2017-07-27 12:55       ` Martin K. Petersen
2017-07-27 16:26     ` Dave Carroll
2017-07-27 16:30       ` Martin K. Petersen
2017-07-27 16:51         ` Dave Carroll
2017-07-27  2:10 ` [PATCH 1/2] scsi: aacraid: reading out of bounds Martin K. Petersen
2017-07-27 16:12   ` Dave Carroll

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