Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2073133rdb; Mon, 9 Oct 2023 11:32:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEOAyj+o9yk22QWKZE2dAwKNgWvoVpRTdbFk50MTIIAg7u/4/dR8+h6oHFHk6B0NEKV0IMf X-Received: by 2002:a17:903:25d4:b0:1c6:945:1427 with SMTP id jc20-20020a17090325d400b001c609451427mr11495330plb.11.1696876332923; Mon, 09 Oct 2023 11:32:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696876332; cv=none; d=google.com; s=arc-20160816; b=Ja70uuJgH4lZV7zvmF7ORDF/AFImmxUWcVX/KsJpnouHBVSmjwD4v6SLCghAkQxBkr rDsRQUNy6qBXV0ylLdS9nJw0rCOzjywPhhh+SIw642fjZ4ocGiFkOsai0u0ke6Grv5of hysBREZIE2yor1JB+ONKHMleRbByslZfj67IJe8hfVXKJaO5SHWX0AOpJeeM7KbHEZJ1 ZTsEUq/FyumeREaYzc2HT+e8fyiGvHRjxjaLjBDPUHMuSTJ4DRhQqqxD7piQoQLPx9WF xmvDt2L8MX6w00JLLjbL8qDzp1kl6XNdgkjGM7ru+/BXZyohlnT4SFN8cvZ8K5ZCsBwI Za4A== 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=KxOk0Qe6UPn44OvxWZwPSW3rRJkqXORiJb9E5OphMiQ=; fh=9jsy8AbJvGuLuRkVPwhOjX5rocIcnUak6lkzc/Cn27k=; b=lXlnV/MRMcVJBXnBiu9XMlUEVVj4pFISW4dGFRsCP31zv+i9K3X6vyJiCoyghFP3P5 4nRw8OqxYReioEYhyvEOYOLGpurLLKozxMK8szAotzqgH+y/9Yb6+rpmcQfJjJJfPgcZ BHq8Pg+CYHShmamSRNT3FO231i5BOCLZZpj2xWdYLEaC0V++hyHlDrZSVoM3U6JrOY9Z PgE4Ic9gHRQQggCWW7HKsLhPaclQwKzAVN0cGiA2NSaRmd2eQ4N/mTZ9ou9dlicISk1y szEClWWxK9/SCjiFp+XnvA18Dog0fMeYSJ1HzK3VW/5/ZEFnKAyBoQq/CvjE0zKljNlm K6iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="n/SIJ1/S"; 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 b7-20020a170903228700b001c1f1394bf9si10880613plh.357.2023.10.09.11.32.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 11:32:12 -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="n/SIJ1/S"; 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 64F968098424; Mon, 9 Oct 2023 11:32:10 -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 S1378049AbjJIScA (ORCPT + 99 others); Mon, 9 Oct 2023 14:32:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377501AbjJISb6 (ORCPT ); Mon, 9 Oct 2023 14:31:58 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5728E1 for ; Mon, 9 Oct 2023 11:31:49 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-692ada71d79so3663339b3a.1 for ; Mon, 09 Oct 2023 11:31:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696876309; x=1697481109; 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=KxOk0Qe6UPn44OvxWZwPSW3rRJkqXORiJb9E5OphMiQ=; b=n/SIJ1/StnZQ/Sekobp/ZBP8e7mbHRPqgRKZcEuCrTTrDwpzYLkFBLVxBKWuo9R0EC nmlxQdeSuXKXMf9PYDxBCJlM31//nzfzLdLP5IE/W///X0nFvnaWWef9CHnIRrOODrxX nnpNJUEfL64aHETUZeDvMQ0Wbc0frAJdmckKc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696876309; x=1697481109; 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=KxOk0Qe6UPn44OvxWZwPSW3rRJkqXORiJb9E5OphMiQ=; b=RhFVWRayqyweKqanF5WhpyH8EUbr5mFEmUUgTkfmoxo5bEORQ+GSlobXPEG9VPVwoO C4la8KKCudTxT1gWdY44qes5wOic+uFhWbS/3n2XQsZQBnyN4ZoyXCUaWj31U8S5odmY XZqw3H9BSfFyDdZnJxT4fY6KgQWgjcns5EKWPRKdCmMK/uFO2mueaxvWXtDI3Fz62D/O n/QmTjipPjWSL2OnoRl0cIG9wUfQHdCqbo6k/tSTWYbzNXkK5m2N/k1t6tkv7YXwbDoF 69qISOxBPbA+LWZKHdV14lnVo+EhB/TDT+wkvqwyiapQZudqWWI3NUPOFmRQoRRrZdYR 6MJw== X-Gm-Message-State: AOJu0YzU5ldPq4zg4/9HZZdfPNjLP8ufzMxU0T3SS26YNq2l+TnXvHom IC2drnCjTASBCm8v0DUDpoKP7w== X-Received: by 2002:a05:6a20:3d29:b0:15d:7e2a:cc77 with SMTP id y41-20020a056a203d2900b0015d7e2acc77mr16427859pzi.48.1696876309199; Mon, 09 Oct 2023 11:31:49 -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 a25-20020a62e219000000b0068fe7e07190sm6653399pfi.3.2023.10.09.11.31.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 11:31:48 -0700 (PDT) Date: Mon, 9 Oct 2023 11:31:46 -0700 From: Kees Cook To: Justin Stitt Cc: =?utf-8?B?QXLEsW7DpyDDnE5BTA==?= , Daniel Golle , Landen Chao , DENG Qingfang , Sean Wang , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Matthias Brugger , AngeloGioacchino Del Regno , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] net: dsa: mt7530: replace deprecated strncpy with ethtool_sprintf Message-ID: <202310091131.550C9CD8@keescook> References: <20231009-strncpy-drivers-net-dsa-mt7530-c-v1-1-ec6677a6436a@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231009-strncpy-drivers-net-dsa-mt7530-c-v1-1-ec6677a6436a@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:32:10 -0700 (PDT) X-Spam-Level: ** On Mon, Oct 09, 2023 at 06:29:19PM +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/mt7530.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c > index 035a34b50f31..e00126af8318 100644 > --- a/drivers/net/dsa/mt7530.c > +++ b/drivers/net/dsa/mt7530.c > @@ -836,8 +836,7 @@ mt7530_get_strings(struct dsa_switch *ds, int port, u32 stringset, > return; > > for (i = 0; i < ARRAY_SIZE(mt7530_mib); i++) > - strncpy(data + i * ETH_GSTRING_LEN, mt7530_mib[i].name, > - ETH_GSTRING_LEN); > + ethtool_sprintf(&data, "%s", mt7530_mib[i].name); Err, wait, I spoke too soon. Shouldn't this be "data" and not "&data"? > } > > static void > > --- > base-commit: cbf3a2cb156a2c911d8f38d8247814b4c07f49a2 > change-id: 20231009-strncpy-drivers-net-dsa-mt7530-c-40cad383654d > > Best regards, > -- > Justin Stitt > > -- Kees Cook