From patchwork Wed Oct 11 21:37:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Stitt X-Patchwork-Id: 13417984 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B736ECDB482 for ; Wed, 11 Oct 2023 21:37:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: Mime-Version:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=62/rHhfoRR1pmjHwTuSJdsq3Np7+mLfBiF9QJBvLMM8=; b=x/g xQGUmiaCqxlYrkaB0b0dxpggLnNSPo8UmtZB7NR1GVFKTW6lqjbjyVMafoUhXFIa66MbjYICbf+Ko VYB3lKiZ0EJvwNipmEk+WJjt2tCuBqsXfolnTj40/9IuUm9ELobXRAftsVWW2PolJ4/SZQGrsFr/A v+mPAud80XK9Zn+ZYLGuPPYvFXaC83TSUnkDbyDV/HCYbBznMoex9rnzLkGLTApqJYqIJH1k2TgWd IF1/Tlw7VWniaKTpm+6fUjFsknw1QT+lkFNbIjfpuDQGFPmIOyT+3OjDbBIEHAY4gmncYbx/BJex0 9uCOsA8Ey7LKU0dZ/mQtjUFVKLiNGGA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qqgtU-00Gkkk-26; Wed, 11 Oct 2023 21:37:28 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qqgtR-00Gkk9-2g for linux-arm-kernel@lists.infradead.org; Wed, 11 Oct 2023 21:37:27 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5a7dac80595so4845827b3.0 for ; Wed, 11 Oct 2023 14:37:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697060243; x=1697665043; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=bdhtumD96yS+0S1renjDPDHQ2oQXBATflGNogyMiPxo=; b=qZ9Ti7IpgyD007u61Dh5/5hdb0no2wmULsc/Y2K3OoOYUpeeontVPFDL0FIk8z9Rz0 U6zLEK99ljdxN0MAk+Mn+b9i7UkQWQek0EDyxlcoadIjVyeyRM3eu2G2rhnvF6pOIPi7 zyVhkMXfOx0el+R0rh8Re17GBo+Qtqz2VO84h6JF45ayqD6SxDJ/NvVmQQScS6cZXAFt 28lpcgX1hiloVluzkRChI5le4UzObT5z89omRirWvnO/LFCv3N1og7U2Aahio8gaPHMr 1ymSQ+9k0jO0H7bcpA1w5ZUTnDwZ5BUOa18pD/l1BYx8fpexqOOxDi26hxajl6guA51r J0vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697060243; x=1697665043; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=bdhtumD96yS+0S1renjDPDHQ2oQXBATflGNogyMiPxo=; b=LlvXnpLsvawcyFwfsp0aVEfmHyj7+1hDHFYKc098R15/7Wj+9azQp8286C/509C+RM Nidp5AIVOt17UBJhFdePfsvHobDMvijfveRy2R4NJhzrcWxX0Bd/ImbCCZi/qEdtBm1p ZPXZznjBS12yP3UWh7wYr3F226DdCae+N0JX25lhasSoOamnvIkjSIpoW/OhkEssNdP9 Az1S69v320/Shs4POGatturMz4RwiBgCa4gu1efpsEcVF06vFrAKwj7yGubmppcXA6Ho CMK24ahsTbjMsUgxLJWLg7JvuPiCdWfDSzwH6qLohJ1fUCd+eq/rKJ/3zOFPYuyO6h/z NlTA== X-Gm-Message-State: AOJu0Yzh771wPaGGNz/w+alUgG/7IDih8uj2AIjxUUnQ8f+c5WNA46Uk 8qahnQJECpDGd3EhQtHuNukE9CGB5dSoXPVoFA== X-Google-Smtp-Source: AGHT+IHDNvnEYdVeA7aq+enyxmGfB/h9i6Fu3pciabl/8PXY/oPHdAuzxhC6COR8jt65lRiN26z1YArFR414iovQng== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:4056:0:b0:d9a:4f4c:961b with SMTP id n83-20020a254056000000b00d9a4f4c961bmr131018yba.1.1697060243280; Wed, 11 Oct 2023 14:37:23 -0700 (PDT) Date: Wed, 11 Oct 2023 21:37:18 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAI0VJ2UC/y2OUQrCQAxEr1LybaDbarVeRURqmroB3V2SpVRK7 +4qfs08eDCzgrEKG5yrFZRnMYmhgNtVQH4ID0YZC0NTN62rnUPLGii9cVSZWQ0DZ+TsWb/lJaS RvCS0NOhy+MetCDnGJxIe+/bUd+O9o2kPZSQpT7L8Dlyu2/YBrl/wDZAAAAA= X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1697060242; l=1738; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=s+mTiltMqX7As4CbGqq/2I96f5ZlgOW3Hq371eE6U+A=; b=ortN8RXCgeBg2EiOfufpEEBmLQpe8xksMJsaC4JoTO2illgEiCNaRXqc2GNe2S/2gmaFOFSuc i++d+IVn74jAvc5kUy5AXBSjvAe9ZIm7qtF4OH5athk1nrp+QrRszKS X-Mailer: b4 0.12.3 Message-ID: <20231011-strncpy-drivers-net-ethernet-microchip-sparx5-sparx5_ethtool-c-v1-1-410953d07f42@google.com> Subject: [PATCH] net: sparx5: replace deprecated strncpy with ethtool_sprintf From: Justin Stitt To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Lars Povlsen , Steen Hegelund , Daniel Machon , UNGLinuxDriver@microchip.com Cc: netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Justin Stitt X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231011_143725_892559_AF438C42 X-CRM114-Status: UNSURE ( 9.56 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org strncpy() is deprecated for use on NUL-terminated destination strings [1] and as such we should prefer more robust and less ambiguous string interfaces. ethtool_sprintf() is designed specifically for get_strings() usage. Let's replace strncpy() in favor of this more robust and easier to understand interface. Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2] Link: https://github.com/KSPP/linux/issues/90 Cc: linux-hardening@vger.kernel.org Signed-off-by: Justin Stitt Reviewed-by: Kees Cook --- Note: build-tested only. Found with: $ rg "strncpy\(" --- drivers/net/ethernet/microchip/sparx5/sparx5_ethtool.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) --- base-commit: cbf3a2cb156a2c911d8f38d8247814b4c07f49a2 change-id: 20231011-strncpy-drivers-net-ethernet-microchip-sparx5-sparx5_ethtool-c-793896db6cf4 Best regards, -- Justin Stitt diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_ethtool.c b/drivers/net/ethernet/microchip/sparx5/sparx5_ethtool.c index 01f3a3a41cdb..37d2584b48a7 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_ethtool.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_ethtool.c @@ -1012,8 +1012,7 @@ static void sparx5_get_sset_strings(struct net_device *ndev, u32 sset, u8 *data) return; for (idx = 0; idx < sparx5->num_ethtool_stats; idx++) - strncpy(data + idx * ETH_GSTRING_LEN, - sparx5->stats_layout[idx], ETH_GSTRING_LEN); + ethtool_sprintf(&data, "%s", sparx5->stats_layout[idx]); } static void sparx5_get_sset_data(struct net_device *ndev,