Message ID | 20231012-strncpy-drivers-net-ethernet-ti-netcp_ethss-c-v1-1-93142e620864@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1498510vqb; Thu, 12 Oct 2023 14:06:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFcvbk5L8q+RGcMMevSF9STi85WG8AGum/RMmIIU6wURkK5mkrcRfvh1VKxbd94l/Jn3g3g X-Received: by 2002:a17:902:e28b:b0:1c9:e48c:7260 with SMTP id o11-20020a170902e28b00b001c9e48c7260mr2194685plc.6.1697144760864; Thu, 12 Oct 2023 14:06:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697144760; cv=none; d=google.com; s=arc-20160816; b=ls5MApEquLSJT4DrKnhr1Ai/jhXU57QhxPHf3PzoI+nIubShzipSAN9g5sBnXXLTjP wZCcyCacz2OrbYTry1M6S/W6l3xHBH5VnP/qgWuZpc2bDLp+PlU2e3Lo95NSrirnFbdL 8CX8jsYIy8Mp+uAKEhc0S5AMt/DtoKkmOjpn/CT7TFEgIjbAZPRPeNg3QrntjhoqB5i0 IBZzEKq0eVjOwvypWwU9BwOkYBgkir/0j1P/gHoe40wtedJISKqik8hEDXck+AaxzOfV SpahGi7p8vo2NfpUQYfHgQmZIM71QrZ2aoxaAd7d2ZjSPiasqXVm0u3TjnKw9OtqTs0b wcQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=9oP1I5+6soWcUdUsGpPJJ1MkksTpN6au5vjlY6dm6ew=; fh=LHfPMpUMVAjX1GRqeBb2cvalpYllxfW1M8v2DYqSmME=; b=B/MfIRWdHsBdRSzOafv3wwHukpiTrCIZwjYE0Ko0DntvM14ZmsI3+nchRY9vbU28j9 vIJji22AtKw2owcWphUhjAl4EIntPFKollJUbp9gUh7wATa11SYgnCdWMF58KITCbD8u 5SAVTqGeDxqVd5z8CRa8EOuFpx49MHpST5L7S+4EkbPGNeRjh4Eu9JUcjBazmQD7nPPu Rtg14ejk6Cgrpp0rOxQE4HZNDgUZKtjNxdY0Zcoxf+oWRUyudxTTF9eJQFImrVjAfVPI 1lIR3+jT4qB7JWu041W+6rGMemEkPA6vXFPNVMEYnRCFUlXon3JPLvE/AinZ2fJqafTL VE0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=FL4WKoDf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id b13-20020a170902d50d00b001c73d73f163si3183298plg.505.2023.10.12.14.06.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 14:06:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=FL4WKoDf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id AD9C981A4FE7; Thu, 12 Oct 2023 14:05:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442643AbjJLVFp (ORCPT <rfc822;rua109.linux@gmail.com> + 19 others); Thu, 12 Oct 2023 17:05:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344156AbjJLVFn (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 12 Oct 2023 17:05:43 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2C6CA9 for <linux-kernel@vger.kernel.org>; Thu, 12 Oct 2023 14:05:41 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d86dac81f8fso1998067276.1 for <linux-kernel@vger.kernel.org>; Thu, 12 Oct 2023 14:05:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697144741; x=1697749541; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=9oP1I5+6soWcUdUsGpPJJ1MkksTpN6au5vjlY6dm6ew=; b=FL4WKoDfrNzUfF5xOsMB0jsP+qN7hxQ4Bn/JloeAIva4CPC5+7u8qttj2yP6lqCKN7 pRM6kM7gcArQWUleJWvgxSEBZgwy9oUAqIuaIsY/54xKKQFOc8WUp6f5Fo4qtzqfmyCV ko0pKKj8Z7PultN256DASij0HpWE5/ewhZkcrb88lVMQuwHLHJE9SKI1S52zGvh5V8Ce MN93sQ3ytzi1iMJwG04qV6n1PQPawcclrFYxtHlqiyVcVplhItx4uBOTY7nNNb3SM3PC etPmvSyK/sle7U2VABVYgeMCVBlMFE+epS+lyAMaklpT86JLAAea2ACovcZACkZANXbi IZIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697144741; x=1697749541; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=9oP1I5+6soWcUdUsGpPJJ1MkksTpN6au5vjlY6dm6ew=; b=jsrfzdlKZpoDwVnKY27enovccb2bphPrPZdMGTvEjGuZq11gGjg3Qsk3KkdD6Y7fDI S8m6YLi+g+0/iYXfQF8MlRLvCmPKb53zw56OV4E7HHczepY+XCfSafjPEpxBqLy9pE6A ziD7NqkWcMNdrzENeoiMYT/ZL57eWxB2/CFP7Qf8WwNyat1Pyz8VWemamXN5Cfj39bJp so4bRw1JLGK9HRXbLQPSeAAMVO0WClt4o446THzr1RS5EbQoEoX5Gpn0gjvuyFLju9SF 1c01JLHdK+qq3H9Ara+eRqjWlPXzPh4DNnmvIiMZYVmm8DneHE4Klaop4raf1JjahosT oOyA== X-Gm-Message-State: AOJu0YwDqLBlZV96wZ4SNztX7uBHkoCbgU/HXYfuLnQAKMK1z3jpFJ8P s4u+MbffncjUTp5cCsAHEpicJgxyKYymqzd2YQ== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a05:6902:4a9:b0:d9a:4c45:cfd0 with SMTP id r9-20020a05690204a900b00d9a4c45cfd0mr192649ybs.2.1697144741041; Thu, 12 Oct 2023 14:05:41 -0700 (PDT) Date: Thu, 12 Oct 2023 21:05:40 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAKNfKGUC/x3NzQqDQAwE4FeRnBvYH0Tpq5RSJEbNZV2SRSriu 7t6m28OMwcYq7DBuzlAeROTNVX4VwO0DGlmlLEaggvROx/QiibKO44qG6th4oJcFtY7FLlN+Vc bMySMrh3a2HeRJoK6mZUn+T9/n+95XhC8cMN/AAAA X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1697144739; l=2331; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=x/31VF0rLVNABMGyii39oVifDyB7uVtgS7xEolZ5yEo=; b=yfIEANn3f5HuZXL0PZLHgFcd1H8NeT0NZngBT+amfYdzZCLwoLOmXx7VYz2PwhUYgQ2e4arJx 4p9sHq8QdmSA/QPh6cM04BI9frRlWD0J/j144CQAbvbgCs+oa+XI86u X-Mailer: b4 0.12.3 Message-ID: <20231012-strncpy-drivers-net-ethernet-ti-netcp_ethss-c-v1-1-93142e620864@google.com> Subject: [PATCH] net: netcp: replace deprecated strncpy with strscpy From: Justin Stitt <justinstitt@google.com> To: "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com> Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Justin Stitt <justinstitt@google.com> Content-Type: text/plain; charset="utf-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 12 Oct 2023 14:05:56 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779585264818424625 X-GMAIL-MSGID: 1779585264818424625 |
Series |
net: netcp: replace deprecated strncpy with strscpy
|
|
Commit Message
Justin Stitt
Oct. 12, 2023, 9:05 p.m. UTC
strncpy() is deprecated for use on NUL-terminated destination strings
[1] and as such we should prefer more robust and less ambiguous string
interfaces.
Considering the above, a suitable replacement is `strscpy` [2] due to
the fact that it guarantees NUL-termination on the destination buffer
without unnecessarily NUL-padding.
Other implementations of .*get_drvinfo also use strscpy so this patch
brings keystone_get_drvinfo() in line as well:
igb/igb_ethtool.c +851
static void igb_get_drvinfo(struct net_device *netdev,
igbvf/ethtool.c
167:static void igbvf_get_drvinfo(struct net_device *netdev,
i40e/i40e_ethtool.c
1999:static void i40e_get_drvinfo(struct net_device *netdev,
e1000/e1000_ethtool.c
529:static void e1000_get_drvinfo(struct net_device *netdev,
ixgbevf/ethtool.c
211:static void ixgbevf_get_drvinfo(struct net_device *netdev,
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 <justinstitt@google.com>
---
Note: build-tested only.
Found with: $ rg "strncpy\("
---
drivers/net/ethernet/ti/netcp_ethss.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
---
base-commit: cbf3a2cb156a2c911d8f38d8247814b4c07f49a2
change-id: 20231012-strncpy-drivers-net-ethernet-ti-netcp_ethss-c-305a53873cfc
Best regards,
--
Justin Stitt <justinstitt@google.com>
Comments
On Thu, Oct 12, 2023 at 09:05:40PM +0000, Justin Stitt wrote: > strncpy() is deprecated for use on NUL-terminated destination strings > [1] and as such we should prefer more robust and less ambiguous string > interfaces. > > Considering the above, a suitable replacement is `strscpy` [2] due to > the fact that it guarantees NUL-termination on the destination buffer > without unnecessarily NUL-padding. > > Other implementations of .*get_drvinfo also use strscpy so this patch > brings keystone_get_drvinfo() in line as well: > > igb/igb_ethtool.c +851 > static void igb_get_drvinfo(struct net_device *netdev, > > igbvf/ethtool.c > 167:static void igbvf_get_drvinfo(struct net_device *netdev, > > i40e/i40e_ethtool.c > 1999:static void i40e_get_drvinfo(struct net_device *netdev, > > e1000/e1000_ethtool.c > 529:static void e1000_get_drvinfo(struct net_device *netdev, > > ixgbevf/ethtool.c > 211:static void ixgbevf_get_drvinfo(struct net_device *netdev, > > 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 <justinstitt@google.com> > --- > Note: build-tested only. > > Found with: $ rg "strncpy\(" > --- > drivers/net/ethernet/ti/netcp_ethss.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/net/ethernet/ti/netcp_ethss.c b/drivers/net/ethernet/ti/netcp_ethss.c > index 2adf82a32bf6..02cb6474f6dc 100644 > --- a/drivers/net/ethernet/ti/netcp_ethss.c > +++ b/drivers/net/ethernet/ti/netcp_ethss.c > @@ -1735,8 +1735,8 @@ static const struct netcp_ethtool_stat xgbe10_et_stats[] = { > static void keystone_get_drvinfo(struct net_device *ndev, > struct ethtool_drvinfo *info) > { > - strncpy(info->driver, NETCP_DRIVER_NAME, sizeof(info->driver)); > - strncpy(info->version, NETCP_DRIVER_VERSION, sizeof(info->version)); > + strscpy(info->driver, NETCP_DRIVER_NAME, sizeof(info->driver)); > + strscpy(info->version, NETCP_DRIVER_VERSION, sizeof(info->version)); > } Hi Justin We have been deprecating setting info->version in drivers, because it is mostly useless. The core now puts in the kernel git hash, which does actually represent something useful. So feel free to just remove it, rather than figure out if its safe to convert to strscpy. Reviewed-by: Andrew Lunn <andrew@lunn.ch> Andrew
Hello: This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <kuba@kernel.org>: On Thu, 12 Oct 2023 21:05:40 +0000 you wrote: > strncpy() is deprecated for use on NUL-terminated destination strings > [1] and as such we should prefer more robust and less ambiguous string > interfaces. > > Considering the above, a suitable replacement is `strscpy` [2] due to > the fact that it guarantees NUL-termination on the destination buffer > without unnecessarily NUL-padding. > > [...] Here is the summary with links: - net: netcp: replace deprecated strncpy with strscpy https://git.kernel.org/netdev/net-next/c/eb7fa2eb9689 You are awesome, thank you!
diff --git a/drivers/net/ethernet/ti/netcp_ethss.c b/drivers/net/ethernet/ti/netcp_ethss.c index 2adf82a32bf6..02cb6474f6dc 100644 --- a/drivers/net/ethernet/ti/netcp_ethss.c +++ b/drivers/net/ethernet/ti/netcp_ethss.c @@ -1735,8 +1735,8 @@ static const struct netcp_ethtool_stat xgbe10_et_stats[] = { static void keystone_get_drvinfo(struct net_device *ndev, struct ethtool_drvinfo *info) { - strncpy(info->driver, NETCP_DRIVER_NAME, sizeof(info->driver)); - strncpy(info->version, NETCP_DRIVER_VERSION, sizeof(info->version)); + strscpy(info->driver, NETCP_DRIVER_NAME, sizeof(info->driver)); + strscpy(info->version, NETCP_DRIVER_VERSION, sizeof(info->version)); } static u32 keystone_get_msglevel(struct net_device *ndev)