Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2083627rdb; Mon, 9 Oct 2023 11:56:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFbtcJnYSqFlzMXP5srxdCDrdGCz43yHt2o8eBMdxk5dDUBxZ8/Ta7RygzvxAi38YXJX2lN X-Received: by 2002:a05:6a20:8f1f:b0:13d:5b8e:db83 with SMTP id b31-20020a056a208f1f00b0013d5b8edb83mr17963461pzk.9.1696877806666; Mon, 09 Oct 2023 11:56:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696877806; cv=none; d=google.com; s=arc-20160816; b=W5xw67Y6B1AepxFDLuKKkrqFDDBe2Qe6mVFMjJ0hGtvWfv/6braF5ZNTKTyKmSx/nM nXEe/qW5A/ACbpl/AMp4dwe3lYvYef9m980vyYB2/kFK7ZBdj8YSVU6UznMzqSj1PbBH Asc6stp6rXmrOnhrjW97iHheeSSXpYIvYjj3vSAcOKUf+S9bthxMvuXmbjqM2X7Kb9qI eaQdYSjVYyaOMtnTS7amO4CDudwimml9/TntltMCc3IF9YXh6Yy0h+VL/ZRhxcNouFwV z1BOzCQ+FZo9rhpwU5j1gA8wHZDvLW+UoTGLchqyY5mVKq4j02LQ0YNpOXeMd/1vfNpH 32qg== 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=3MsTR/cGryQq7rM7HxcuS1zRjm3nltuO+eDU9+kch7k=; fh=9jsy8AbJvGuLuRkVPwhOjX5rocIcnUak6lkzc/Cn27k=; b=mxC+OgjD7DlL1tXMihe+/N41d4/YjdkXCrTVDKHDEjSl1LxL+cqgc9LsBtvrgEUiC7 Lb3zGH/+6uGw8WDO7gxShobrIFQwmIs978WDEPTTK8yqSiOVCUncg69pV3IelBrt3Mzc L0FGzTYKsG/usK9NQTN5la3vae3+/OY+CJclxde7RpjDaL9LT3FE0JskbksIVh598xGv YTN59nexCRJRPoMpKPiWuwLtwOAQ9WXICZcNWIdqXCb/wfst2kNvnCwYoYR9/4StqY0K J59IwV/K1mQHEytKjhysmXt4PZ5QDldZ9TwyW4iJspxA2QClMPo5urvKctPxa3nehN6T O5GA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="QoVQcJR/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id p2-20020a056a000b4200b006901504b6a3si4266664pfo.153.2023.10.09.11.56.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 11:56:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="QoVQcJR/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 3277D8104F60; Mon, 9 Oct 2023 11:56:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377493AbjJIS4i (ORCPT + 99 others); Mon, 9 Oct 2023 14:56:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234593AbjJIS4h (ORCPT ); Mon, 9 Oct 2023 14:56:37 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C570A6 for ; Mon, 9 Oct 2023 11:56:36 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-692eed30152so3549411b3a.1 for ; Mon, 09 Oct 2023 11:56:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696877796; x=1697482596; 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=3MsTR/cGryQq7rM7HxcuS1zRjm3nltuO+eDU9+kch7k=; b=QoVQcJR/1pcjpu45m1k4UZu/cDfvLCeUm4NHZ8etsBRlON2NUCosa4RTj2TvrcAscN SNhO0CvK+kvlg0gOfa7t1ZpW6JipZk3mj/hl8jU+0Hj04AxzUG/eWgGI+PSdr+BZirY4 ANfFuGTt7etyT1BSiYt6vCarGiZns4AcIU2N0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696877796; x=1697482596; 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=3MsTR/cGryQq7rM7HxcuS1zRjm3nltuO+eDU9+kch7k=; b=Jj3lV9CTGvIpEwyKXeTTEhdMTAc81CrCHd9i7+j5TPewb60qvODvDV2+NLbMc2kint PhiSP0WQvtSXcAtsKqJwD1pzDYfMEyorvrwI/VLKgh1JYlpg0HtY/xNH/p8w3nPP5eFK Qf0p85/stNQo4S6M7SVUFGXVDcVNAWPD6RxqtgoGIzPzxWppPIQoDDdF15keWTkluXHo wHQxlzwYr3GqfY/WrjRB6wGmfyYUJJ3hZeMYuvS9uRXe9L6P72xkJHFea3lMgTNipBAw D4gJC/nz+jN3iiMKzSskty3XLCb5OZEEQA+smcGJ29M+PC1C/i+Hjfni6gdKYEiGFDT5 1LbQ== X-Gm-Message-State: AOJu0Yx09VhOZ8rLAONGsx2LshARwg1w087YnAqg3ei2u5FznjT48q3F mU0AF4Wb5e84C7vJ4ClyjwCwfQ== X-Received: by 2002:a05:6a00:2450:b0:693:4108:1eb7 with SMTP id d16-20020a056a00245000b0069341081eb7mr15271604pfj.30.1696877795997; Mon, 09 Oct 2023 11:56:35 -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 ey5-20020a056a0038c500b0068fe9c7b199sm6820919pfb.105.2023.10.09.11.56.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 11:56:35 -0700 (PDT) Date: Mon, 9 Oct 2023 11:56:33 -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: <202310091155.3E4328DC1B@keescook> References: <20231009-strncpy-drivers-net-dsa-mt7530-c-v1-1-ec6677a6436a@google.com> <202310091131.550C9CD8@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202310091131.550C9CD8@keescook> 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 morse.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 (morse.vger.email [0.0.0.0]); Mon, 09 Oct 2023 11:56:44 -0700 (PDT) X-Spam-Level: ** On Mon, Oct 09, 2023 at 11:31:46AM -0700, Kees Cook wrote: > 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"? Ugh, ignore me. I keep forgetting that ethtool_sprintf() updates the "data" pointer. My original Reviewed-by is fine. :) -Kees -- Kees Cook