All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/1] USB: serial: Add boundry check for read_urbs array access
@ 2018-03-07 20:23 ` sathyanarayanan.kuppuswamy
  0 siblings, 0 replies; 16+ messages in thread
From: sathyanarayanan.kuppuswamy @ 2018-03-07 20:23 UTC (permalink / raw)
  To: gregkh, johan; +Cc: linux-usb, linux-kernel, Kuppuswamy Sathyanarayanan

From: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>

In usb_serial_generic_submit_read_urb() function we are accessing the
port->read_urbs array without any boundry checks. This might lead to
kernel panic when index value goes above array length.

One posible call path for this issue is,

usb_serial_generic_read_bulk_callback()
{
 ...
 if (!port->throttled) {
	usb_serial_generic_submit_read_urb(port, i, GFP_ATOMIC);
 ...
}

This patch fixes this issue.

Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
---
 drivers/usb/serial/generic.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index 2274d96..72ebdde 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -306,6 +306,9 @@ static int usb_serial_generic_submit_read_urb(struct usb_serial_port *port,
 {
 	int res;
 
+	if (index >= ARRAY_SIZE(port->read_urbs))
+		return -EINVAL;
+
 	if (!test_and_clear_bit(index, &port->read_urbs_free))
 		return 0;
 
-- 
2.7.4


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

* [v1,1/1] USB: serial: Add boundry check for read_urbs array access
@ 2018-03-07 20:23 ` sathyanarayanan.kuppuswamy
  0 siblings, 0 replies; 16+ messages in thread
From: sathyanarayanan.kuppuswamy @ 2018-03-07 20:23 UTC (permalink / raw)
  To: gregkh, johan; +Cc: linux-usb, linux-kernel, Kuppuswamy Sathyanarayanan

From: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>

In usb_serial_generic_submit_read_urb() function we are accessing the
port->read_urbs array without any boundry checks. This might lead to
kernel panic when index value goes above array length.

One posible call path for this issue is,

