Received: by 2002:a4a:3008:0:0:0:0:0 with SMTP id q8-v6csp3534285oof; Mon, 10 Sep 2018 16:31:14 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbAfVrw0EJL+kv+OPSTGT2RkF2XjA3lOowt7ihcS4AbMkihkdGj4/UyAe3OVIaBl9eTLeEF X-Received: by 2002:a65:40cd:: with SMTP id u13-v6mr24955390pgp.334.1536622274102; Mon, 10 Sep 2018 16:31:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536622274; cv=none; d=google.com; s=arc-20160816; b=jLNqAXEjB8BFlxnG5ntycx5BkfxrEYGJRTWAU+eqkW6fw7OkxFos9I0dl9cMxgPM8v SCrZ3bKc+LqQCfQUItfCeAR58OXMtI9LvSSReNgxplVeKHE0MLCItJV77ULvWI1hU3Ef /2Lp/Lpyujr+sCa5dhelKOavPUpP/PcC9bZCAzktsSFnGV8R+GsOJEmTa5gF9InzJM6Q AiwvcnjnHVK7lCEUcIKH7nBKhOJqyyRu9mLc+LlSt3xDlB9eiazxcAiCgKHK2LvqM/zT NQzXIoPllxhF2cZ8vc2ISbTe+CBAOfWE1/6gxWjwLh3QlO/yOMQ2Y6rAOC5n94BmjBZ8 9oRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature; bh=NcJTiVda9qNLkIcK6ilDi4YUjY23ckcR220NYasT/7I=; b=rUaCzd+jr2xR2OQntYYzrrUWGjs5Ex2NcZDdvKihaNSVl378NWvWrqNdwoffWakpCa xBSo2A77yatam/aOhk84KACGZ/MTb7D0H88C3rZU/P9cIpfDEY/WIwv607KXL2yFqeqm 3LbgelSGRBFx6YVPz12mANAYv/qtyi291B6FhuUjejaiXtQiiVKuHVI464WY2qLtGQUB 0aTQjQFYyk1vLF9ZQ9cLyqkoauDgQ9DNMK8dFtOGRq4YGh7xikze+hv2DjM1c4Mcpr4M EU8QFxNOYSwWc5aHXZdYIz4k8dJhrMQfKThshOwma7E9lthnZPeJLndstttPbVDgZw8R WtPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dFXeI7Ws; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p187-v6si19879598pfp.27.2018.09.10.16.30.58; Mon, 10 Sep 2018 16:31:14 -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; dkim=pass header.i=@chromium.org header.s=google header.b=dFXeI7Ws; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726393AbeIKE1O (ORCPT + 99 others); Tue, 11 Sep 2018 00:27:14 -0400 Received: from mail-yb1-f195.google.com ([209.85.219.195]:42461 "EHLO mail-yb1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726143AbeIKE1O (ORCPT ); Tue, 11 Sep 2018 00:27:14 -0400 Received: by mail-yb1-f195.google.com with SMTP id j8-v6so8634676ybg.9 for ; Mon, 10 Sep 2018 16:30:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=NcJTiVda9qNLkIcK6ilDi4YUjY23ckcR220NYasT/7I=; b=dFXeI7WstUtnaOoeKX4qnTmMVKYrX4z6q1smOuZGBbrYZyIEl42CxRpxAuS3atHKaD bdBtbUkyvquwkzqghp7X3QfWmfXXaNpiuKgo+3dV/ey11cPXnKLg0JiaEeyJejcH20Ze spx4FaoC11dWvOXMTFUSd3EzrVctLkvCx38C4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=NcJTiVda9qNLkIcK6ilDi4YUjY23ckcR220NYasT/7I=; b=HU4gK649m/Y+3nZVGvtNoSFNBLXDFkLqHwZWvVM5J3rfI54VGlknFAiWDehXrGYvl9 sT1o1HCcaRe32I0xTiVItG3qFnIu+1yXUCSYgmw2/FDJTWe66JTUshgn1uMZE77Z4BWQ DdmFlML3IQ2keeVehzga6IZ4X+N06s2f7hYYpDQPjqzc2ICL1MVbSPP+pofryWFjZgoN 2yl8x2Sxa3d0vGKkYiDWUVRpQyJsXCdDFc/B1Q1eGd4MDOTdBdYIYgPbhsa9xEiR018E d2NiAKkuJrgjEuf1n0QcA2xPp5eI3NGymMojaDN5B0HRMm8amC62KnI/dHnhcR9o3BUP y4tg== X-Gm-Message-State: APzg51CfyTif9DxJ4qfh18r8+den2il+P0jqAnbRpQaC1+OLzJif6ey0 o1VIFj0dzmKFctCQyZjiiWrrj+nkLVE= X-Received: by 2002:a25:a4c8:: with SMTP id g66-v6mr11278808ybi.76.1536622249723; Mon, 10 Sep 2018 16:30:49 -0700 (PDT) Received: from mail-yw1-f48.google.com (mail-yw1-f48.google.com. [209.85.161.48]) by smtp.gmail.com with ESMTPSA id d6-v6sm5743303ywa.85.2018.09.10.16.30.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Sep 2018 16:30:48 -0700 (PDT) Received: by mail-yw1-f48.google.com with SMTP id n21-v6so8532019ywh.5 for ; Mon, 10 Sep 2018 16:30:47 -0700 (PDT) X-Received: by 2002:a81:1194:: with SMTP id 142-v6mr11699570ywr.168.1536622247298; Mon, 10 Sep 2018 16:30:47 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a25:5f04:0:0:0:0:0 with HTTP; Mon, 10 Sep 2018 16:30:46 -0700 (PDT) In-Reply-To: <20180910223723.25357-1-labbott@redhat.com> References: <20180910223723.25357-1-labbott@redhat.com> From: Kees Cook Date: Mon, 10 Sep 2018 16:30:46 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] scsi: ibmvscsis: Fix a stringop-overflow warning To: Laura Abbott Cc: "Bryant G. Ly" , Michael Cyr , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, target-devel , LKML , Prarit Bhargava Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); > 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? -Kees -- Kees Cook Pixel Security