Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp447974rdg; Tue, 10 Oct 2023 15:36:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGdQCJfsQvgph6PA8KJGUlFNu5zyih9EYM6YV4S1zfEwjdjPDRa4AkeRra8RIKiqC43XfNI X-Received: by 2002:a05:6358:278c:b0:143:8084:e625 with SMTP id l12-20020a056358278c00b001438084e625mr20688768rwb.11.1696977380573; Tue, 10 Oct 2023 15:36:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696977380; cv=none; d=google.com; s=arc-20160816; b=Vh3AC6w679BzVpIHiXjEv6NL1sh3eLqD5Tg3smRUHmpaWwr+KhvXv/fa8OcDRjJnie ZkPLfea9tWrxk54w1WlxEtvIxZSbWDR3Nheq+NVMl0AhvJVHCf2MU4pDIp5GWKFg5DFi ErC6N7y9fxA/FcQb1o9lL0a3H4xV9DUNIbEShMw0djGLt6CP6YY2g4yh0fqRvkUok1Jb WNcuY2cJ+lVh1uPdHb7OklSyZ3ZBvgdLbO4rD2YUj2IKCCpCzBDsvwTUXNcDqLi1qg4J zdnaFevlBISnQSscBNXabUtDtHlWJ3zmpntr1BMS2z2OSyfwPmJwyaLFmYslLdbgNY8v NXKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=LbnEdKq2z/F673J0PyLo1dcLzZBfT0ZL+5O9D0Q9H3k=; fh=9y4adKj9IXY1LzIPcT6xX3vgN/R4hMpwmgEa5U8HlkU=; b=imtkv1VeCQYTIikbxIzUtvjv1RbWwfO0fueZZfes8SK3naKE0vKEbJ/suek79Oau9x PSpVsJJ0nkvElGXzODov9PZXNXIjVwJDAg4l2/FIhdVicyLgaczxfKkoy4AAfeOKvWqU ZxeQStDZP1JaiBKTJEE2bWk1ZNBLgOPnkQpxqc+fLyMOvmuEyqHv8Pb416xTQe5DssWI Q67S4WbMv3SBmjccoGCplswZLyuMkOWb4Qb7Vby9Cavc1twvVk/uZtUiHDGTC+oPReC3 NqNQvQwDM+WQBJPq74TE7W3jT1cqB4Qlc3etYd7aUcDYqL28EkD0MAWNQsNpB0v+ltwI Ixbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=b5VghDhb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id lp15-20020a17090b4a8f00b0027756e1f0c2si10354561pjb.7.2023.10.10.15.36.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:36:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=b5VghDhb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 549D4809188C; Tue, 10 Oct 2023 15:35:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229769AbjJJWfe (ORCPT + 99 others); Tue, 10 Oct 2023 18:35:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229577AbjJJWfc (ORCPT ); Tue, 10 Oct 2023 18:35:32 -0400 Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51C6498 for ; Tue, 10 Oct 2023 15:35:30 -0700 (PDT) Received: by mail-io1-xd2d.google.com with SMTP id ca18e2360f4ac-79fe6da0049so256842339f.1 for ; Tue, 10 Oct 2023 15:35:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696977329; x=1697582129; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=LbnEdKq2z/F673J0PyLo1dcLzZBfT0ZL+5O9D0Q9H3k=; b=b5VghDhb2Ysz4Ub07PijViWG/KRXCZFORn0pshqvZqNxUZKfNK6QAx8789LgeNPJMZ OAON8/chzN7eWxghmbPNC6uyoD4C5YYX3wzgtqBzqUXkfqvdBg7GPHi+fljDRkWMx5w/ x4S32AT4ySLuYKHGy0d7/fC5g/iWCsIO0N5CYYfcNUU2MbIYBik7m+cJIl8uh8T9SWe9 CfQJIjTOIYII4mVu7db8q0goVVb+S9wlC1LfUEk5q7b7T+lbYXo96MfQcM/jmx8sC2+q CQagDUc7k05icWWrGt6wDWsneYg1O6MyGGAOiuS1aUmWtjSt8RqsdzNVFP/6NrBMdCte IJ/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696977329; x=1697582129; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=LbnEdKq2z/F673J0PyLo1dcLzZBfT0ZL+5O9D0Q9H3k=; b=uf7kFwK6Iu41AI1pX8hZuQPWQGlWtvlwBtn3l37SO7b5hPtj2+KjexTz0mAcPE6tIy Jo1s2EPxD2XXVNqPg1nEJcRLdqEPZDJobeszmQICudpfytF9VFlFxQ9Aj0/ZdiBo4aN2 Exe5PeGLhV0Ju1kG1/JoaBD5U+OZxVXdagmfsUjV5OnyWLC7GNPi8CEn+qUeeXx2SGCa 3ig+rZDx42oT9RRzwrZs2nDnhLxLZg+nuPbDDuLy86dvEFxBznocwAvTMqD0a91NxHli BZsdeZ+mLf7C2GmYMXQRvJ+1TLEDC5eIU0AIJpE+VVa5g95oO6gWSp0c0zpMeEK3/v1G kVdg== X-Gm-Message-State: AOJu0Yzlnm1wueDsCBHLCPRVbkHitMpwcLU2CN/mJXhqjEWu42tW/LpV jHhKlx1s5zVC1S14qCOMsrOr5A== X-Received: by 2002:a6b:6f09:0:b0:790:a073:f122 with SMTP id k9-20020a6b6f09000000b00790a073f122mr19043765ioc.2.1696977329595; Tue, 10 Oct 2023 15:35:29 -0700 (PDT) Received: from google.com (161.74.123.34.bc.googleusercontent.com. [34.123.74.161]) by smtp.gmail.com with ESMTPSA id q21-20020a02a315000000b0042b2df337ccsm2907113jai.76.2023.10.10.15.35.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:35:28 -0700 (PDT) Date: Tue, 10 Oct 2023 22:35:26 +0000 From: Justin Stitt To: Jesse Brandeburg , Tony Nguyen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] e100: replace deprecated strncpy with strscpy Message-ID: <20231010223526.2qc4q64txfoi64lq@google.com> References: <20231009-strncpy-drivers-net-ethernet-intel-e100-c-v1-1-ca0ff96868a3@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231009-strncpy-drivers-net-ethernet-intel-e100-c-v1-1-ca0ff96868a3@google.com> 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 howler.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 (howler.vger.email [0.0.0.0]); Tue, 10 Oct 2023 15:35:59 -0700 (PDT) On Mon, Oct 09, 2023 at 11:41:01PM +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. > > 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 > --- > 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); > > --- > base-commit: cbf3a2cb156a2c911d8f38d8247814b4c07f49a2 > change-id: 20231009-strncpy-drivers-net-ethernet-intel-e100-c-4547179d9f2c > > Best regards, > -- > Justin Stitt > Hi, this patch was bundled up with some others. It has a new home: https://lore.kernel.org/all/20231010-netdev-replace-strncpy-resend-as-series-v1-0-caf9f0f2f021@google.com/