usb_serial_generic_read_bulk_callback()
{
 ...
 if (!port->throttled) {
	usb_serial_generic_submit_read_urb(port, i, GFP_ATOMIC);
 ...
}

This patch fixes this issue.

Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
---
 drivers/usb/serial/generic.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index 2274d96..72ebdde 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -306,6 +306,9 @@ static int usb_serial_generic_submit_read_urb(struct usb_serial_port *port,
 {
 	int res;
 
+	if (index >= ARRAY_SIZE(port->read_urbs))
+		return -EINVAL;
+
 	if (!test_and_clear_bit(index, &port->read_urbs_free))
 		return 0;
 

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

* Re: [PATCH v1 1/1] USB: serial: Add boundry check for read_urbs array access
@ 2018-03-07 20:58   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 16+ messages in thread
From: Greg KH @ 2018-03-07 20:58 UTC (permalink / raw)
  To: sathyanarayanan.kuppuswamy; +Cc: johan, linux-usb, linux-kernel

On Wed, Mar 07, 2018 at 12:23:56PM -0800, sathyanarayanan.kuppuswamy@linux.intel.com wrote:
> From: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
> 
> In usb_serial_generic_submit_read_urb() function we are accessing the
> port->read_urbs array without any boundry checks. This might lead to
> kernel panic when index value goes above array length.
> 
> One posible call path for this issue is,
> 
> usb_serial_generic_read_bulk_callback()
> {
>  ...
>  if (!port->throttled) {
> 	usb_serial_generic_submit_read_urb(port, i, GFP_ATOMIC);
>  ...
> }

How does i ever get to be greater than the array size here in this
function?  It directly came from looking in that array in the first
place :)

So I don't see why your check is needed, what other code path would ever
call this function in a way that the bounds check would be needed?

thanks,

greg k-h

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

* [v1,1/1] USB: serial: Add boundry check for read_urbs array access
@ 2018-03-07 20:58   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 16+ messages in thread
From: Greg Kroah-Hartman @ 2018-03-07 20:58 UTC (permalink / raw)
  To: sathyanarayanan.kuppuswamy; +Cc: johan, linux-usb, linux-kernel

On Wed, Mar 07, 2018 at 12:23:56PM -0800, sathyanarayanan.kuppuswamy@linux.intel.com wrote:
> From: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
> 
> In usb_serial_generic_submit_read_urb() function we are accessing the
> port->read_urbs array without any boundry checks. This might lead to
> kernel panic when index value goes above array length.
> 
> One posible call path for this issue is,
> 
> usb_serial_generic_read_bulk_callback()
> {
>  ...
>  if (!port->throttled) {
> 	usb_serial_generic_submit_read_urb(port, i, GFP_ATOMIC);
>  ...
> }

How does i ever get to be greater than the array size here in this
function?  It directly came from looking in that array in the first
place :)

So I don't see why your check is needed, what other code path would ever
call this function in a way that the bounds check would be needed?

thanks,

greg k-h
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v1 1/1] USB: serial: Add boundry check for read_urbs array access
@ 2018-03-07 21:41     ` sathyanarayanan.kuppuswamy
  0 siblings, 0 replies; 16+ messages in thread
From: sathyanarayanan kuppuswamy @ 2018-03-07 21:41 UTC (permalink / raw)
  To: Greg KH; +Cc: johan, linux-usb, linux-kernel



On 03/07/2018 12:58 PM, Greg KH wrote:
> On Wed, Mar 07, 2018 at 12:23:56PM -0800, sathyanarayanan.kuppuswamy@linux.intel.com wrote:
>> From: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
>>
>> In usb_serial_generic_submit_read_urb() function we are accessing the
>> port->read_urbs array without any boundry checks. This might lead to
>> kernel panic when index value goes above array length.
>>
>> One posible call path for this issue is,
>>
>> usb_serial_generic_read_bulk_callback()
>> {
>>   ...
>>   if (!port->throttled) {
>> 	usb_serial_generic_submit_read_urb(port, i, GFP_ATOMIC);
>>   ...
>> }
> How does i ever get to be greater than the array size here in this
> function?  It directly came from looking in that array in the first
> place :)
>
> So I don't see why your check is needed, what other code path would ever
> call this function in a way that the bounds check would be needed?
void usb_serial_generic_read_bulk_callback(struct urb *urb)

385         for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) {
386                 if (urb == port->read_urbs[i])
387                         break;
388         }

In here, after this for loop is done (without any matching urb), i value 
will be equal to ARRAY_SIZE(port->read_urbs). So there is a possibility 
of usb_serial_generic_submit_read_urb() getting called with this invalid 
index.

>
> thanks,
>
> greg k-h
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

-- 
Sathyanarayanan Kuppuswamy
Linux kernel developer


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

* [v1,1/1] USB: serial: Add boundry check for read_urbs array access
@ 2018-03-07 21:41     ` sathyanarayanan.kuppuswamy
  0 siblings, 0 replies; 16+ messages in thread
From: sathyanarayanan.kuppuswamy @ 2018-03-07 21:41 UTC (permalink / raw)
  To: Greg KH; +Cc: johan, linux-usb, linux-kernel

On 03/07/2018 12:58 PM, Greg KH wrote:
> On Wed, Mar 07, 2018 at 12:23:56PM -0800, sathyanarayanan.kuppuswamy@linux.intel.com wrote:
>> From: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
>>
>> In usb_serial_generic_submit_read_urb() function we are accessing the
>> port->read_urbs array without any boundry checks. This might lead to
>> kernel panic when index value goes above array length.
>>
>> One posible call path for this issue is,
>>
>> usb_serial_generic_read_bulk_callback()
>> {
>>   ...
>>   if (!port->throttled) {
>> 	usb_serial_generic_submit_read_urb(port, i, GFP_ATOMIC);
>>   ...
>> }
> How does i ever get to be greater than the array size here in this
> function?  It directly came from looking in that array in the first
> place :)
>
> So I don't see why your check is needed, what other code path would ever
> call this function in a way that the bounds check would be needed?
void usb_serial_generic_read_bulk_callback(struct urb *urb)

385         for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) {
386                 if (urb == port->read_urbs[i])
387                         break;
388         }

In here, after this for loop is done (without any matching urb), i value 
will be equal to ARRAY_SIZE(port->read_urbs). So there is a possibility 
of usb_serial_generic_submit_read_urb() getting called with this invalid 
index.

>
> thanks,
>
> greg k-h
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

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

* Re: [PATCH v1 1/1] USB: serial: Add boundry check for read_urbs array access
@ 2018-03-08  8:54       ` Oliver Neukum
  0 siblings, 0 replies; 16+ messages in thread
From: Oliver Neukum @ 2018-03-08  8:54 UTC (permalink / raw)
  To: sathyanarayanan.kuppuswamy, Greg KH; +Cc: johan, linux-kernel, linux-usb

Am Mittwoch, den 07.03.2018, 13:41 -0800 schrieb sathyanarayanan
kuppuswamy       :
> 
> On 03/07/2018 12:58 PM, Greg KH wrote:

> > So I don't see why your check is needed, what other code path would ever
> > call this function in a way that the bounds check would be needed?
> void usb_serial_generic_read_bulk_callback(struct urb *urb)
> 
> 385         for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) {
> 386                 if (urb == port->read_urbs[i])
> 387                         break;
> 388         }
> 
> In here, after this for loop is done (without any matching urb), i value 
> will be equal to ARRAY_SIZE(port->read_urbs). So there is a possibility 
> of usb_serial_generic_submit_read_urb() getting called with this invalid 
> index.

If this happens the function was called for a stray URB.
Your check comes to late. We have called set_bit with an invalid index
and other shit.
We definitely do not just want to return an error in that case.

	Regards
		Oliver


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

* [v1,1/1] USB: serial: Add boundry check for read_urbs array access
@ 2018-03-08  8:54       ` Oliver Neukum
  0 siblings, 0 replies; 16+ messages in thread
From: Oliver Neukum @ 2018-03-08  8:54 UTC (permalink / raw)
  To: sathyanarayanan.kuppuswamy, Greg KH; +Cc: johan, linux-kernel, linux-usb

Am Mittwoch, den 07.03.2018, 13:41 -0800 schrieb sathyanarayanan
kuppuswamy       :
> 
> On 03/07/2018 12:58 PM, Greg KH wrote:

> > So I don't see why your check is needed, what other code path would ever
> > call this function in a way that the bounds check would be needed?
> void usb_serial_generic_read_bulk_callback(struct urb *urb)
> 
> 385         for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) {
> 386                 if (urb == port->read_urbs[i])
> 387                         break;
> 388         }
> 
> In here, after this for loop is done (without any matching urb), i value 
> will be equal to ARRAY_SIZE(port->read_urbs). So there is a possibility 
> of usb_serial_generic_submit_read_urb() getting called with this invalid 
> index.

