Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4377857imm; Tue, 11 Sep 2018 10:56:25 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdaca2kwIvoeBAfhzPJlrO2ibjuJO0AlhoF0wPt/EqocIt5znhCxVriSzc6pT97WUK/AaetS X-Received: by 2002:a63:c702:: with SMTP id n2-v6mr30176024pgg.108.1536688585229; Tue, 11 Sep 2018 10:56:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536688585; cv=none; d=google.com; s=arc-20160816; b=YXZKrO7dF1BaO7VTlRgLd2NWgE35ExBHhSMSpif8qoGbnbYTekmbqVXiGqv/Y8FL2G Qu5oZTMTtgKNXVVEJHv6nEQdAU+/CSwgIfX89tLgzUC6EQE90lOxY59Hlb+CN4ng2KZf wBhO2luqwFovkluwYsvmww5myEeQXPPATEK2iS9J4htPN5cmWGQI9AOCucFnoTjj99fx o036+WKN6v6eaHPPCMQI3+YmZpzSpE6sb487VvEFXrla5B/DShnhqceDNqKRtJOSZN60 bHAZW6GXNQqdpgAaC1p3P3utxAkaralkp/do8I2VHnAW5IPqBG97D+g2ahnSr/qYgio1 k6ZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=eX40pw1gYlsecW+rcTLM1uBV+HJDFWvSB2IJl6ogqDA=; b=fbkfnVtrRKDiH82vClaN9YWDUkLV9+yBhBVNrcE7134EoxpMgko9kSdI8C3yusHGvd paUPa/zPlr1Srq4Au5iCFtVk8vHRGIdU07xa2XZrbZ4UYf2K6+hOliC1FcqXo3REdhit qeuTHD/5mV2PLgUy4hi/PpvqHKSsifvxO0mBjVjolAyWP7efFhPLQKNF2NkCCXm5kq6l G58marIytLyntpnQJpSsQpkG6E2N3yQAZayMvFMcP5XBtGAJm4//CBNzyo2/wV9fV2Hv eqbPvu+lg1xlIGB836tX8E26n6rujpTd7c3vs/YssnBoA7nKMWDrllWOQ9gGmrcspsMd Z1WA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l64-v6si19586817pge.420.2018.09.11.10.56.02; Tue, 11 Sep 2018 10:56:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728139AbeIKWz6 (ORCPT + 99 others); Tue, 11 Sep 2018 18:55:58 -0400 Received: from mail-qk1-f196.google.com ([209.85.222.196]:33548 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726782AbeIKWz6 (ORCPT ); Tue, 11 Sep 2018 18:55:58 -0400 Received: by mail-qk1-f196.google.com with SMTP id z78-v6so17338509qka.0 for ; Tue, 11 Sep 2018 10:55:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=eX40pw1gYlsecW+rcTLM1uBV+HJDFWvSB2IJl6ogqDA=; b=oKPtb1LtuHmEpyefmfEWRwVC/qYE5ATZffKHdsc29nVTmIr7r5QzaAeHyOIihox68V sIzPvdp2jbA2CKGD7ksV8QiCBu35U4eEZMPbT+PYj2pYaPAoWkrhyptr0hbHYazCfKVM T2fp/2ShqFQsCvPHsI7srYbnf97jghS43myBRUplG46cbLN6v6s1C/CZ8MjGi/8BJk64 6FkvrI9VwTUFtO2HxkeqftzIA22zvYUCYWgoyZ+qafQD/zlkomQ+XymwRXDqPv27SwoC Ehmzj/jhQ74NOsFN+ZgFzM4TXlDezR7o8zN8hl6yK/u7BEPF2Ad9HNodO9SO/mJQz7Xg HNIw== X-Gm-Message-State: APzg51CabiVSyDctN+dlXWyc1M2s8Ae5C3+MtrKbo64MyqWrrDQ+3pTs U2SmwDFREOjuNGXSOLrvZVidsA== X-Received: by 2002:a37:5e03:: with SMTP id s3-v6mr20083773qkb.339.1536688532909; Tue, 11 Sep 2018 10:55:32 -0700 (PDT) Received: from ?IPv6:2601:602:9802:a8dc::42c3? ([2601:602:9802:a8dc::42c3]) by smtp.gmail.com with ESMTPSA id 63-v6sm10873965qkm.0.2018.09.11.10.55.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Sep 2018 10:55:31 -0700 (PDT) Subject: Re: [PATCH] scsi: ibmvscsis: Fix a stringop-overflow warning To: "Bryant G. Ly" , Kees Cook Cc: "Bryant G. Ly" , Michael Cyr , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, target-devel , LKML , Prarit Bhargava References: <20180910223723.25357-1-labbott@redhat.com> <36c9adee-fbe8-f58d-e407-bbd57fdb1959@linux.ibm.com> From: Laura Abbott Message-ID: Date: Tue, 11 Sep 2018 10:55:29 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <36c9adee-fbe8-f58d-e407-bbd57fdb1959@linux.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/11/2018 07:34 AM, Bryant G. Ly wrote: > On 9/10/18 6:30 PM, Kees Cook wrote: > >> On Mon, Sep 10, 2018 at 3:37 PM, Laura Abbott wrote: >>> There's currently a warning about string overflow with strncat: >>> >>> drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c: In function 'ibmvscsis_probe': >>> drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c:3479:2: error: 'strncat' specified >>> bound 64 equals destination size [-Werror=stringop-overflow=] >>> strncat(vscsi->eye, vdev->name, MAX_EYE); >>> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >>> >>> Switch to using strlcat which correctly accounts for lengths that >>> are equal to the destination buffer. >>> >>> Signed-off-by: Laura Abbott >>> --- >>> drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git a/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c b/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c >>> index fac377320158..53d344d8dc43 100644 >>> --- a/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c >>> +++ b/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c >>> @@ -3475,7 +3475,7 @@ static int ibmvscsis_probe(struct vio_dev *vdev, >>> vscsi->dds.window[REMOTE].liobn); >>> >>> strcpy(vscsi->eye, "VSCSI "); >>> - strncat(vscsi->eye, vdev->name, MAX_EYE); >>> + strlcat(vscsi->eye, vdev->name, MAX_EYE); >> Can this just get switched to snprintf() instead? >> >> snprintf(vscsi->eye, sizeof(vscsi->eye), "VSCSI%s", vdev->name); > > Either works for me. > I'll switch to the snprintf since that's cleaner. >> >>> vscsi->dds.unit_id = vdev->unit_address; >>> strncpy(vscsi->dds.partition_name, partition_name, >> And does this strncpy need a NUL-termination and/or trailing padding? >> > Yes, good catch, it does need NUL-termination. > I can send that cleanup in a second patch. > -Bryant > >