From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3AAF1CDB465 for ; Sat, 14 Oct 2023 16:31:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233278AbjJNQbb (ORCPT ); Sat, 14 Oct 2023 12:31:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233230AbjJNQb3 (ORCPT ); Sat, 14 Oct 2023 12:31:29 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9135FB7; Sat, 14 Oct 2023 09:31:28 -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=THW6nJ2E4AHZv1MDVtsblWf1vbWublGZsqD9188DwRQ=; b=2M5x3pC1mi007B7pI4y7wNG/un A1lastkRpMyrGbf3qUyYHJTvyTclWO0y1uI+gDzqvhwxHe/1GML/NHgwZXFSz22Uy+jtlymWPRuXn EoLmFOnO4bPYCIbab1hOci/DMstEoEvC3nhLI4SEK08YRYRvdzgVR94u2pvwQcyH34Fg=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1qrhXo-002Bdy-5p; Sat, 14 Oct 2023 18:31:16 +0200 Date: Sat, 14 Oct 2023 18:31:16 +0200 From: Andrew Lunn To: Justin Stitt Cc: Jiawen Wu , Mengyuan Lou , "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: txgbe: replace deprecated strncpy with strscpy Message-ID: <1c0e94ff-617b-4672-addb-8933f92edc29@lunn.ch> References: <20231012-strncpy-drivers-net-ethernet-wangxun-txgbe-txgbe_main-c-v1-1-c9bb3270ac98@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231012-strncpy-drivers-net-ethernet-wangxun-txgbe-txgbe_main-c-v1-1-c9bb3270ac98@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 12, 2023 at 09:20:04PM +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. > > Based on usage part_str usage within txgbe_read_pba_string(), we expect > part_str to be NUL-terminated but not necessarily NUL-padded: > | /* put a null character on the end of our string */ > | pba_num[10] = '\0'; > > Interestingly, part_str is not used after txgbe_read_pba_string(): > | ... > | err = txgbe_read_pba_string(wx, part_str, TXGBE_PBANUM_LENGTH); > | if (err) > | strscpy(part_str, "Unknown", sizeof(part_str)); > | > | netif_info(wx, probe, netdev, "%pM\n", netdev->dev_addr); > | > | return 0; > | > |err_remove_phy: > | txgbe_remove_phy(txgbe); > |err_release_hw: > | wx_clear_interrupt_scheme(wx); > | wx_control_hw(wx, false); > |err_free_mac_table: > | kfree(wx->mac_table); > |err_pci_release_regions: > | pci_release_selected_regions(pdev, > | pci_select_bars(pdev, IORESOURCE_MEM)); > |err_pci_disable_dev: > | pci_disable_device(pdev); > | return err; > |} > ... this means this strncpy (or now strscpy) is probably useless. For > now, let's make the swap to strscpy() as I am not sure if this is truly > dead code or not. Hi Julian I agree, this looks like dead code. Jiawen, please could you submit a patch cleaning this up. Either swap to strscpy() and make use of the string, or delete it all. Andrew --- pw-bot: cr