If this happens the function was called for a stray URB.
Your check comes to late. We have called set_bit with an invalid index
and other shit.
We definitely do not just want to return an error in that case.

	Regards
		Oliver
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v1 1/1] USB: serial: Add boundry check for read_urbs array access
@ 2018-03-08 14:01       ` Greg Kroah-Hartman
  0 siblings, 0 replies; 16+ messages in thread
From: Greg KH @ 2018-03-08 14:01 UTC (permalink / raw)
  To: sathyanarayanan kuppuswamy; +Cc: johan, linux-usb, linux-kernel

On Wed, Mar 07, 2018 at 01:41:51PM -0800, sathyanarayanan kuppuswamy wrote:
> 
> 
> On 03/07/2018 12:58 PM, Greg KH wrote:
> > On Wed, Mar 07, 2018 at 12:23:56PM -0800, sathyanarayanan.kuppuswamy@linux.intel.com wrote:
> > > From: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
> > > 
> > > In usb_serial_generic_submit_read_urb() function we are accessing the
> > > port->read_urbs array without any boundry checks. This might lead to
> > > kernel panic when index value goes above array length.
> > > 
> > > One posible call path for this issue is,
> > > 
> > > usb_serial_generic_read_bulk_callback()
> > > {
> > >   ...
> > >   if (!port->throttled) {
> > > 	usb_serial_generic_submit_read_urb(port, i, GFP_ATOMIC);
> > >   ...
> > > }
> > How does i ever get to be greater than the array size here in this
> > function?  It directly came from looking in that array in the first
> > place :)
> > 
> > So I don't see why your check is needed, what other code path would ever
> > call this function in a way that the bounds check would be needed?
> void usb_serial_generic_read_bulk_callback(struct urb *urb)
> 
> 385         for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) {
> 386                 if (urb == port->read_urbs[i])
> 387                         break;
> 388         }
> 
> In here, after this for loop is done (without any matching urb),

How is it possible to not have any matching urbs here?  If that ever
happens, we have much worse problems happening in the USB stack :)

thanks,

greg k-h

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

* [v1,1/1] USB: serial: Add boundry check for read_urbs array access
@ 2018-03-08 14:01       ` Greg Kroah-Hartman
  0 siblings, 0 replies; 16+ messages in thread
