Message ID | 20231010-netdev-replace-strncpy-resend-as-series-v1-1-caf9f0f2f021@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 ib8csp171970vqb; Tue, 10 Oct 2023 15:27:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFLeE/58AOLDO5WfYw0veUm4FsGs5NMr+NrNwldsSXy8aPEnqIeJb42Meh5tYiDNBFv4N4j X-Received: by 2002:a05:6a00:398c:b0:68a:6cbe:35a7 with SMTP id fi12-20020a056a00398c00b0068a6cbe35a7mr22142139pfb.2.1696976876191; Tue, 10 Oct 2023 15:27:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696976876; cv=none; d=google.com; s=arc-20160816; b=S7yub+hooGnaJbBH+5ud10rqqYCqgDlpjTlTkbaTfUZ/UA/akkF8Q4yfdmmdbRC0XR oUxbeYRRYQPA/Sceuug/8COEWH6L54bugvx6eX6hhq3rop5JwmNQzZoDINVuF8S64jXY gZaApFLBPV0V7dBthoxbnr9SmrK/TS0SVVYiT5QZanRxjyg4DYJ1izFpCt1guNnuDdVs Gp5sWvbcfj19PzG5H+uAw+etsF04EmvhLfykI/rEQPc6SsqyJSF2dRWjpiOxmbqwu/1M FbQNPiGjQiqhRMzy3Ps94A0T42B2v1StBM2y74ATRmXio+wy05jvpEXUzKNCnD61GDzq f44A== 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:references :mime-version:in-reply-to:date:dkim-signature; bh=oRxxfOpYGYsMYGCPD0LU0Gx9K2SMiFZ6T4X3/eq+2Jo=; fh=jBrXfr1CofwHzdCs7t+hNw/6P+fbZjn/vMCgpWmT8zI=; b=Pf7uGqaVPLw9zihssO6Sq957ZxoMuGz0QjAHjLH7C/SWW91lgRZ6emy/Vao0Tz3+CZ TcZuChAD/wHNTEOuySo7EqUj7NlgV8Hnka25tgDja1s97ZZq2bFr4bCOSN9Rshha2M7U TV8NdAmamI2fCTczKjU3qfZJKDt/5yawYFgHYA8eXqHgkJz4SnJD79JKg4nRaJM5ax9G 4qK+iJfCNemQ/NmrGwE+w+P6YF2ofiqkMH6jqo4fioLzy5aza7QmjPWJgrqNPs+T610R JDpXigtqIpAkjqm29xKd51wKlrrWKDTKQRuLhx/X5V8PJWLUFQGhXgOEGpqkDyiAzqqB JAnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=sCzWLzIf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id f15-20020a056a00238f00b0069100de2235si10863675pfc.187.2023.10.10.15.27.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:27:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=sCzWLzIf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 03C7C801C03C; Tue, 10 Oct 2023 15:27:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230034AbjJJW1V (ORCPT <rfc822;rua109.linux@gmail.com> + 19 others); Tue, 10 Oct 2023 18:27:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234457AbjJJW1L (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 10 Oct 2023 18:27:11 -0400 Received: from mail-oo1-xc49.google.com (mail-oo1-xc49.google.com [IPv6:2607:f8b0:4864:20::c49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E32FA100 for <linux-kernel@vger.kernel.org>; Tue, 10 Oct 2023 15:27:07 -0700 (PDT) Received: by mail-oo1-xc49.google.com with SMTP id 006d021491bc7-57b7aefb23aso7447780eaf.2 for <linux-kernel@vger.kernel.org>; Tue, 10 Oct 2023 15:27:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696976827; x=1697581627; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=oRxxfOpYGYsMYGCPD0LU0Gx9K2SMiFZ6T4X3/eq+2Jo=; b=sCzWLzIfbyvEdCcjd9shAkwt7hPStxK53ArHcfgnX2URuIOwrYvwkKjs2ENbrkKMM2 R/FnDR+TI05cGo+o/Vr1a1wo2ADkb0gieGjV3wViWVQQNRYjZbv38WDQyv8fHFzgG9o2 Ak07Pse+fp8trMmMT9gfKSH7ePXt+G6eftHgpJAX729MFyX1Wq9hz6tSl07LSAL42jy8 2VzkDd84qFrQxRktlAz3UO2Z2PxDfWyTnKSzuBmqt9L8SZc5SofmAGBYAkDYi9XZgUT/ 6uCPj8w54u7CHODVfb/e1b/BYT68Srycl6IzLMPF2q3bJMDOmELqdr6gziXZf4c+bko+ Xq4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696976827; x=1697581627; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oRxxfOpYGYsMYGCPD0LU0Gx9K2SMiFZ6T4X3/eq+2Jo=; b=RCjAOiNOtDav70BqWhNEyKHkT4eVpVLQH+kRkHu0C+bM5PEyexwn0UkdSGt22P+e3w uV3IjAD4lIoQO1CrgoFFVcq37bjG9R01PhEN3uO4yY3L1j1O5Ns3qOEGxx2m+Bof87Un fsdwqsjgnruSU/snpLHASgvS/CttZ+atfhFhqqXzIjUA+1/9OURgSx/9Y0242EC0y8cr zbXBdPZcs/+Cohp+Wj4Mte+clj+APp0e7cMot5XL2EjN0Amx1otcsFlmZ87ePurEP4yX qWCw7UElSUjJYJycgm2gDnDF+sAUYggeHy7w7X90YTXMKgkdV5HmE/cdtqM98O9qldn3 Uv1A== X-Gm-Message-State: AOJu0Yy4CuhfAd11yQgHkC58a0tyn8oeDBUIL7qWkco9J3FcNLBvhFrC 0zRmcCyLzJXQeTAC5acfnwqpq6ueIqToFD4Hzw== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a05:6870:9891:b0:1d6:5e45:3bc7 with SMTP id eg17-20020a056870989100b001d65e453bc7mr8002308oab.5.1696976826877; Tue, 10 Oct 2023 15:27:06 -0700 (PDT) Date: Tue, 10 Oct 2023 22:26:54 +0000 In-Reply-To: <20231010-netdev-replace-strncpy-resend-as-series-v1-0-caf9f0f2f021@google.com> Mime-Version: 1.0 References: <20231010-netdev-replace-strncpy-resend-as-series-v1-0-caf9f0f2f021@google.com> X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1696976824; l=2047; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=OWWhQIBafVgfDlqmMd0xlq6kW1ggHRaXB3P7V35piho=; b=VuwZhA1UAIYHpGKXaFjSv1uwbivUM+rFKhtVdtifrMMZE3YsgHH/o4bhCiH0jMRbuplw/zZ5l Sq50xVfC9K1BbFHqYK+Q9zMPrzpmcn1bglNfo7vqJwP60dNdZLWRsiu X-Mailer: b4 0.12.3 Message-ID: <20231010-netdev-replace-strncpy-resend-as-series-v1-1-caf9f0f2f021@google.com> Subject: [PATCH v1 net-next 1/7] e100: replace deprecated strncpy with strscpy From: Justin Stitt <justinstitt@google.com> To: Jesse Brandeburg <jesse.brandeburg@intel.com>, Tony Nguyen <anthony.l.nguyen@intel.com>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com> Cc: linux-hardening@vger.kernel.org, intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Justin Stitt <justinstitt@google.com> Content-Type: text/plain; charset="utf-8" X-Spam-Status: No, score=-4.8 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Tue, 10 Oct 2023 15:27:54 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779409224874947785 X-GMAIL-MSGID: 1779409224874947785 |
Series |
net: intel: replace deprecated strncpy uses
|
|
Commit Message
Justin Stitt
Oct. 10, 2023, 10:26 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.
The "...-1" pattern makes it evident that netdev->name is expected to be
NUL-terminated.
Meanwhile, it seems NUL-padding is not required due to alloc_etherdev
zero-allocating the buffer.
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.
This is in line with other uses of strscpy on netdev->name:
$ rg "strscpy\(netdev\->name.*pci.*"
drivers/net/ethernet/intel/e1000e/netdev.c
7455: strscpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
10839: strscpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
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.
---
drivers/net/ethernet/intel/e100.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/intel/e100.c b/drivers/net/ethernet/intel/e100.c index d3fdc290937f..01f0f12035ca 100644 --- a/drivers/net/ethernet/intel/e100.c +++ b/drivers/net/ethernet/intel/e100.c @@ -2841,7 +2841,7 @@ static int e100_probe(struct pci_dev *pdev, const struct pci_device_id *ent) netdev->netdev_ops = &e100_netdev_ops; netdev->ethtool_ops = &e100_ethtool_ops; netdev->watchdog_timeo = E100_WATCHDOG_PERIOD; - strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); + strscpy(netdev->name, pci_name(pdev), sizeof(netdev->name)); nic = netdev_priv(netdev); netif_napi_add_weight(netdev, &nic->napi, e100_poll, E100_NAPI_WEIGHT);