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


Groups > linux.kernel > #1647025 > unrolled thread

Re: [PATCH] csiostor: Avoid content leaks and casts

Started byVarun Prakash <varun@chelsio.com>
First post2017-05-22 17:10 +0200
Last post2017-05-23 11:40 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH] csiostor: Avoid content leaks and casts Varun Prakash <varun@chelsio.com> - 2017-05-22 17:10 +0200
    Re: [PATCH] csiostor: Avoid content leaks and casts Kees Cook <keescook@chromium.org> - 2017-05-22 18:30 +0200
      Re: [PATCH] csiostor: Avoid content leaks and casts Varun Prakash <varun@chelsio.com> - 2017-05-23 11:40 +0200

#1647025 — Re: [PATCH] csiostor: Avoid content leaks and casts

FromVarun Prakash <varun@chelsio.com>
Date2017-05-22 17:10 +0200
SubjectRe: [PATCH] csiostor: Avoid content leaks and casts
Message-ID<tJX86-7gH-21@gated-at.bofh.it>
On Tue, May 09, 2017 at 03:34:44PM -0700, Kees Cook wrote:
> When copying attributes, the len argument was padded out and the resulting
> memcpy() would copy beyond the end of the source buffer.  Avoid this,
> and use size_t for val_len to avoid all the casts. Similarly, avoid source
> buffer casts and use void *.
> 
> Additionally enforces val_len can be represented by u16 and that
> the DMA buffer was not overflowed. Fixes the size of mfa, which is not
> FC_FDMI_PORT_ATTR_MAXFRAMESIZE_LEN (but it will be padded up to 4). This
> was noticed by the future CONFIG_FORTIFY_SOURCE checks.
> 
> Cc: Daniel Micay <danielmicay@gmail.com>
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
>  drivers/scsi/csiostor/csio_lnode.c | 43 +++++++++++++++++++++++---------------
>  1 file changed, 26 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/scsi/csiostor/csio_lnode.c b/drivers/scsi/csiostor/csio_lnode.c
> index c00b2ff72b55..be5ee2d37815 100644
> --- a/drivers/scsi/csiostor/csio_lnode.c
> +++ b/drivers/scsi/csiostor/csio_lnode.c
> @@ -238,14 +238,23 @@ csio_osname(uint8_t *buf, size_t buf_len)
>  }
>  


