From patchwork Mon Mar 22 16:02:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 406165 Delivered-To: patch@linaro.org Received: by 2002:a17:906:5290:0:0:0:0 with SMTP id c16csp1348297ejm; Mon, 22 Mar 2021 09:05:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+wuRkXgk6iOVDYcHacZ7u5cAo7tzTUxMmL+iEBGeGeLyWZkB3VJftw3yEr8ilJimVFOA8 X-Received: by 2002:a17:90a:498d:: with SMTP id d13mr86381pjh.47.1616429120485; Mon, 22 Mar 2021 09:05:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616429120; cv=none; d=google.com; s=arc-20160816; b=oEldlYoS8eNjgsd7RQdD9JfcwqMMDYrlx66MI4nNe9SPfKqOH7GO7bOydD45Ye0lga GBJU1T22ZRnc7Bo4y0xQNeg3p3x+mDzvZ+jKjaKEEYgJ0rxaXysOAnMOiSj7kaCrptw5 rbg1vplcFM/wl5o2ETEyzU2Xe5bQgUUXsycwuev90BF+aOpv5HVFY10+Gkr5IFCieQ00 8otCmyaGqWUuQLGnyqA55ukS29UUfAhMmrKn4LCT6tVi02IHdTuu03cfVsk97QIlYcdL Mk+nx8zkyNTjHQ4+5CH3tL7aEUaP87l/yIlSGHKuKjwh+6juUSKCodY/uXdcwERsTgG8 jIUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:delivered-to; bh=lVaBl3rZkdopO3vct4+hDOQmILxH7e6aV4WCoEQ8K7M=; b=XEgtkae7a8I41GRewxAeoCIYYbDN0dAU1T3cvxc5CmA3vuAwqRywLQXorlQHqNw6Ip Hs4qR0YwM01lq+yFwm8lkO1ojf9/OrLl71iot5aiC7cM6Y7p2ay0SLaVb8dUHYaINgaB kzQOOTd/IXMqGt09SUmDlFvjWV0B0U/5moq6y5JXwMr6ivioS/kifiR8dpFq4/pQzi+M feOO92YO+Yp1GV7JNWI+E/ZD1UpIHhmwEIevVx73b8zWdwWifZ99pszFwyUZGmZsggPU t5TkcgXb7EqJKipptM0UieI7i6koYbexZ3SjNKKhE8kAxJ42qHNuf4mH+6e/cHNx4zoc z29A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b=odvbczUM; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [2610:10:20:722:a800:ff:fe36:1795]) by mx.google.com with ESMTPS id y15si15709747pll.388.2021.03.22.09.05.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 09:05:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) client-ip=2610:10:20:722:a800:ff:fe36:1795; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b=odvbczUM; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 68DFF6E505; Mon, 22 Mar 2021 16:05:19 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by gabe.freedesktop.org (Postfix) with ESMTPS id ABA246E505; Mon, 22 Mar 2021 16:05:18 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 72908619A9; Mon, 22 Mar 2021 16:05:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616429118; bh=EPe3bIidXGt1QSXUt8K/T9qB09rG8+BNJJvNG8YjWag=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=odvbczUMlcMOL6OYbdCtO6qt6RZm272nfTphlFLY6klU5CkTn017tx34pnASZGNCF IpTcV7nYkdiHmdTO4YSIbtaihkUG1yjP/yyOdl4AEWNcNqBp3RlBD18ZnYm597BmUn wbL0s1j6ZDhyXNOvtPSEo+IomEmxiiG2PhvFgAApDhn6IwYxk6QphMYP+c26QRueLZ RufWjyGVlIhAtQ1wf9LhLwHYQjNNIjPOnznUa3dYOSsg79XhSsMNd+utp3nEch/2kA G7BxSH7No+IViGt23UWj5mYSj83XwgoEag8qXDcmE/UvDP4IP5Eh1a52oCa4LWy515 1pAfWyFQAG1Kg== From: Arnd Bergmann To: linux-kernel@vger.kernel.org, Martin Sebor , James Smart , Dick Kennedy , "James E.J. Bottomley" , "Martin K. Petersen" Subject: [PATCH 09/11] scsi: lpfc: fix gcc -Wstringop-overread warning Date: Mon, 22 Mar 2021 17:02:47 +0100 Message-Id: <20210322160253.4032422-10-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210322160253.4032422-1-arnd@kernel.org> References: <20210322160253.4032422-1-arnd@kernel.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anders Larsen , dri-devel@lists.freedesktop.org, Lee Jones , linux-scsi@vger.kernel.org, x86@kernel.org, tboot-devel@lists.sourceforge.net, Kalle Valo , ath11k@lists.infradead.org, Ye Bin , Serge Hallyn , Arnd Bergmann , intel-gfx@lists.freedesktop.org, Ning Sun , Hannes Reinecke , Colin Ian King , cgroups@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, linux-wireless@vger.kernel.org, linux-security-module@vger.kernel.org, Tejun Heo , Simon Kelley Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Arnd Bergmann gcc-11 warns about an strnlen with a length larger than the size of the passed buffer: drivers/scsi/lpfc/lpfc_attr.c: In function 'lpfc_nvme_info_show': drivers/scsi/lpfc/lpfc_attr.c:518:25: error: 'strnlen' specified bound 4095 exceeds source size 24 [-Werror=stringop-overread] 518 | strnlen(LPFC_NVME_INFO_MORE_STR, PAGE_SIZE - 1) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In this case, the code is entirely valid, as the string is properly terminated, and the size argument is only there out of extra caution in case it exceeds a page. This cannot really happen here, so just simplify it to a sizeof(). Fixes: afff0d2321ea ("scsi: lpfc: Add Buffer overflow check, when nvme_info larger than PAGE_SIZE") Signed-off-by: Arnd Bergmann --- drivers/scsi/lpfc/lpfc_attr.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) -- 2.29.2 _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel diff --git a/drivers/scsi/lpfc/lpfc_attr.c b/drivers/scsi/lpfc/lpfc_attr.c index bdd9a29f4201..f6d886f9dfb3 100644 --- a/drivers/scsi/lpfc/lpfc_attr.c +++ b/drivers/scsi/lpfc/lpfc_attr.c @@ -512,11 +512,9 @@ lpfc_nvme_info_show(struct device *dev, struct device_attribute *attr, "6314 Catching potential buffer " "overflow > PAGE_SIZE = %lu bytes\n", PAGE_SIZE); - strlcpy(buf + PAGE_SIZE - 1 - - strnlen(LPFC_NVME_INFO_MORE_STR, PAGE_SIZE - 1), + strlcpy(buf + PAGE_SIZE - 1 - sizeof(LPFC_NVME_INFO_MORE_STR), LPFC_NVME_INFO_MORE_STR, - strnlen(LPFC_NVME_INFO_MORE_STR, PAGE_SIZE - 1) - + 1); + sizeof(LPFC_NVME_INFO_MORE_STR) + 1); } return len;