Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp249536yba; Fri, 12 Apr 2019 02:49:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqxTtbm+v7MnnGq5rop2mXjgQlK9i+iP5vslCyMnk2LxzKjikJdq+FhjQAz4qYgfasFmEURO X-Received: by 2002:a17:902:28e9:: with SMTP id f96mr34664813plb.190.1555062579081; Fri, 12 Apr 2019 02:49:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555062579; cv=none; d=google.com; s=arc-20160816; b=GXjYrbJsXmKNf2sXwbnKqhvfSZcOeWUHnrlRqRpRFCuU0ujkoB3UMEBjRpcJ5wjtww 6xCPMXpASpM2jRbCX5wzX4HAd/JiIrSFPtP/J3ObW1MkrM6c5kIqomEmKmAQ4Ns4EAJS ylINQTTcGB6NA+izVbTS4gk1GztMBOgThIpo3MeW+/e132zHk9AUgMEIFSBepCSHEj7I ovcP+wTS2jJc3BbpO1EJ0wEhtM72Oow4giaPKW0Zn6tL3baZ7tzSoMhS7SUW1iNz1+O0 vyBmXhjuYviw1yq+OKCJPEBkAXnrIXXLq8h8Z3QSVC5/fsba8IFFgwn22DUQIYnZiWvH 7Adg== 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:mime-version :message-id:date:subject:cc:to:from; bh=/OWkSijGYddoU3nigEmMSJ10tpiuyWB9anvRHTYa/HM=; b=SajWSX2T5BFSdAph2Fi0ZnSkkOs09mEZVZW7RFebU8tyRdR1YNDYHeVc1rshXLE98v 7d2r/J6q1ra980MvGl3QRvmmUKCjvahVs1RhAHMiJgDGzHFSlwtlVj8Xr1mouuNEuZDo MBKNMlsyow3rG/6Nt75JtirZhpEw6qAsgiPAKgdm2uChdWfwRyFbXhPRU+JcFJTThDSS ViX2Rn06zsW6w1rkvrdG8SBl7pL4KuhdFdaTYg27S3V53ebtU2/7nJC9LAVVuMDHmrVT R5P48mXoXbw/gzN4lrxhW5xriHxTirlQgodxdeHmsIyS9hd0zLKb+Jrx30TQa/oSPAuv /aMg== 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=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c14si20187894pfn.40.2019.04.12.02.49.23; Fri, 12 Apr 2019 02:49:39 -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=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726857AbfDLJse (ORCPT + 99 others); Fri, 12 Apr 2019 05:48:34 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:49429 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726713AbfDLJse (ORCPT ); Fri, 12 Apr 2019 05:48:34 -0400 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1hEsnN-0005FC-IV; Fri, 12 Apr 2019 09:48:29 +0000 From: Colin King To: QLogic-Storage-Upstream@cavium.com, "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][V2] scsi: qedf: remove memset/memcpy to nfunc and use func instead Date: Fri, 12 Apr 2019 10:48:29 +0100 Message-Id: <20190412094829.15868-1-colin.king@canonical.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King Currently the qedf_dbg_* family of functions can overrun the end of the source string if it is less than the destination buffer length because of the use of a fixed sized memcpy. Remove the memset/memcpy calls to nfunc and just use func instead as it is always a null terminated string. Addresses-Coverity: ("Out-of-bounds access") Fixes: 61d8658b4a43 ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver framework.") Signed-off-by: Colin Ian King --- V2: replace the V1 strscpy with just using func since this is always going to be a NUL terminated string. Thanks to Rasmus Villemoes for noticing that. --- drivers/scsi/qedf/qedf_dbg.c | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/drivers/scsi/qedf/qedf_dbg.c b/drivers/scsi/qedf/qedf_dbg.c index f2397ee9ba69..f7d170bffc82 100644 --- a/drivers/scsi/qedf/qedf_dbg.c +++ b/drivers/scsi/qedf/qedf_dbg.c @@ -15,10 +15,6 @@ qedf_dbg_err(struct qedf_dbg_ctx *qedf, const char *func, u32 line, { va_list va; struct va_format vaf; - char nfunc[32]; - - memset(nfunc, 0, sizeof(nfunc)); - memcpy(nfunc, func, sizeof(nfunc) - 1); va_start(va, fmt); @@ -27,9 +23,9 @@ qedf_dbg_err(struct qedf_dbg_ctx *qedf, const char *func, u32 line, if (likely(qedf) && likely(qedf->pdev)) pr_err("[%s]:[%s:%d]:%d: %pV", dev_name(&(qedf->pdev->dev)), - nfunc, line, qedf->host_no, &vaf); + func, line, qedf->host_no, &vaf); else - pr_err("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf); + pr_err("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf); va_end(va); } @@ -40,10 +36,6 @@ qedf_dbg_warn(struct qedf_dbg_ctx *qedf, const char *func, u32 line, { va_list va; struct va_format vaf; - char nfunc[32]; - - memset(nfunc, 0, sizeof(nfunc)); - memcpy(nfunc, func, sizeof(nfunc) - 1); va_start(va, fmt); @@ -55,9 +47,9 @@ qedf_dbg_warn(struct qedf_dbg_ctx *qedf, const char *func, u32 line, if (likely(qedf) && likely(qedf->pdev)) pr_warn("[%s]:[%s:%d]:%d: %pV", dev_name(&(qedf->pdev->dev)), - nfunc, line, qedf->host_no, &vaf); + func, line, qedf->host_no, &vaf); else - pr_warn("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf); + pr_warn("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf); ret: va_end(va); @@ -69,10 +61,6 @@ qedf_dbg_notice(struct qedf_dbg_ctx *qedf, const char *func, u32 line, { va_list va; struct va_format vaf; - char nfunc[32]; - - memset(nfunc, 0, sizeof(nfunc)); - memcpy(nfunc, func, sizeof(nfunc) - 1); va_start(va, fmt); @@ -84,10 +72,10 @@ qedf_dbg_notice(struct qedf_dbg_ctx *qedf, const char *func, u32 line, if (likely(qedf) && likely(qedf->pdev)) pr_notice("[%s]:[%s:%d]:%d: %pV", - dev_name(&(qedf->pdev->dev)), nfunc, line, + dev_name(&(qedf->pdev->dev)), func, line, qedf->host_no, &vaf); else - pr_notice("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf); + pr_notice("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf); ret: va_end(va); @@ -99,10 +87,6 @@ qedf_dbg_info(struct qedf_dbg_ctx *qedf, const char *func, u32 line, { va_list va; struct va_format vaf; - char nfunc[32]; - - memset(nfunc, 0, sizeof(nfunc)); - memcpy(nfunc, func, sizeof(nfunc) - 1); va_start(va, fmt); @@ -114,9 +98,9 @@ qedf_dbg_info(struct qedf_dbg_ctx *qedf, const char *func, u32 line, if (likely(qedf) && likely(qedf->pdev)) pr_info("[%s]:[%s:%d]:%d: %pV", dev_name(&(qedf->pdev->dev)), - nfunc, line, qedf->host_no, &vaf); + func, line, qedf->host_no, &vaf); else - pr_info("[0000:00:00.0]:[%s:%d]: %pV", nfunc, line, &vaf); + pr_info("[0000:00:00.0]:[%s:%d]: %pV", func, line, &vaf); ret: va_end(va); -- 2.20.1