From: Greg Kroah-Hartman @ 2018-03-08 14:01 UTC (permalink / raw)
  To: sathyanarayanan kuppuswamy; +Cc: johan, linux-usb, linux-kernel

On Wed, Mar 07, 2018 at 01:41:51PM -0800, sathyanarayanan kuppuswamy wrote:
> 
> 
> On 03/07/2018 12:58 PM, Greg KH wrote:
> > On Wed, Mar 07, 2018 at 12:23:56PM -0800, sathyanarayanan.kuppuswamy@linux.intel.com wrote:
> > > From: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
> > > 
> > > In usb_serial_generic_submit_read_urb() function we are accessing the
> > > port->read_urbs array without any boundry checks. This might lead to
> > > kernel panic when index value goes above array length.
> > > 
> > > One posible call path for this issue is,
> > > 
> > > usb_serial_generic_read_bulk_callback()
> > > {
> > >   ...
> > >   if (!port->throttled) {
> > > 	usb_serial_generic_submit_read_urb(port, i, GFP_ATOMIC);
> > >   ...
> > > }
> > How does i ever get to be greater than the array size here in this
> > function?  It directly came from looking in that array in the first
> > place :)
> > 
> > So I don't see why your check is needed, what other code path would ever
> > call this function in a way that the bounds check would be needed?
> void usb_serial_generic_read_bulk_callback(struct urb *urb)
> 
> 385         for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) {
> 386                 if (urb == port->read_urbs[i])
> 387                         break;
> 388         }
> 
> In here, after this for loop is done (without any matching urb),

How is it possible to not have any matching urbs here?  If that ever
happens, we have much worse problems happening in the USB stack :)

thanks,

