From patchwork Tue Sep 11 19:22:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laura Abbott X-Patchwork-Id: 10596217 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C030B14BD for ; Tue, 11 Sep 2018 19:22:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA1A229D0D for ; Tue, 11 Sep 2018 19:22:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE56F29D21; Tue, 11 Sep 2018 19:22:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 518DF29D0D for ; Tue, 11 Sep 2018 19:22:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728132AbeILAXU (ORCPT ); Tue, 11 Sep 2018 20:23:20 -0400 Received: from mail-qk1-f196.google.com ([209.85.222.196]:38205 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728071AbeILAXT (ORCPT ); Tue, 11 Sep 2018 20:23:19 -0400 Received: by mail-qk1-f196.google.com with SMTP id g197-v6so17532050qke.5 for ; Tue, 11 Sep 2018 12:22:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ta5tHOBMbSYoicbu0+CPW7rTPB5krKblxPmZPIYaX7A=; b=a4+z4wqBYEUSFODSeW7HFFUh1gGBNNgfKbNZdWygQEPLB2siJnCzUr6XsRIBhPcxS9 DKOr6/R0U7bwBMxjruWvZaYtx2UAlqmKhg/+m/UuV2zHopJ9765pjdgtcq1EHcfbaDlo 1jsLBeLDavQte0sU/9dAAzHFjW++Tw4K16Wdn0A+ookDdyITnPV6GUef5v4uILqiFVey GAaGMojRNUpAFAVqv3jBqtDFOhPZGmFBhqAoLf/9FRH8frxjgm+aenIfwKS0rB2VVbTw sPOPjH2qZVcihZd5dNQxXau7ikaptmst2SsFn/jZKWKgsgmP34T6kxx1CjRQp1jc9EEA Hxnw== X-Gm-Message-State: APzg51BzaLOAtNv87QYgpPxjFdMBhlSdWGbu+gWf4w12d4c/iXNjeMkW oGyOH+iUMvvy78qfJZpOFSI5TA== X-Google-Smtp-Source: ANB0VdbmpoEGoSSuxumh2RAvcCGh6GccWKxp2YlXEHXHyh9qfMagyf4N92ahnEwbGZGN8jZL68aJmg== X-Received: by 2002:a37:1414:: with SMTP id e20-v6mr19562943qkh.88.1536693754793; Tue, 11 Sep 2018 12:22:34 -0700 (PDT) Received: from labbott-redhat.redhat.com ([2601:602:9802:a8dc::42c3]) by smtp.gmail.com with ESMTPSA id g14-v6sm13639452qtc.66.2018.09.11.12.22.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Sep 2018 12:22:33 -0700 (PDT) From: Laura Abbott To: "Bryant G. Ly" , Michael Cyr , Kees Cook Cc: Laura Abbott , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCHv3 1/2] scsi: ibmvscsis: Fix a stringop-overflow warning Date: Tue, 11 Sep 2018 12:22:25 -0700 Message-Id: <20180911192226.3620-2-labbott@redhat.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180911192226.3620-1-labbott@redhat.com> References: <20180911192226.3620-1-labbott@redhat.com> Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 a single snprintf instead of a strcpy + strcat to handle this cleanly. Signed-off-by: Laura Abbott Reviewed-by: Bryant G. Ly bly@catalogicsoftware.com --- v3: Make sure there is an extra space in the partition name --- drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c b/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c index fac377320158..b3a029ad07cd 100644 --- a/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c +++ b/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c @@ -3474,8 +3474,7 @@ static int ibmvscsis_probe(struct vio_dev *vdev, vscsi->dds.window[LOCAL].liobn, vscsi->dds.window[REMOTE].liobn); - strcpy(vscsi->eye, "VSCSI "); - strncat(vscsi->eye, vdev->name, MAX_EYE); + snprintf(vscsi->eye, sizeof(vscsi->eye), "VSCSI %s", vdev->name); vscsi->dds.unit_id = vdev->unit_address; strncpy(vscsi->dds.partition_name, partition_name, From patchwork Tue Sep 11 19:22:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laura Abbott X-Patchwork-Id: 10596213 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EE22814F9 for ; Tue, 11 Sep 2018 19:22:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E700829D20 for ; Tue, 11 Sep 2018 19:22:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DAC2929D1A; Tue, 11 Sep 2018 19:22:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C7F4C29D1A for ; Tue, 11 Sep 2018 19:22:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727805AbeILAXV (ORCPT ); Tue, 11 Sep 2018 20:23:21 -0400 Received: from mail-qt0-f194.google.com ([209.85.216.194]:43988 "EHLO mail-qt0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728150AbeILAXV (ORCPT ); Tue, 11 Sep 2018 20:23:21 -0400 Received: by mail-qt0-f194.google.com with SMTP id g53-v6so29460698qtg.10 for ; Tue, 11 Sep 2018 12:22:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IYDLXOvqXi5U1MpjfZDRh4TELVkjnKkN4SnOhEmKxyU=; b=l4tBlzRKopUwTSBXfarjuDVK0RxBlzp/MwKlVWkx7r2NZLd54mFFL168+wTj08+dB5 5jPgtdTE0AE/+qwM1Av8m8/FROrGq2FiUfrLj6Df9hb3vYaQUo78q2ghIugEdTdDfVGh 6oz5l0Jk/f6/nb0ncie/t/JqjOcxlzeNqP6VeI70XBnW9Fz6oPNlA+3MgDl1wiOZfx4r m7qTaQ87IJS4FpPbmOieSH3MurlHLRftOZeL05dc5M5qqdLJINfRNjI5RR8WdFASaqUZ QQq5MhFzB4li5b5BxpW86wJ7dCHfZtFl9zSGKeUbkx7ynSoFPKy5LBxBDmRazyddY7I7 0+eA== X-Gm-Message-State: APzg51AIvBTvuE0Px4csAwCFdHF03Nvzam3bpI0jnHUwk5WK3cYBpg7R 3Ms8/Ymx8/9/s2I/x3Xu200eaQ== X-Google-Smtp-Source: ANB0VdbpXC6hn2sjKF29TZkHQO+B1eGtVLUg2Sc11SgggHa2Uq7Si1DGRVx/gzX38uK0UpdskCj/jg== X-Received: by 2002:aed:3c55:: with SMTP id u21-v6mr20941353qte.198.1536693757296; Tue, 11 Sep 2018 12:22:37 -0700 (PDT) Received: from labbott-redhat.redhat.com ([2601:602:9802:a8dc::42c3]) by smtp.gmail.com with ESMTPSA id g14-v6sm13639452qtc.66.2018.09.11.12.22.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Sep 2018 12:22:36 -0700 (PDT) From: Laura Abbott To: "Bryant G. Ly" , Michael Cyr , Kees Cook Cc: Laura Abbott , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCHv2 2/2] scsi: ibmvscsis: Ensure partition name is properly NUL terminated Date: Tue, 11 Sep 2018 12:22:26 -0700 Message-Id: <20180911192226.3620-3-labbott@redhat.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180911192226.3620-1-labbott@redhat.com> References: <20180911192226.3620-1-labbott@redhat.com> Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP While reviewing another part of the code, Kees noticed that the strncpy of the partition name might not always be NUL terminated. Switch to using strscpy which does this safely. Reported-by: Kees Cook Signed-off-by: Laura Abbott Reviewed-by: Kees Cook Reviewed-by: Bryant G. Ly bly@catalogicsoftware.com --- v2: Switch to strscpy instead of just strlcpy --- 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 b3a029ad07cd..f42a619198c4 100644 --- a/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c +++ b/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c @@ -3477,7 +3477,7 @@ static int ibmvscsis_probe(struct vio_dev *vdev, snprintf(vscsi->eye, sizeof(vscsi->eye), "VSCSI %s", vdev->name); vscsi->dds.unit_id = vdev->unit_address; - strncpy(vscsi->dds.partition_name, partition_name, + strscpy(vscsi->dds.partition_name, partition_name, sizeof(vscsi->dds.partition_name)); vscsi->dds.partition_num = partition_number;