From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935256AbdEVPF4 (ORCPT ); Mon, 22 May 2017 11:05:56 -0400 Received: from stargate.chelsio.com ([12.32.117.8]:27216 "EHLO stargate.chelsio.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934539AbdEVPFy (ORCPT ); Mon, 22 May 2017 11:05:54 -0400 Date: Mon, 22 May 2017 20:35:47 +0530 From: Varun Prakash To: Kees Cook Cc: linux-kernel@vger.kernel.org, "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Daniel Micay Subject: Re: [PATCH] csiostor: Avoid content leaks and casts Message-ID: <20170522150544.GA1677@chelsio.com> References: <20170509223444.GA51314@beast> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170509223444.GA51314@beast> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > Signed-off-by: Kees Cook > --- > 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;