greg k-h
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v1 1/1] USB: serial: Add boundry check for read_urbs array access
@ 2018-03-08 23:29         ` sathyanarayanan.kuppuswamy
  0 siblings, 0 replies; 16+ messages in thread
From: sathyanarayanan kuppuswamy @ 2018-03-08 23:29 UTC (permalink / raw)
  To: Oliver Neukum, Greg KH; +Cc: johan, linux-kernel, linux-usb



On 03/08/2018 12:54 AM, Oliver Neukum wrote:
> Am Mittwoch, den 07.03.2018, 13:41 -0800 schrieb sathyanarayanan
> kuppuswamy       :
>> On 03/07/2018 12:58 PM, Greg KH wrote:
>>> So I don't see why your check is needed, what other code path would ever
>>> call this function in a way that the bounds check would be needed?
>> void usb_serial_generic_read_bulk_callback(struct urb *urb)
>>
>> 385         for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) {
>> 386                 if (urb == port->read_urbs[i])
>> 387                         break;
>> 388         }
>>
>> In here, after this for loop is done (without any matching urb), i value
>> will be equal to ARRAY_SIZE(port->read_urbs). So there is a possibility
>> of usb_serial_generic_submit_read_urb() getting called with this invalid
>> index.
> If this happens the function was called for a stray URB.
> Your check comes to late. We have called set_bit with an invalid index
> and other shit.
> We definitely do not just want to return an error in that case.
In that case do you think we should use some WARN_ON() for invalid index 
in usb_serial_generic_read_bulk_callback()?
>
> 	Regards
> 		Oliver
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

-- 
Sathyanarayanan Kuppuswamy
Linux kernel developer

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

* [v1,1/1] USB: serial: Add boundry check for read_urbs array access
@ 2018-03-08 23:29         ` sathyanarayanan.kuppuswamy
  0 siblings, 0 replies; 16+ messages in thread
From: sathyanarayanan.kuppuswamy @ 2018-03-08 23:29 UTC (permalink / raw)
  To: Oliver Neukum, Greg KH; +Cc: johan, linux-kernel, linux-usb

On 03/08/2018 12:54 AM, Oliver Neukum wrote:
> Am Mittwoch, den 07.03.2018, 13:41 -0800 schrieb sathyanarayanan
> kuppuswamy       :
>> On 03/07/2018 12:58 PM, Greg KH wrote:
>>> So I don't see why your check is needed, what other code path would ever
>>> call this function in a way that the bounds check would be needed?
>> void usb_serial_generic_read_bulk_callback(struct urb *urb)
>>
>> 385         for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) {
>> 386                 if (urb == port->read_urbs[i])
>> 387                         break;
>> 388         }
>>
>> In here, after this for loop is done (without any matching urb), i value
>> will be equal to ARRAY_SIZE(port->read_urbs). So there is a possibility
>> of usb_serial_generic_submit_read_urb() getting called with this invalid
>> index.
> If this happens the function was called for a stray URB.
> Your check comes to late. We have called set_bit with an invalid index
> and other shit.
> We definitely do not just want to return an error in that case.
In that case do you think we should use some WARN_ON() for invalid index 
in usb_serial_generic_read_bulk_callback()?
>
> 	Regards
> 		Oliver
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

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

* Re: [PATCH v1 1/1] USB: serial: Add boundry check for read_urbs array access
@ 2018-03-08 23:43           ` Greg Kroah-Hartman
  0 siblings, 0 replies; 16+ messages in thread
From: Greg KH @ 2018-03-08 23:43 UTC (permalink / raw)
  To: sathyanarayanan kuppuswamy; +Cc: Oliver Neukum, johan, linux-kernel, linux-usb

On Thu, Mar 08, 2018 at 03:29:48PM -0800, sathyanarayanan kuppuswamy wrote:
> 
> 
> On 03/08/2018 12:54 AM, Oliver Neukum wrote:
> > Am Mittwoch, den 07.03.2018, 13:41 -0800 schrieb sathyanarayanan
> > kuppuswamy       :
> > > On 03/07/2018 12:58 PM, Greg KH wrote:
> > > > So I don't see why your check is needed, what other code path would ever
> > > > call this function in a way that the bounds check would be needed?
> > > void usb_serial_generic_read_bulk_callback(struct urb *urb)
> > > 
> > > 385         for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) {
> > > 386                 if (urb == port->read_urbs[i])
> > > 387                         break;
> > > 388         }
> > > 
> > > In here, after this for loop is done (without any matching urb), i value
> > > will be equal to ARRAY_SIZE(port->read_urbs). So there is a possibility
> > > of usb_serial_generic_submit_read_urb() getting called with this invalid
> > > index.
> > If this happens the function was called for a stray URB.
> > Your check comes to late. We have called set_bit with an invalid index
> > and other shit.
> > We definitely do not just want to return an error in that case.
> In that case do you think we should use some WARN_ON() for invalid index in
> usb_serial_generic_read_bulk_callback()?

No, again, how could that ever happen?

Don't add pointless error checking for things that are impossible to
ever hit :)

thanks,

greg k-h

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

* [v1,1/1] USB: serial: Add boundry check for read_urbs array access
@ 2018-03-08 23:43           ` Greg Kroah-Hartman
  0 siblings, 0 replies; 16+ messages in thread
From: Greg Kroah-Hartman @ 2018-03-08 23:43 UTC (permalink / raw)
  To: sathyanarayanan kuppuswamy; +Cc: Oliver Neukum, johan, linux-kernel, linux-usb

On Thu, Mar 08, 2018 at 03:29:48PM -0800, sathyanarayanan kuppuswamy wrote:
> 
> 
> On 03/08/2018 12:54 AM, Oliver Neukum wrote:
> > Am Mittwoch, den 07.03.2018, 13:41 -0800 schrieb sathyanarayanan
> > kuppuswamy       :
> > > On 03/07/2018 12:58 PM, Greg KH wrote:
> > > > So I don't see why your check is needed, what other code path would ever
> > > > call this function in a way that the bounds check would be needed?
> > > void usb_serial_generic_read_bulk_callback(struct urb *urb)
> > > 
> > > 385         for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) {
> > > 386                 if (urb == port->read_urbs[i])
> > > 387                         break;
> > > 388         }
> > > 
> > > In here, after this for loop is done (without any matching urb), i value
> > > will be equal to ARRAY_SIZE(port->read_urbs). So there is a possibility
> > > of usb_serial_generic_submit_read_urb() getting called with this invalid
> > > index.
> > If this happens the function was called for a stray URB.
> > Your check comes to late. We have called set_bit with an invalid index
> > and other shit.
> > We definitely do not just want to return an error in that case.
> In that case do you think we should use some WARN_ON() for invalid index in
> usb_serial_generic_read_bulk_callback()?

No, again, how could that ever happen?

Don't add pointless error checking for things that are impossible to
ever hit :)

thanks,

greg k-h
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v1 1/1] USB: serial: Add boundry check for read_urbs array access
@ 2018-03-09  0:34             ` sathyanarayanan.kuppuswamy
  0 siblings, 0 replies; 16+ messages in thread
From: sathyanarayanan kuppuswamy @ 2018-03-09  0:34 UTC (permalink / raw)
  To: Greg KH; +Cc: Oliver Neukum, johan, linux-kernel, linux-usb



On 03/08/2018 03:43 PM, Greg KH wrote:
> On Thu, Mar 08, 2018 at 03:29:48PM -0800, sathyanarayanan kuppuswamy wrote:
>>
>> On 03/08/2018 12:54 AM, Oliver Neukum wrote:
>>> Am Mittwoch, den 07.03.2018, 13:41 -0800 schrieb sathyanarayanan
>>> kuppuswamy       :
>>>> On 03/07/2018 12:58 PM, Greg KH wrote:
>>>>> So I don't see why your check is needed, what other code path would ever
>>>>> call this function in a way that the bounds check would be needed?
>>>> void usb_serial_generic_read_bulk_callback(struct urb *urb)
>>>>
>>>> 385         for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) {
>>>> 386                 if (urb == port->read_urbs[i])
>>>> 387                         break;
>>>> 388         }
>>>>
>>>> In here, after this for loop is done (without any matching urb), i value
>>>> will be equal to ARRAY_SIZE(port->read_urbs). So there is a possibility
>>>> of usb_serial_generic_submit_read_urb() getting called with this invalid
>>>> index.
>>> If this happens the function was called for a stray URB.
>>> Your check comes to late. We have called set_bit with an invalid index
>>> and other shit.
>>> We definitely do not just want to return an error in that case.
>> In that case do you think we should use some WARN_ON() for invalid index in
>> usb_serial_generic_read_bulk_callback()?
> No, again, how could that ever happen?
>
> Don't add pointless error checking for things that are impossible to
> ever hit :)
Thanks Greg.
>
> thanks,
>
> greg k-h
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

-- 
Sathyanarayanan Kuppuswamy
Linux kernel developer

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

* [v1,1/1] USB: serial: Add boundry check for read_urbs array access
@ 2018-03-09  0:34             ` sathyanarayanan.kuppuswamy
  0 siblings, 0 replies; 16+ messages in thread
From: sathyanarayanan.kuppuswamy @ 2018-03-09  0:34 UTC (permalink / raw)
  To: Greg KH; +Cc: Oliver Neukum, johan, linux-kernel, linux-usb

On 03/08/2018 03:43 PM, Greg KH wrote:
> On Thu, Mar 08, 2018 at 03:29:48PM -0800, sathyanarayanan kuppuswamy wrote:
>>
>> On 03/08/2018 12:54 AM, Oliver Neukum wrote:
>>> Am Mittwoch, den 07.03.2018, 13:41 -0800 schrieb sathyanarayanan
>>> kuppuswamy       :
>>>> On 03/07/2018 12:58 PM, Greg KH wrote:
>>>>> So I don't see why your check is needed, what other code path would ever
>>>>> call this function in a way that the bounds check would be needed?
>>>> void usb_serial_generic_read_bulk_callback(struct urb *urb)
>>>>
>>>> 385         for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) {
>>>> 386                 if (urb == port->read_urbs[i])
>>>> 387                         break;
>>>> 388         }
>>>>
>>>> In here, after this for loop is done (without any matching urb), i value
>>>> will be equal to ARRAY_SIZE(port->read_urbs). So there is a possibility
>>>> of usb_serial_generic_submit_read_urb() getting called with this invalid
>>>> index.
>>> If this happens the function was called for a stray URB.
>>> Your check comes to late. We have called set_bit with an invalid index
>>> and other shit.
>>> We definitely do not just want to return an error in that case.
>> In that case do you think we should use some WARN_ON() for invalid index in
>> usb_serial_generic_read_bulk_callback()?
> No, again, how could that ever happen?
>
> Don't add pointless error checking for things that are impossible to
> ever hit :)
Thanks Greg.
>
> thanks,
>
> greg k-h
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

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

end of thread, other threads:[~2018-03-09  0:34 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-07 20:23 [PATCH v1 1/1] USB: serial: Add boundry check for read_urbs array access sathyanarayanan.kuppuswamy
2018-03-07 20:23 ` [v1,1/1] " sathyanarayanan.kuppuswamy
2018-03-07 20:58 ` [PATCH v1 1/1] " Greg KH
2018-03-07 20:58   ` [v1,1/1] " Greg Kroah-Hartman
2018-03-07 21:41   ` [PATCH v1 1/1] " sathyanarayanan kuppuswamy
2018-03-07 21:41     ` [v1,1/1] " sathyanarayanan.kuppuswamy
2018-03-08  8:54     ` [PATCH v1 1/1] " Oliver Neukum
2018-03-08  8:54       ` [v1,1/1] " Oliver Neukum
2018-03-08 23:29       ` [PATCH v1 1/1] " sathyanarayanan kuppuswamy
2018-03-08 23:29         ` [v1,1/1] " sathyanarayanan.kuppuswamy
2018-03-08 23:43         ` [PATCH v1 1/1] " Greg KH
2018-03-08 23:43           ` [v1,1/1] " Greg Kroah-Hartman
2018-03-09  0:34           ` [PATCH v1 1/1] " sathyanarayanan kuppuswamy
2018-03-09  0:34             ` [v1,1/1] " sathyanarayanan.kuppuswamy
2018-03-08 14:01     ` [PATCH v1 1/1] " Greg KH
2018-03-08 14:01       ` [v1,1/1] " Greg Kroah-Hartman

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.