Message ID | 20231010-netdev-replace-strncpy-resend-as-series-v1-2-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 ib8csp172095vqb; Tue, 10 Oct 2023 15:28:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFqF4p5/WH0hSNVKKQa4hDr8Tcvxpadjc3/ZS5a2FUmek8QeaIdYFduWINCpBTPk4Y/is2E X-Received: by 2002:a05:6a20:43a6:b0:16c:b514:a4bc with SMTP id i38-20020a056a2043a600b0016cb514a4bcmr12951239pzl.4.1696976896801; Tue, 10 Oct 2023 15:28:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696976896; cv=none; d=google.com; s=arc-20160816; b=D5septpSaVxDlPPL0mVEU3QkvE3f6nJaCkDNzuc4OGQnco863GthF3ELqzp/vpSClX HPQpt5QPc1zK5NN5LfnL6YkLeaXHrxhssE9LBl+qVACP8nntWIfUOkLugRrwdrqwFNBu mPH9heW9XEO8Ufonov9eFsnpl63PXasJM9mKmPBRyHM1UPz4bWaCOfBrvSkacDgEb1+K /t9eiHF6T3azMAITYxjrUaVZQvFP9ubDELmvguC3PtEEtJIN4YzVOEoqSsER+fbtG9ng ZCSO19y9q7thvLyiZEfPXa15ExcWYt0BbuW7jFPhHuLnYMCctVp3O8eAFMaKq/L7yHD+ PoeA== 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=pa7deZDH3/y1FuC+NXYPP7L7Yz4eW2ecVvy54MDyytM=; fh=jBrXfr1CofwHzdCs7t+hNw/6P+fbZjn/vMCgpWmT8zI=; b=JgGgr9WY3qo4AAs3jsyPfLtMb54qByBWqYQCf4t9u5ViBmByZ6bypDb7anyxAPmwVc NLsEP7AraOyuc8jddfX6yiMrvVytEODiaDCFvEWD6ImBXHJ1fdLcJkANCY3mEh3YYSsR dYyJtdXWRgV47q/fHg7bCQh43JySI8cvOu5xfQI3o/SqLpc3UPfIAWNpLVr/rSaQNQ+z QsggRxZ48m3NHQoeJjR8x2EopHmCRDxe2GwSKITUZ3gAqXwtFC48jeTV/Yih/vSmo/em DNjSgIlWJvcRquwU0pTifd/w5/MeJ2p6GT4sbmve8abmwN9/h3zRakGzxF6GSe92w5+R aZSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=dNtSoZG1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id e3-20020a17090301c300b001c9b6735417si2300718plh.398.2023.10.10.15.28.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:28:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=dNtSoZG1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 399B6831D2FB; Tue, 10 Oct 2023 15:28:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234754AbjJJW1n (ORCPT <rfc822;rua109.linux@gmail.com> + 19 others); Tue, 10 Oct 2023 18:27:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234654AbjJJW1L (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 10 Oct 2023 18:27:11 -0400 Received: from mail-oa1-x4a.google.com (mail-oa1-x4a.google.com [IPv6:2001:4860:4864:20::4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F14DB109 for <linux-kernel@vger.kernel.org>; Tue, 10 Oct 2023 15:27:08 -0700 (PDT) Received: by mail-oa1-x4a.google.com with SMTP id 586e51a60fabf-1dd51b98342so9239359fac.3 for <linux-kernel@vger.kernel.org>; Tue, 10 Oct 2023 15:27:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696976828; x=1697581628; 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=pa7deZDH3/y1FuC+NXYPP7L7Yz4eW2ecVvy54MDyytM=; b=dNtSoZG14IAbsxG+bS1SasW0twm/JezTe1SxCulaRIoCL7PfsbgwPfV1ZcT+Uwc5gB fZ9DJf0tnuni4fFF1TI+EOZcopc9nBjpGpwdEFb4rZ/n9UkL9qjp0sl+dRA3haXjuUZ5 +w8EOorgTHr0Gzyojdkrf1JbRHoWKtt0sQ58YPliIHwzZIhGecNutR6SF+NgbjPhqCkq qNAoDCCQtpVVRXx3nGnAJEffH7f6xf0aYbTyotbXE3m8jfeWWYWLUf8y8d0Kga60gTnO tPWK68jU23eRmgsavQ9SKSpTMslsMCN+37MQrefGA4QDRM9oX026F3eDwjXeoSvYzrHb SfkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696976828; x=1697581628; 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=pa7deZDH3/y1FuC+NXYPP7L7Yz4eW2ecVvy54MDyytM=; b=Zx/FtSaAEmuqp0uU/ml1Qjh5vW71xut/YN5cOn6EqwRqSm2nZJTgxUG7AIrBHhV2tX KGXrO/YZ65dhtt/oaoKj3nLx2dKqz6uOqsUKR56g23NGN5Wq3qxcBZ2LQb2d/5P4hw81 R9DlP89nzguD1DAWHKTy3Z3lqLzrhpc8e6Cy/6LqaBiKgYdRd7ibRlkpppan8u21TjeS C1iDiB7ciFYORL6uAyrl1HrNHowFgBjn8xYqJAxgPuSFDm0GfPfwBPRKY7ovUHWYbfdF 2q/NHbG1tlMVIYVD0YSHTs4yZQ6fTbjVQ/bTmWKCzcCRbByzmn2lZLxZ/qiI+GkJUCqn Kmpg== X-Gm-Message-State: AOJu0YxIzKKLiE0TaAec1IZ1PeT7q1fly/uHS0g7EXqHpy5cXCNHCgm0 y5ZTZAmnvThkshGxnBhvNEC91OiPp2BdaNLLWQ== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a05:6870:b7b5:b0:1dd:7381:e05 with SMTP id ed53-20020a056870b7b500b001dd73810e05mr8328180oab.3.1696976828369; Tue, 10 Oct 2023 15:27:08 -0700 (PDT) Date: Tue, 10 Oct 2023 22:26:55 +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=1965; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=rxi6aLNd8v6Nf40hnmQomEOrEb/86fYL7CHbZkLYeOc=; b=j6JQnwbowPf3dzuBaUDjGqeCKA2qyFTP3KIo3eNBNMZczwWVdcd3sWaiujAjoY1XHmfpZr4MB wYA0z04z+jOBph3+HO6oqCmF+03nCsxlBi/fNo6z+SwJCX6k5QcwpK9 X-Mailer: b4 0.12.3 Message-ID: <20231010-netdev-replace-strncpy-resend-as-series-v1-2-caf9f0f2f021@google.com> Subject: [PATCH v1 net-next 2/7] e1000: 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 morse.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 (morse.vger.email [0.0.0.0]); Tue, 10 Oct 2023 15:28:14 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779409246555775421 X-GMAIL-MSGID: 1779409246555775421 |
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.
We can see that netdev->name is expected to be NUL-terminated based on
it's usage with format strings:
| pr_info("%s NIC Link is Down\n",
| netdev->name);
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/e1000/e1000_main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/intel/e1000/e1000_main.c b/drivers/net/ethernet/intel/e1000/e1000_main.c index da6e303ad99b..1d1e93686af2 100644 --- a/drivers/net/ethernet/intel/e1000/e1000_main.c +++ b/drivers/net/ethernet/intel/e1000/e1000_main.c @@ -1014,7 +1014,7 @@ static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent) netdev->watchdog_timeo = 5 * HZ; netif_napi_add(netdev, &adapter->napi, e1000_clean); - strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); + strscpy(netdev->name, pci_name(pdev), sizeof(netdev->name)); adapter->bd_number = cards_found;