From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id 7C49E1B1BA for ; Thu, 5 Oct 2017 15:02:22 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8DAE1FECD; Thu, 5 Oct 2017 13:02:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8DAE1FECD Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=maxime.coquelin@redhat.com Received: from [10.36.112.45] (ovpn-112-45.ams2.redhat.com [10.36.112.45]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1AE3C6062A; Thu, 5 Oct 2017 13:02:18 +0000 (UTC) To: Bruce Richardson Cc: "Piasecki, JacekX" , "Jastrzebski, MichalX K" , "yliu@fridaylinux.org" , "dev@dpdk.org" , "Jain, Deepak K" , "Liu, Changpeng" References: <20170922130734.7256-1-michalx.k.jastrzebski@intel.com> <60ABE07DBB3A454EB7FAD707B4BB158213C40F16@IRSMSX109.ger.corp.intel.com> <0a469856-29c8-a79e-bb6a-ad21dfbccaf4@redhat.com> <8B71977F507A4143BF605D4D8BA8F23C0114CD14@HASMSX106.ger.corp.intel.com> <52f9f89c-dcf0-a3cb-166c-76ec2c83ddc5@redhat.com> <20171005130112.GB12160@bricha3-MOBL3.ger.corp.intel.com> From: Maxime Coquelin Message-ID: <258f3999-b425-965a-287d-345e1f5d529c@redhat.com> Date: Thu, 5 Oct 2017 15:02:15 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20171005130112.GB12160@bricha3-MOBL3.ger.corp.intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 05 Oct 2017 13:02:21 +0000 (UTC) Subject: Re: [dpdk-dev] [PATCH] examples/vhost_scsi: fix buffer not terminated X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Oct 2017 13:02:22 -0000 On 10/05/2017 03:01 PM, Bruce Richardson wrote: > On Thu, Oct 05, 2017 at 02:42:24PM +0200, Maxime Coquelin wrote: >> >> >> On 10/05/2017 02:35 PM, Piasecki, JacekX wrote: >>> -----Original Message----- >>> From: Maxime Coquelin [mailto:maxime.coquelin@redhat.com] >>> Sent: Monday, 2 October, 2017 17:07 >>> To: Jastrzebski, MichalX K ; yliu@fridaylinux.org >>> Cc: dev@dpdk.org; Jain, Deepak K ; Piasecki, JacekX ; Liu, Changpeng ; stable@dpdk.org >>> Subject: Re: [dpdk-dev] [PATCH] examples/vhost_scsi: fix buffer not terminated >>> >>> >>> >>> On 10/02/2017 03:50 PM, Jastrzebski, MichalX K wrote: >>>>> -----Original Message----- >>>>> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Michal >>>>> Jastrzebski >>>>> Sent: Friday, September 22, 2017 3:08 PM >>>>> To: yliu@fridaylinux.org; maxime.coquelin@redhat.com >>>>> Cc: dev@dpdk.org; Jain, Deepak K ; Piasecki, >>>>> JacekX ; Liu, Changpeng >>>>> ; stable@dpdk.org >>>>> Subject: [dpdk-dev] [PATCH] examples/vhost_scsi: fix buffer not >>>>> terminated >>>>> >>>>> From: Jacek Piasecki >>>>> >>>>> Fix size of buffer in strcpy. There was possible to get not >>>>> terminated string after copy operation. >>>>> >>>>> Coverity issue: 158631 >>>>> Fixes: db75c7af19bb ("examples/vhost_scsi: introduce a new sample >>>>> app") >>>>> Cc: changpeng.liu@intel.com >>>>> Cc: stable@dpdk.org >>>>> >>>>> Signed-off-by: Jacek Piasecki >>>>> --- >>>>> examples/vhost_scsi/scsi.c | 3 ++- >>>>> 1 file changed, 2 insertions(+), 1 deletion(-) >>>>> >>>>> diff --git a/examples/vhost_scsi/scsi.c b/examples/vhost_scsi/scsi.c >>>>> index 54d3104..de9639a 100644 >>>>> --- a/examples/vhost_scsi/scsi.c >>>>> +++ b/examples/vhost_scsi/scsi.c >>>>> @@ -307,7 +307,8 @@ >>>>> strncpy((char *)inqdata->t10_vendor_id, "INTEL", 8); >>>>> >>>>> /* PRODUCT IDENTIFICATION */ >>>>> - strncpy((char *)inqdata->product_id, bdev->product_name, >>>>> 16); >>>>> + strncpy((char *)inqdata->product_id, bdev->product_name, >>>>> + ARRAY_SIZE(inqdata->product_id) - 1); >>> >>> Does it assume that product_id is memzero'ed before? >>> IIUC strncpy manpage, it wouldn't protect against non-null terminated strings if it is not the case: >>> >>> Yes, I assumed that this area is zeroed before strncpy. Earlier there is a casting from *task to *inqdata (*task is zmalloced). >> Ok. I think the assumption is dangerous. >> >>> To be sure that the destination area is clear I propose to add: >>> memset(inqdata->product_id, 0, ARRAY_SIZE(inqdata->product_id)); >>> before strncpy. Would that be OK? >> >> Or call strncpy with ARRAY_SIZE(inqdata->product_id) as max length, >> and then do >> inqdata->product_id[ARRAY_SIZE(inqdata->product_id) - 1] = '\0'; >> >> Regards, >> Maxime >>> > Or use snprintf instead of strncpy, as we do in many places in DPDK. > Still only one line of code, with nice null-termination, and truncation > semantics. +1 > /Bruce >