Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2074865rdb; Mon, 9 Oct 2023 11:35:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFALPwInXtbqsIqPN8eWjT4zrG/3rQpSUEoGbQTRltw035NIT2O5OV9w5z0h6wemij6MXmN X-Received: by 2002:a05:6a21:3381:b0:16b:c20d:f979 with SMTP id yy1-20020a056a21338100b0016bc20df979mr12447066pzb.13.1696876546272; Mon, 09 Oct 2023 11:35:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696876546; cv=none; d=google.com; s=arc-20160816; b=BOC48yKCIvkmyYGs1FLMo7gdiUlo/ve54w59vPUqHlrpp0gLEJdlCMqZpU737oHhz+ iKvZ/WXnWAXkd3QBEa7Aa0wfYND9oqsgfvm0O816Sx2OHEeEV34S0q7K3vQ6ZAeDf5do uxTt9h8zZLwAltwkyYlHSLtp4RmCAlOAwGcwYD5Gtr1T+b+7vw8+msRkDUGkNk9avAEO wIKLnvCXSMxG1bQlmWhmEEv3qVBGq6XaPVqZqiF3UinbmX+Cm21uQULhTjXDzVhg+D+a hZJcYIihcVGHtkZbQeQc6y8jkcnbU/aRmlItoGBAvHJlt7XuopUB9X4lIAlK4XEHJAAJ 45oA== 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=QzW61PmvMhB7wvidR/JyZKEPGFGfKZhJxFsTC+Jw3gA=; fh=FsCqQPf0UdRo3SFKLGZflMv7iiUs0vvPVOExuhGSP00=; b=myVuqMRZu8mSyDUhUJp1nMal6PJ8mv1IyikgALHlNX5YERZXMplpK9QbNdp55gytD1 XaMFGYgUgp7kxXnf6FbL2FKDe/3TQO9MZ9GOnwy1T0QpJ/IoZ3rRdtVfm2Qd8lryRgaj S6Pv6H9klyqcCRyVnn7G31TZxJ45RjFfDrNWF6oW32B2EXc2h4UYTil1SpYlqxqJnzN1 fhHDUtk9fHwfyZwauPtfPnkPCqAA6VJZXJtUy89tw1P6HhOiK89+RSMWdkz5t244ah+j t3E4F229jlx1Z8Rl0Oe/ixUKSYBJceP+RaP6TUiTstdYDLc6Mo0tFp6z6pfUIH8e01jy 1hcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=DvQnqtbl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id q22-20020a656856000000b00563fe2c1163si10566325pgt.168.2023.10.09.11.35.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 11:35:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=DvQnqtbl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 397AE809D44E; Mon, 9 Oct 2023 11:35:25 -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 S1378245AbjJISey (ORCPT + 99 others); Mon, 9 Oct 2023 14:34:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378183AbjJISep (ORCPT ); Mon, 9 Oct 2023 14:34:45 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 015BC121 for ; Mon, 9 Oct 2023 11:34:30 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1c61bde0b4bso41226525ad.3 for ; Mon, 09 Oct 2023 11:34:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696876469; x=1697481269; 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=QzW61PmvMhB7wvidR/JyZKEPGFGfKZhJxFsTC+Jw3gA=; b=DvQnqtblCV35+DnVSWHtzRv1KZkI8ZK/i6++M8AnWOeeiYsk4hz60iI31+cMiRzXt7 HBvfkNLiI2qg1dWv2Q+jAqY+PfSvuFE+qiP9wS1BJWQBM5eVOBweX7KjU9ucGKso4BKU pZ8fBQF9Vogq2kHkVmiZXrN8ZfHBA4xn/r7KQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696876469; x=1697481269; 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=QzW61PmvMhB7wvidR/JyZKEPGFGfKZhJxFsTC+Jw3gA=; b=biHGcBqoVrQpEFxCUoZXkvU6wKlCTAXDQhVh4HJIbzWPjdLpumaaJhEtA52aq7zIfj 4mWn0tIMjablULih130sF3vFUUgIPIci9dZOC1MF6p82ZYsavmDEC6bEzvA5cNGgfBL+ ciomX6j0r0CWm2DjSO8ioc6DbQ9YT3cEPL7zC4mCi8PJrAweZs0qcXzAxDWwj8UKMRCH hyLa+aH58Nkrv53tMrS3LTycV3NMcwwG7/HxZmy835pMqmenCYMTRUu9IUJMDcqPSjVn RdVMold+cLEAAopa8oQqhez0fspeZ6neKEUwwuFzO2RXcaMRnVywyXhbQB2hHwfcY8nl 8t2g== X-Gm-Message-State: AOJu0YyTpdMmDpfrVtoPA4D/vPnixddf/RZ+S5FpkOoCnqV7yBkWNNVD 4NX3crCtI/vmboG3ZAJRFctZSw== X-Received: by 2002:a17:903:2589:b0:1c7:2347:7777 with SMTP id jb9-20020a170903258900b001c723477777mr14962150plb.11.1696876469423; Mon, 09 Oct 2023 11:34:29 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id y5-20020a170902ed4500b001c78446d65fsm9980460plb.113.2023.10.09.11.34.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 11:34:28 -0700 (PDT) Date: Mon, 9 Oct 2023 11:34:27 -0700 From: Kees Cook To: Justin Stitt Cc: Hauke Mehrtens , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "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: dsa: lantiq_gswip: replace deprecated strncpy with ethtool_sprintf Message-ID: <202310091134.67A4236E@keescook> References: <20231009-strncpy-drivers-net-dsa-lantiq_gswip-c-v1-1-d55a986a14cc@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231009-strncpy-drivers-net-dsa-lantiq_gswip-c-v1-1-d55a986a14cc@google.com> X-Spam-Status: No, score=2.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS 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: 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]); Mon, 09 Oct 2023 11:35:25 -0700 (PDT) X-Spam-Level: ** On Mon, Oct 09, 2023 at 06:24:20PM +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. > > ethtool_sprintf() is designed specifically for get_strings() usage. > Let's replace strncpy in favor of this more robust and easier to > understand interface. > > 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/dsa/lantiq_gswip.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/net/dsa/lantiq_gswip.c b/drivers/net/dsa/lantiq_gswip.c > index 3c76a1a14aee..d60bc2e37701 100644 > --- a/drivers/net/dsa/lantiq_gswip.c > +++ b/drivers/net/dsa/lantiq_gswip.c > @@ -1759,8 +1759,7 @@ static void gswip_get_strings(struct dsa_switch *ds, int port, u32 stringset, > return; > > for (i = 0; i < ARRAY_SIZE(gswip_rmon_cnt); i++) > - strncpy(data + i * ETH_GSTRING_LEN, gswip_rmon_cnt[i].name, > - ETH_GSTRING_LEN); > + ethtool_sprintf(&data, "%s", gswip_rmon_cnt[i].name); Sorry, I read too fast: this should be "data", not "&data", yeah? -Kees > } > > static u32 gswip_bcm_ram_entry_read(struct gswip_priv *priv, u32 table, > > --- > base-commit: cbf3a2cb156a2c911d8f38d8247814b4c07f49a2 > change-id: 20231005-strncpy-drivers-net-dsa-lantiq_gswip-c-ece909a364f7 > > Best regards, > -- > Justin Stitt > > -- Kees Cook