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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 91804CD611F for ; Mon, 9 Oct 2023 18:32:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=pM/mnKcPcDRFM3HqnbA/yDLZdD6xvtgGtB/h6Tc5AIU=; b=aysel2DfvkGs+t gjIVjC6sWLoo+WDtjnUCIIJlAmh8wq5smV17HcHoNIauYqljBfylNVjQEF/lJIQIRxz2FqEGF5h+v NdnMulTx+QgIXsq6Taqt68PkPrAylB+NLtVmB0InT4YuHafpKENwouXpWMkoctvzU50oyibfaoE3D 83A0fPjfrPEhnMTEenI/tb0VtdDqckobXLTt2lKk3iWvFfmEQotIts3A+QKzfZIpAHaZcCi8JoR+h 5Pd+zUDId1fek9qwlWbhVMgHwCIoPzAlBax4+mvA7L4gqXs3aWLg1Iggx2HpGEJX4q1l+0nKCCPvp J9Rj/KqI5I+5uFnMai+A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qpv2m-00BOSl-33; Mon, 09 Oct 2023 18:31:52 +0000 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qpv2k-00BOS6-1D for linux-arm-kernel@lists.infradead.org; Mon, 09 Oct 2023 18:31:51 +0000 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-692ada71d79so3663338b3a.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=lists.infradead.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=ciFao5nGKK+C4SnUdhiRtnegzcO0RW4fF2cAzczaItXs/k22KFrPwtstjoG0PLaeJ0 zc+WEnPoDo6pCgNf3jBhECeIn4hkbnfzu+PafdjJbO6h3Uj2ZMAxQuDMVa/BqV+dQEj8 t/VuueNEkxwP4auPz3TnoFMUlWbVSe7/XQFOI= 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=AsRDkek+73MU1efnxjaPk2QuQI+U7BEyXW6KyPUbEby+R1KDFPEcKhUDh9r4o9UgP2 v/dmMm2S7w5ruFy0Ky1Dheti2V5htQegu73WRats+XLLjXInC01JeBfcrI87vYo1pVBD 62O3j4dA+ePXq8VSRLkE0WiSgoPS/Hu752qOhjsl/c3+8hTsdp3OClzOYgsfrNsVqnav Yn8iQrSMvvVylSNibyalixP3TTVZwpgpP4O0N+twzrOr48dHCgPLv8y6gidfbcOmI+9O FLPORK8dznm/xISef35H8nOo/wDaSiIA95d3nVsh/WtSUUDu1sfoOwWW2FlnHaNzYwjj NIwA== X-Gm-Message-State: AOJu0YxyPNYWGBvoEIvgx0Rq8bxaQQYhr2QmXZxfai+YzfLDnhj10Ba2 GuHfjgcbdOABV7U6/aamrvo4Wg== X-Google-Smtp-Source: AGHT+IGMYrmFaqpRwdTAW2MVusib1Bdp/eV2z4yNjbyFulBH77GpTBAsliVbiaNkBmPnFki9DWoAJw== 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-Disposition: inline In-Reply-To: <20231009-strncpy-drivers-net-dsa-mt7530-c-v1-1-ec6677a6436a@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231009_113150_413360_B22B180A X-CRM114-Status: GOOD ( 19.81 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel