public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* re: [SCSI] qla4xxx: support iscsiadm session mgmt
@ 2012-06-14 18:27 Dan Carpenter
  2012-08-08 15:00 ` Dan Carpenter
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2012-06-14 18:27 UTC (permalink / raw)
  To: manish.rangankar; +Cc: Mike Christie, open-iscsi, linux-kernel

Hi Manish,

The patch b3a271a94d00: "[SCSI] qla4xxx: support iscsiadm session 
mgmt" from Jul 25, 2011, leads to the following warning:
drivers/scsi/qla4xxx/ql4_os.c:4479 qla4xxx_get_ep_fwdb()
	 warn: casting from 16 to 28 bytes

(Sort of).

drivers/scsi/qla4xxx/ql4_os.c qla4xxx_ep_connect()
   705          qla_ep = ep->dd_data;
   706          memset(qla_ep, 0, sizeof(struct qla_endpoint));
   707          if (dst_addr->sa_family == AF_INET) {
   708                  memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
   709                  addr = (struct sockaddr_in *)&qla_ep->dst_addr;
   710                  DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
   711                                    (char *)&addr->sin_addr));
   712          } else if (dst_addr->sa_family == AF_INET6) {
   713                  memcpy(&qla_ep->dst_addr, dst_addr,
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   714                         sizeof(struct sockaddr_in6));
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Both qla_ep->dst_addr and dst_addr are type struct sockaddr.  We are
copying sizeof(struct sockaddr_in6) bytes which is 12 bytes larger.  I
don't know the actual size of qla_ep->dst_addr but dst_addr is allocated
in qla4xxx_get_ep_fwdb() as a struct sockaddr.  So we are copying past
the end of the struct here and it's possibly an information leak or even
a memory corruption issue depending on how much space ep->dd_data has.

   715                  addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
   716                  DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
   717                                    (char *)&addr6->sin6_addr));
   718          }

regards,
dan carpenter


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

* Re: [SCSI] qla4xxx: support iscsiadm session mgmt
  2012-06-14 18:27 [SCSI] qla4xxx: support iscsiadm session mgmt Dan Carpenter
@ 2012-08-08 15:00 ` Dan Carpenter
  2012-08-08 15:35   ` Mike Christie
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2012-08-08 15:00 UTC (permalink / raw)
  To: manish.rangankar; +Cc: Mike Christie, open-iscsi, linux-kernel

I never heard back on this.  This buffer overflow is still present
in the current code.

regards,
dan carpenter

On Thu, Jun 14, 2012 at 09:27:45PM +0300, Dan Carpenter wrote:
> Hi Manish,
> 
> The patch b3a271a94d00: "[SCSI] qla4xxx: support iscsiadm session 
> mgmt" from Jul 25, 2011, leads to the following warning:
> drivers/scsi/qla4xxx/ql4_os.c:4479 qla4xxx_get_ep_fwdb()
> 	 warn: casting from 16 to 28 bytes
> 
> (Sort of).
> 
> drivers/scsi/qla4xxx/ql4_os.c qla4xxx_ep_connect()
>    705          qla_ep = ep->dd_data;
>    706          memset(qla_ep, 0, sizeof(struct qla_endpoint));
>    707          if (dst_addr->sa_family == AF_INET) {
>    708                  memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
>    709                  addr = (struct sockaddr_in *)&qla_ep->dst_addr;
>    710                  DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
>    711                                    (char *)&addr->sin_addr));
>    712          } else if (dst_addr->sa_family == AF_INET6) {
>    713                  memcpy(&qla_ep->dst_addr, dst_addr,
>                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>    714                         sizeof(struct sockaddr_in6));
>                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> Both qla_ep->dst_addr and dst_addr are type struct sockaddr.  We are
> copying sizeof(struct sockaddr_in6) bytes which is 12 bytes larger.  I
> don't know the actual size of qla_ep->dst_addr but dst_addr is allocated
> in qla4xxx_get_ep_fwdb() as a struct sockaddr.  So we are copying past
> the end of the struct here and it's possibly an information leak or even
> a memory corruption issue depending on how much space ep->dd_data has.
> 
>    715                  addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
>    716                  DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
>    717                                    (char *)&addr6->sin6_addr));
>    718          }
> 
> regards,
> dan carpenter

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

* Re: [SCSI] qla4xxx: support iscsiadm session mgmt
  2012-08-08 15:00 ` Dan Carpenter
@ 2012-08-08 15:35   ` Mike Christie
  2012-08-08 16:57     ` Dan Carpenter
  0 siblings, 1 reply; 5+ messages in thread
From: Mike Christie @ 2012-08-08 15:35 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: manish.rangankar, open-iscsi, linux-kernel

On 08/08/2012 10:00 AM, Dan Carpenter wrote:
> I never heard back on this.  This buffer overflow is still present
> in the current code.
> 

Qlogic just sent a patch yesterday.
http://marc.info/?l=linux-scsi&m=134434199930938&w=2