>  
>  	csio_append_attrib(&pld, FC_FDMI_HBA_ATTR_MAXCTPAYLOAD,
> -			   (uint8_t *)&maxpayload,
> -			   FC_FDMI_HBA_ATTR_MAXCTPAYLOAD_LEN);
> +			   &maxpayload, FC_FDMI_HBA_ATTR_MAXCTPAYLOAD_LEN);
>  	len = (uint32_t)(pld - (uint8_t *)cmd);
>  	numattrs++;
>  	attrib_blk->numattrs = htonl(numattrs);
> @@ -1794,6 +1801,8 @@ csio_ln_mgmt_submit_req(struct csio_ioreq *io_req,
>  	struct csio_mgmtm *mgmtm = csio_hw_to_mgmtm(hw);
>  	int rv;
>  
> +	BUG_ON(pld_len > pld->len);
> +

I think WARN_ON() is better than BUG_ON() in this case

	if (WARN_ON(pld_len > pld->len))
		return -EINVAL;

>  	io_req->io_cbfn = io_cbfn;	/* Upper layer callback handler */
>  	io_req->fw_handle = (uintptr_t) (io_req);
>  	io_req->eq_idx = mgmtm->eq_idx;

[toc] | [next] | [standalone]


#1647106

FromKees Cook <keescook@chromium.org>
Date2017-05-22 18:30 +0200
Message-ID<tJYnv-80c-11@gated-at.bofh.it>
In reply to#1647025
On Mon, May 22, 2017 at 8:05 AM, Varun Prakash <varun@chelsio.com> wrote:
> On Tue, May 09, 2017 at 03:34:44PM -0700, Kees Cook wrote:
>> When copying attributes, the len argument was padded out and the resulting
>> memcpy() would copy beyond the end of the source buffer.  Avoid this,
>> and use size_t for val_len to avoid all the casts. Similarly, avoid source
>> buffer casts and use void *.
>>
>> Additionally enforces val_len can be represented by u16 and that
>> the DMA buffer was not overflowed. Fixes the size of mfa, which is not
>> FC_FDMI_PORT_ATTR_MAXFRAMESIZE_LEN (but it will be padded up to 4). This
>> was noticed by the future CONFIG_FORTIFY_SOURCE checks.
>>
>> Cc: Daniel Micay <danielmicay@gmail.com>
>> Signed-off-by: Kees Cook <keescook@chromium.org>
>> ---
>>  drivers/scsi/csiostor/csio_lnode.c | 43 +++++++++++++++++++++++---------------
>>  1 file changed, 26 insertions(+), 17 deletions(-)
>>
>> diff --git a/drivers/scsi/csiostor/csio_lnode.c b/drivers/scsi/csiostor/csio_lnode.c
>> index c00b2ff72b55..be5ee2d37815 100644
>> --- a/drivers/scsi/csiostor/csio_lnode.c
>> +++ b/drivers/scsi/csiostor/csio_lnode.c
>> @@ -238,14 +238,23 @@ csio_osname(uint8_t *buf, size_t buf_len)
>>  }
>>
>
>
>>
>>       csio_append_attrib(&pld, FC_FDMI_HBA_ATTR_MAXCTPAYLOAD,
>> -                        (uint8_t *)&maxpayload,
>> -                        FC_FDMI_HBA_ATTR_MAXCTPAYLOAD_LEN);
>> +                        &maxpayload, FC_FDMI_HBA_ATTR_MAXCTPAYLOAD_LEN);
>>       len = (uint32_t)(pld - (uint8_t *)cmd);
>>       numattrs++;
>>       attrib_blk->numattrs = htonl(numattrs);
>> @@ -1794,6 +1801,8 @@ csio_ln_mgmt_submit_req(struct csio_ioreq *io_req,
>>       struct csio_mgmtm *mgmtm = csio_hw_to_mgmtm(hw);
>>       int rv;
>>
>> +     BUG_ON(pld_len > pld->len);
>> +
>
> I think WARN_ON() is better than BUG_ON() in this case
>
>         if (WARN_ON(pld_len > pld->len))
>                 return -EINVAL;
>
>>       io_req->io_cbfn = io_cbfn;      /* Upper layer callback handler */
>>       io_req->fw_handle = (uintptr_t) (io_req);
>>       io_req->eq_idx = mgmtm->eq_idx;

I chose BUG_ON here because the damage has already been done. If this
assertion is hit, the heap buffers have already been overrun. This
isn't a state we should only warn about...

-Kees

-- 
Kees Cook
Pixel Security

[toc] | [prev] | [next] | [standalone]


#1647884

FromVarun Prakash <varun@chelsio.com>
Date2017-05-23 11:40 +0200
Message-ID<tKesi-1hY-9@gated-at.bofh.it>
In reply to#1647106
On Mon, May 22, 2017 at 09:29:41AM -0700, Kees Cook wrote:
> On Mon, May 22, 2017 at 8:05 AM, Varun Prakash <varun@chelsio.com> wrote:
> > On Tue, May 09, 2017 at 03:34:44PM -0700, Kees Cook wrote:
> >> When copying attributes, the len argument was padded out and the resulting
> >> memcpy() would copy beyond the end of the source buffer.  Avoid this,
> >> and use size_t for val_len to avoid all the casts. Similarly, avoid source
> >> buffer casts and use void *.
> >>
> >> Additionally enforces val_len can be represented by u16 and that
> >> the DMA buffer was not overflowed. Fixes the size of mfa, which is not
> >> FC_FDMI_PORT_ATTR_MAXFRAMESIZE_LEN (but it will be padded up to 4). This
> >> was noticed by the future CONFIG_FORTIFY_SOURCE checks.
> >>
> >> Cc: Daniel Micay <danielmicay@gmail.com>
> >> Signed-off-by: Kees Cook <keescook@chromium.org>
> >> ---
> >>  drivers/scsi/csiostor/csio_lnode.c | 43 +++++++++++++++++++++++---------------
> >>  1 file changed, 26 insertions(+), 17 deletions(-)
> >>
> >> diff --git a/drivers/scsi/csiostor/csio_lnode.c b/drivers/scsi/csiostor/csio_lnode.c
> >> index c00b2ff72b55..be5ee2d37815 100644
> >> --- a/drivers/scsi/csiostor/csio_lnode.c
> >> +++ b/drivers/scsi/csiostor/csio_lnode.c
> >> @@ -238,14 +238,23 @@ csio_osname(uint8_t *buf, size_t buf_len)
> >>  }
> >>
> >
> >
> >>
> >>       csio_append_attrib(&pld, FC_FDMI_HBA_ATTR_MAXCTPAYLOAD,
> >> -                        (uint8_t *)&maxpayload,
> >> -                        FC_FDMI_HBA_ATTR_MAXCTPAYLOAD_LEN);
> >> +                        &maxpayload, FC_FDMI_HBA_ATTR_MAXCTPAYLOAD_LEN);
> >>       len = (uint32_t)(pld - (uint8_t *)cmd);
> >>       numattrs++;
> >>       attrib_blk->numattrs = htonl(numattrs);
> >> @@ -1794,6 +1801,8 @@ csio_ln_mgmt_submit_req(struct csio_ioreq *io_req,
> >>       struct csio_mgmtm *mgmtm = csio_hw_to_mgmtm(hw);
> >>       int rv;
> >>
> >> +     BUG_ON(pld_len > pld->len);
> >> +
> >
> > I think WARN_ON() is better than BUG_ON() in this case
> >
> >         if (WARN_ON(pld_len > pld->len))
> >                 return -EINVAL;
> >
> >>       io_req->io_cbfn = io_cbfn;      /* Upper layer callback handler */
> >>       io_req->fw_handle = (uintptr_t) (io_req);
> >>       io_req->eq_idx = mgmtm->eq_idx;
> 
> I chose BUG_ON here because the damage has already been done. If this
> assertion is hit, the heap buffers have already been overrun. This
> isn't a state we should only warn about...
> 

Ok.

Acked-by: Varun Prakash <varun@chelsio.com>

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web