Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1625208rdg; Sat, 14 Oct 2023 09:31:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE/gy7Fe0YR/cunbG1GuG6eJmvjvUqXdctMhEKFzLe1Xsh+IuJXcDSa3kxS0eU6458qfcbn X-Received: by 2002:a05:6a20:5512:b0:14d:d9f8:83ee with SMTP id ko18-20020a056a20551200b0014dd9f883eemr26747058pzb.61.1697301105365; Sat, 14 Oct 2023 09:31:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697301105; cv=none; d=google.com; s=arc-20160816; b=OtCBtbIooqAI1oO+GK5gRt3Y3E0ywJd6lXAQAJGhsbTf7T5t27dTSPybNHg7mzu6GT 8n2v/0qtW5rtO4hJThWnfxHN5ipx089fbIq5dqlgezNuiYrBP9PetMP/EXZe7gfKjGBp II1Q7q5BIU23ZRJYRwwCSl/izEqJiHmE1hDosfiNgg6YGUHT5qh3NQUepTdcJmUqTPYi 0V9rbR+x9HCYf67asE5u37k+QIwyD9XFFa2/2P6h9Uv1QljYoDj4h9ZlcN/13avSaypp Jf5noKGMkdO9xPjHk4WRtqycwxqe1M3ixw5CjN82fPsPdS97rV4aUDS4PEMOXDQNk2jU EPfw== 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=m+eYhnlsWW3tRR7KfXjnN2nxeoc3/iQb0fw4Feji7t0=; fh=YTomHt3TDNdusqbDoTLIA25BCpJ5Jgaq5sT/Yscdx+4=; b=RHlC3hBMy0VFXl/+YrPJ61ev6a0Joiu2ZX+4gKjpGzN4qiE+9mnJHMiIYei0ZCrzNC xGeNUnWPdFfRckGeXo5Pjn6mnk6fQIBE/bdpZi8O58/RDOvJm8luizvqFedJvQUE/3TK skqpy0oOX83GO17S06svv7ZwX5AXBWMLFidilXTus62wpHFnWvrzLJ3PE6sxUmNeVLcG Y0Obshfpq9Qh/bJfW/KeoM9Z/iVDJzRW+zRHXU+Kxf1w8vwI58B1Le2D6bp8o7mcDTqB dfgJ3OQcjC6oD+r2xI6e4vtNauhOtvrVz/VpeTU9kwA3Hmx+LKABwGYa107cLyFeX8pS fgcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b=xj1yq9Iz; 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=NONE sp=NONE dis=NONE) header.from=lunn.ch Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id h3-20020a170902f54300b001ca0b64f5a6si3605341plf.449.2023.10.14.09.31.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Oct 2023 09:31:45 -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=@lunn.ch header.s=20171124 header.b=xj1yq9Iz; 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=NONE sp=NONE dis=NONE) header.from=lunn.ch Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 4796E80401C2; Sat, 14 Oct 2023 09:31:42 -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 S233033AbjJNQ0y (ORCPT + 99 others); Sat, 14 Oct 2023 12:26:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233235AbjJNQ0x (ORCPT ); Sat, 14 Oct 2023 12:26:53 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 706BFAB; Sat, 14 Oct 2023 09:26:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Disposition:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:From:Sender:Reply-To:Subject: Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=m+eYhnlsWW3tRR7KfXjnN2nxeoc3/iQb0fw4Feji7t0=; b=xj1yq9Iznwrt6gJL/rfxOyAXUJ BfGAiOO/IIyn/IEY+Opgpqtevmu3V+0NJtECPFSJOTB7sdHtXLPYofuI7OAP/atfXO/wPX31WZxAO wJHmu4/qYrXx9QPk0NvwnOk0N1Szwsyi8NurihsKO6+Yut3XYGENbefon/po0ZuBbnZ4=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1qrhTP-002BcC-5l; Sat, 14 Oct 2023 18:26:43 +0200 Date: Sat, 14 Oct 2023 18:26:43 +0200 From: Andrew Lunn To: Justin Stitt Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] net: netcp: replace deprecated strncpy with strscpy Message-ID: <327af7c3-3a5f-4c0c-b3f7-81ceef14226b@lunn.ch> References: <20231012-strncpy-drivers-net-ethernet-ti-netcp_ethss-c-v1-1-93142e620864@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231012-strncpy-drivers-net-ethernet-ti-netcp_ethss-c-v1-1-93142e620864@google.com> X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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: 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]); Sat, 14 Oct 2023 09:31:42 -0700 (PDT) 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 > --- > 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