From patchwork Sun Oct 22 20:59:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 156603 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp943129vqx; Sun, 22 Oct 2023 14:00:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IET51h6S2ufYeHnFU7sysshst8xmJUnb93jGzCoAOg0OEndycptphM9fy1IK9rm4v8AK6As X-Received: by 2002:a05:6a20:da9f:b0:16b:c20d:fcd1 with SMTP id iy31-20020a056a20da9f00b0016bc20dfcd1mr11325271pzb.21.1698008442816; Sun, 22 Oct 2023 14:00:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698008442; cv=none; d=google.com; s=arc-20160816; b=aU1E6l/ajPEIoQDd5mca4fwNaPi3JRrZVcvm+OBK8X3Pi3DlAx/OA0rzDXWfxrqz9d 14e4ckKDFO+UMDeMnl2nJO8wEcTKA81CXmWNFjZ2eg1CCOz4F9dqXLDb6+tjMW7Wqucd VmKF5sk2ucPeWirLlP/PeNtnJooiWlII67dPWFqwKt9DdiePw6MH3GaOOWYsOzTzGd1h ImDujVV/B5152W9JiNVf5COKaDTZqRBq+feFnq9j22uTN4PDYQ4LYdQ1ptd2TzlioEIz yxVbQFalsYuJCE0vFXgc75ZSMhQpTm0m4HDEQsU1MSZab/o9sBoDC117mTmlYjXe/2AN 27UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=W0mHaNEAAUX2nTaO6oddXS59CQugHmEWhSnV8c4UJ+w=; fh=YiX7ZcaVtj3M2tXkFquBaNQ3ZfkMNtB7gv9cu9mmu04=; b=IS4VQ8M9qI3cTSGvz5U/gsLkRfQ8qoPUSZKjLp+zKZ4NefH44ATg1gGjs6DT9lxvat mw6s3TNwy1W5D6bpbG/e5IKj2X6JerxG5RglsMdS/KAY/qTGj3cM7oME+risBmwsrkMD UAYNDGFmdJkfvM86QAH6/ye/WAwGrhJtWYeWMGraESgsFOAOrfybTpay2hOZ0QSPzSTE b4DdYnXZXJBUWKoA7Hu76k3haZpy5jYq1AJNqKSvVFaH0bds7jjTDbNHXf8oD5lVEQzZ gA3zWSn+WQLv5bJ+0qe8Up8wFAcMMmSv+/nzd2F+K9jNW4jgKLkpAL2PFU2lAMZN7iue a7sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=UxbDtzfo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id a23-20020a637057000000b005a9debd7854si5193331pgn.828.2023.10.22.14.00.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Oct 2023 14:00:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=UxbDtzfo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 737ED8092CA4; Sun, 22 Oct 2023 14:00:40 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232655AbjJVVA2 (ORCPT + 27 others); Sun, 22 Oct 2023 17:00:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232708AbjJVVA1 (ORCPT ); Sun, 22 Oct 2023 17:00:27 -0400 Received: from smtp.smtpout.orange.fr (smtp-16.smtpout.orange.fr [80.12.242.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF5BD126 for ; Sun, 22 Oct 2023 14:00:24 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id ufYFqwcwpG6boufYdqoCCl; Sun, 22 Oct 2023 23:00:23 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1698008423; bh=W0mHaNEAAUX2nTaO6oddXS59CQugHmEWhSnV8c4UJ+w=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=UxbDtzfouZDnBiHAY7DY4xX5Tf2OqORvmMe7We+8GBAdJ3IU/P+6Q9u7nxkUNbxU0 XiNAMfBiNWFs99Zczv0LH6m6oj5Kq6Iji3ALJUQyKjWMHTw4uio+/MYJnwA1bO/6+Q RnhczO2O942rlK/5B1OzgsvX3uICfJg05m6jD92x7lueFfPc3fAxZH56OYqkkb/X86 Y9OzKhbYJVwu3OyF7lcYW1Bf9nx7kBvonzjkLokWtftsIqhRcJ8TDYt86/eUTZ1SBv 0NbQCcTyFss5/bkwM1kZ8lpoRy68YLlV7GfW2OL6UPSGvPg1MerPNx/VYUilpuRkFd Hsq7qCbOo1Oqg== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 22 Oct 2023 23:00:23 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: dchickles@marvell.com, sburla@marvell.com, fmanlunas@marvell.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, veerasenareddy.burru@cavium.com Cc: felix.manlunas@cavium.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH net 1/2] liquidio: Fix an off by one in octeon_download_firmware() Date: Sun, 22 Oct 2023 22:59:46 +0200 Message-Id: <30f085627802594da71bb0b5ca52213ab11301fc.1698007858.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Sun, 22 Oct 2023 14:00:40 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780490873473909822 X-GMAIL-MSGID: 1780490900627559938 In order to append the 'boottime' string to 'h->bootcmd', the final NULL has to betaken into account when checking if there is enough space. Fixes: 907aaa6babe1 ("liquidio: pass date and time info to NIC firmware") Signed-off-by: Christophe JAILLET --- drivers/net/ethernet/cavium/liquidio/octeon_console.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/cavium/liquidio/octeon_console.c b/drivers/net/ethernet/cavium/liquidio/octeon_console.c index 67c3570f875f..bd6baf2872a5 100644 --- a/drivers/net/ethernet/cavium/liquidio/octeon_console.c +++ b/drivers/net/ethernet/cavium/liquidio/octeon_console.c @@ -899,13 +899,13 @@ int octeon_download_firmware(struct octeon_device *oct, const u8 *data, ret = snprintf(boottime, MAX_BOOTTIME_SIZE, " time_sec=%lld time_nsec=%ld", (s64)ts.tv_sec, ts.tv_nsec); - if ((sizeof(h->bootcmd) - strnlen(h->bootcmd, sizeof(h->bootcmd))) < + if ((sizeof(h->bootcmd) - strnlen(h->bootcmd, sizeof(h->bootcmd))) <= ret) { dev_err(&oct->pci_dev->dev, "Boot command buffer too small\n"); return -EINVAL; } strncat(h->bootcmd, boottime, - sizeof(h->bootcmd) - strnlen(h->bootcmd, sizeof(h->bootcmd))); + sizeof(h->bootcmd) - strnlen(h->bootcmd, sizeof(h->bootcmd)) - 1); dev_info(&oct->pci_dev->dev, "Writing boot command: %s\n", h->bootcmd); From patchwork Sun Oct 22 20:59:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 156605 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp943575vqx; Sun, 22 Oct 2023 14:01:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG9R45OL5o//dib2z4IEmcN+bCgJKJClJ1WgHni0YBnR7EPBAdbVDWEfDgsDkwLlxw6fOOX X-Received: by 2002:a05:6a21:a108:b0:15d:e68d:a850 with SMTP id aq8-20020a056a21a10800b0015de68da850mr7934428pzc.29.1698008492543; Sun, 22 Oct 2023 14:01:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698008492; cv=none; d=google.com; s=arc-20160816; b=DgZFctTVfLUcW7Y3og/0s9+joMXWJKz/RUOFCK3RY9AHbzkTT1nm35V0oeXX3EBGTD +dwd06zLWbgcfBBlV62hCPqzTSXhJCUVcLY+uOGtjIhm+q2H94nHEdLaNsO+SNd3HssV WZez/MxDsUNnQdegyHVXA7YI8eXht8syFbhIRWsezsGyQo/PbofAOYjaH3SNmIm3aQ96 TlSJ52/12iE96zOTinvv8VPhOIlLSx99CTt050WgVF14MsoOT4SERB8BpddY86hoYOxC KzHYxn6bdKbXDpcHMfwDOQ0hsm0hv2baa3+qOrTvbcMS+anaVeRX8oFI0KoaH9uXeZYK ZgCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5hCOY5dOqdwNpSOWKR6WdA1L7vg708cH5c+HUNqRzWo=; fh=YiX7ZcaVtj3M2tXkFquBaNQ3ZfkMNtB7gv9cu9mmu04=; b=qpQkTWAkeUJEnUoBRm3JEeuSbmtJKb/F+JbeeBVKaZq4gMwqBID568RZMa/cu3D3qa 3w2HkdbAP1mOaMc+OZn/bJY2NWrGu8ei/v9JOcY5vtTjF6ceWfd60aJVfaC18ccJRGIG hS9uEjFBGDVeqSENsOTy+o+sfmX+WUNijhljuA8SgZuGXUvP2RnvBRvz1bUGL0eu8+3j hT4TYPnbMTvfnjDzAORcnqyByvB+crG+Oo2ED6DUkp3f13Bm5HO6DwbXSh+Tfko4sikT ZmotKHDBNIUkCpXaEOoOm523qByijKx6Cab3A1l361Jgjd6Yg/P5pQpzoj2Bji25/BBd tw7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=FiMJ67yb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id h184-20020a6383c1000000b00585a45417a3si5124129pge.156.2023.10.22.14.01.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Oct 2023 14:01:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=FiMJ67yb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id AEE65807478C; Sun, 22 Oct 2023 14:00:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229452AbjJVVAd (ORCPT + 27 others); Sun, 22 Oct 2023 17:00:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232709AbjJVVAb (ORCPT ); Sun, 22 Oct 2023 17:00:31 -0400 Received: from smtp.smtpout.orange.fr (smtp-15.smtpout.orange.fr [80.12.242.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E5EEE9 for ; Sun, 22 Oct 2023 14:00:28 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id ufYFqwcwpG6boufYhqoCDQ; Sun, 22 Oct 2023 23:00:27 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1698008427; bh=5hCOY5dOqdwNpSOWKR6WdA1L7vg708cH5c+HUNqRzWo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=FiMJ67ybukLxN+2kR7KwWOqtEO6OdNB043ggY48x5x1mdydJdVBNqlQUaVo2DDFhV LBKJNenKjyJlYWt/1Dyu1PZHMGaM3WUH/IIDcDucMwijLro+Xf/LfrOiKbOW89zdTh P7rYnqlmK7eXETkuNCnVq1uhzyfXR/eifYd9dHpc7Hp33Ush5Hp5XJRme2DbuYBlqd JOQwQN57XdOLc1GxYKZPHCenj2dJ93sPppTgSp+ypJcyHE5paASoMoJrGi9GWMTDgH reJX18UNv7l6CYwmH7jVdiLyblpXaCW3kr4hW+0B3SA6gRXukmbzFOSt2yKCI7h3E0 0LXbvv1FOlMXg== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 22 Oct 2023 23:00:27 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: dchickles@marvell.com, sburla@marvell.com, fmanlunas@marvell.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, veerasenareddy.burru@cavium.com Cc: felix.manlunas@cavium.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH net 2/2] liquidio: Simplify octeon_download_firmware() Date: Sun, 22 Oct 2023 22:59:47 +0200 Message-Id: <0278c7dfbc23f78a2d85060369132782f8466090.1698007858.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 22 Oct 2023 14:00:45 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780490952609649276 X-GMAIL-MSGID: 1780490952609649276 In order to remove the usage of strncat(), write directly at the rigth place in the 'h->bootcmd' array and check if the output is truncated. Signed-off-by: Christophe JAILLET --- The goal is to potentially remove the strncat() function from the kernel. Their are only few users and most of them use it wrongly. This patch is compile tested only. --- .../net/ethernet/cavium/liquidio/octeon_console.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/cavium/liquidio/octeon_console.c b/drivers/net/ethernet/cavium/liquidio/octeon_console.c index bd6baf2872a5..f1f0d7a0309a 100644 --- a/drivers/net/ethernet/cavium/liquidio/octeon_console.c +++ b/drivers/net/ethernet/cavium/liquidio/octeon_console.c @@ -802,19 +802,17 @@ static int octeon_console_read(struct octeon_device *oct, u32 console_num, } #define FBUF_SIZE (4 * 1024 * 1024) -#define MAX_BOOTTIME_SIZE 80 int octeon_download_firmware(struct octeon_device *oct, const u8 *data, size_t size) { struct octeon_firmware_file_header *h; - char boottime[MAX_BOOTTIME_SIZE]; struct timespec64 ts; u32 crc32_result; + u32 i, rem, used; u64 load_addr; u32 image_len; int ret = 0; - u32 i, rem; if (size < sizeof(struct octeon_firmware_file_header)) { dev_err(&oct->pci_dev->dev, "Firmware file too small (%d < %d).\n", @@ -896,16 +894,15 @@ int octeon_download_firmware(struct octeon_device *oct, const u8 *data, * Octeon always uses UTC time. so timezone information is not sent. */ ktime_get_real_ts64(&ts); - ret = snprintf(boottime, MAX_BOOTTIME_SIZE, + + used = strnlen(h->bootcmd, sizeof(h->bootcmd)); + ret = snprintf(h->bootcmd + used, sizeof(h->bootcmd) - used, " time_sec=%lld time_nsec=%ld", (s64)ts.tv_sec, ts.tv_nsec); - if ((sizeof(h->bootcmd) - strnlen(h->bootcmd, sizeof(h->bootcmd))) <= - ret) { + if (ret >= sizeof(h->bootcmd) - used) { dev_err(&oct->pci_dev->dev, "Boot command buffer too small\n"); return -EINVAL; } - strncat(h->bootcmd, boottime, - sizeof(h->bootcmd) - strnlen(h->bootcmd, sizeof(h->bootcmd)) - 1); dev_info(&oct->pci_dev->dev, "Writing boot command: %s\n", h->bootcmd);