> regards,
> dan carpenter
> 
> On Thu, Jun 14, 2012 at 09:27:45PM +0300, Dan Carpenter wrote:
>> Hi Manish,
>>
>> The patch b3a271a94d00: "[SCSI] qla4xxx: support iscsiadm session 
>> mgmt" from Jul 25, 2011, leads to the following warning:
>> drivers/scsi/qla4xxx/ql4_os.c:4479 qla4xxx_get_ep_fwdb()
>> 	 warn: casting from 16 to 28 bytes
>>
>> (Sort of).
>>
>> drivers/scsi/qla4xxx/ql4_os.c qla4xxx_ep_connect()
>>    705          qla_ep = ep->dd_data;
>>    706          memset(qla_ep, 0, sizeof(struct qla_endpoint));
>>    707          if (dst_addr->sa_family == AF_INET) {
>>    708                  memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
>>    709                  addr = (struct sockaddr_in *)&qla_ep->dst_addr;
>>    710                  DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
>>    711                                    (char *)&addr->sin_addr));
>>    712          } else if (dst_addr->sa_family == AF_INET6) {
>>    713                  memcpy(&qla_ep->dst_addr, dst_addr,
>>                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>    714                         sizeof(struct sockaddr_in6));
>>                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>
>> Both qla_ep->dst_addr and dst_addr are type struct sockaddr.  We are
>> copying sizeof(struct sockaddr_in6) bytes which is 12 bytes larger.  I
>> don't know the actual size of qla_ep->dst_addr but dst_addr is allocated
>> in qla4xxx_get_ep_fwdb() as a struct sockaddr.  So we are copying past
>> the end of the struct here and it's possibly an information leak or even
>> a memory corruption issue depending on how much space ep->dd_data has.
>>
>>    715                  addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
>>    716                  DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
>>    717                                    (char *)&addr6->sin6_addr));
>>    718          }
>>
>> regards,
>> dan carpenter


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

* Re: [SCSI] qla4xxx: support iscsiadm session mgmt
  2012-08-08 15:35   ` Mike Christie
@ 2012-08-08 16:57     ` Dan Carpenter
  2012-08-09 17:49       ` Michael Christie
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2012-08-08 16:57 UTC (permalink / raw)
  To: Mike Christie; +Cc: manish.rangankar, open-iscsi, linux-kernel

On Wed, Aug 08, 2012 at 10:35:44AM -0500, Mike Christie wrote:
> On 08/08/2012 10:00 AM, Dan Carpenter wrote:
> > I never heard back on this.  This buffer overflow is still present
> > in the current code.
> > 
> 
> Qlogic just sent a patch yesterday.
> http://marc.info/?l=linux-scsi&m=134434199930938&w=2

Ah, good.

It seems like qla4xxx_ep_connect() should take a pointer to struct
sockaddr_storage and also dst_addr in qla4xxx_get_ep_fwdb() should
be changed as well.  As in:

 static struct iscsi_endpoint *
-qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
+qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr_storage *dst_addr,
                    int non_blocking)

regards,
dan carpenter

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

* Re: [SCSI] qla4xxx: support iscsiadm session mgmt
  2012-08-08 16:57     ` Dan Carpenter
@ 2012-08-09 17:49       ` Michael Christie
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Christie @ 2012-08-09 17:49 UTC (permalink / raw)
  To: open-iscsi; +Cc: manish.rangankar, linux-kernel


On Aug 8, 2012, at 11:57 AM, Dan Carpenter <dan.carpenter@oracle.com> wrote:

> On Wed, Aug 08, 2012 at 10:35:44AM -0500, Mike Christie wrote:
>> On 08/08/2012 10:00 AM, Dan Carpenter wrote:
>>> I never heard back on this.  This buffer overflow is still present
>>> in the current code.
>>> 
>> 
>> Qlogic just sent a patch yesterday.
>> http://marc.info/?l=linux-scsi&m=134434199930938&w=2
> 
> Ah, good.
> 
> It seems like qla4xxx_ep_connect() should take a pointer to struct
> sockaddr_storage and also dst_addr in qla4xxx_get_ep_fwdb() should
> be changed as well.  As in:
> 
> static struct iscsi_endpoint *
> -qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
> +qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr_storage *dst_addr,
>                    int non_blocking)


Do you mean that should be done to fix a bug or to just make it nicer? I think it will not be a issue bug wise, because it ends up getting cast to the proper struct in the end and the proper size to copy is detected. What actually gets passed that function above is not a struct sockaddr_storage. It is a sockaddr_in or socaddr_in6. It depends on if it is ipv6 or not.

If you are just saying it would be nicer to be consistent in the struct used then it is a larger change that I think should be done in another patch. It will affect other drivers.

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

end of thread, other threads:[~2012-08-09 17:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-14 18:27 [SCSI] qla4xxx: support iscsiadm session mgmt Dan Carpenter
2012-08-08 15:00 ` Dan Carpenter
2012-08-08 15:35   ` Mike Christie
2012-08-08 16:57     ` Dan Carpenter
2012-08-09 17:49       ` Michael Christie

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