From: Maxime Coquelin <maxime.coquelin@redhat.com>
To: "Piasecki, JacekX" <jacekx.piasecki@intel.com>,
"Jastrzebski, MichalX K" <michalx.k.jastrzebski@intel.com>,
"yliu@fridaylinux.org" <yliu@fridaylinux.org>
Cc: "dev@dpdk.org" <dev@dpdk.org>,
"Jain, Deepak K" <deepak.k.jain@intel.com>,
"Liu, Changpeng" <changpeng.liu@intel.com>
Subject: Re: [dpdk-dev] [PATCH] examples/vhost_scsi: fix buffer not terminated
Date: Thu, 5 Oct 2017 14:42:24 +0200 [thread overview]
Message-ID: <52f9f89c-dcf0-a3cb-166c-76ec2c83ddc5@redhat.com> (raw)
In-Reply-To: <8B71977F507A4143BF605D4D8BA8F23C0114CD14@HASMSX106.ger.corp.intel.com>
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 <michalx.k.jastrzebski@intel.com>; yliu@fridaylinux.org
> Cc: dev@dpdk.org; Jain, Deepak K <deepak.k.jain@intel.com>; Piasecki, JacekX <jacekx.piasecki@intel.com>; Liu, Changpeng <changpeng.liu@intel.com>; 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 <deepak.k.jain@intel.com>; Piasecki,
>>> JacekX <jacekx.piasecki@intel.com>; Liu, Changpeng
>>> <changpeng.liu@intel.com>; stable@dpdk.org
>>> Subject: [dpdk-dev] [PATCH] examples/vhost_scsi: fix buffer not
>>> terminated
>>>
>>> From: Jacek Piasecki <jacekx.piasecki@intel.com>
>>>
>>> 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 <jacekx.piasecki@intel.com>
>>> ---
>>> 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
>
> Regards,
> Jacek
>
>>>
>>> /* PRODUCT REVISION LEVEL */
>>> strncpy((char *)inqdata->product_rev, "0001", 4);
>>> --
>>> 1.9.1
>>
>> Hi Yu / Maxime,
>> I would like to ask for a feedback regarding proposed fix.
>> If everything is ok with it, please send acked-by.
>>
>> Best regards
>> Michal.
>>
next prev parent reply other threads:[~2017-10-05 12:42 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-22 13:07 Michal Jastrzebski
2017-10-02 13:50 ` Jastrzebski, MichalX K
2017-10-02 15:07 ` Maxime Coquelin
2017-10-05 12:35 ` Piasecki, JacekX
2017-10-05 12:42 ` Maxime Coquelin [this message]
2017-10-05 13:01 ` Bruce Richardson
2017-10-05 13:02 ` Maxime Coquelin
2017-10-12 6:44 ` [dpdk-dev] [PATCH v2] " Jacek Piasecki
2017-10-12 11:09 ` Maxime Coquelin
2017-10-12 11:34 ` [dpdk-dev] [PATCH v3] " Jacek Piasecki
2017-10-13 7:12 ` Maxime Coquelin
2017-10-17 13:26 ` Yuanhan Liu
2017-10-24 16:22 ` [dpdk-dev] [dpdk-stable] " Thomas Monjalon
2017-10-25 10:07 ` [dpdk-dev] [PATCH v4] " Jacek Piasecki
2017-10-25 10:18 ` Thomas Monjalon
2017-09-22 13:08 [dpdk-dev] [PATCH] " Michal Jastrzebski
2017-09-22 13:23 ` Jastrzebski, MichalX K
2017-09-22 13:09 Michal Jastrzebski
2017-10-02 13:53 ` Jastrzebski, MichalX K
2017-10-11 13:45 ` Jastrzebski, MichalX K
2018-05-14 19:08 ` Thomas Monjalon
2018-05-15 5:59 ` Pattan, Reshma
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=52f9f89c-dcf0-a3cb-166c-76ec2c83ddc5@redhat.com \
--to=maxime.coquelin@redhat.com \
--cc=changpeng.liu@intel.com \
--cc=deepak.k.jain@intel.com \
--cc=dev@dpdk.org \
--cc=jacekx.piasecki@intel.com \
--cc=michalx.k.jastrzebski@intel.com \
--cc=yliu@fridaylinux.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).