Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2083946rdb; Mon, 9 Oct 2023 11:57:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEiilKZxf37rm6iUz3/KpSiope9fjgD2UoCaoMXZA4ZJ1S1EIwX92JUMR+4lxGcbzfdpGPK X-Received: by 2002:a05:6358:999f:b0:140:f6ab:b11e with SMTP id j31-20020a056358999f00b00140f6abb11emr17863740rwb.28.1696877852482; Mon, 09 Oct 2023 11:57:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696877852; cv=none; d=google.com; s=arc-20160816; b=sxepq6yyOy1NY9HLz7lamG2Ha2OjJuBKjd8Uu4M2jgSZ3Iq/uJOwY73QL6xdqOiudZ GwDVdQHFY7YJUD6Fns3lIEFfaVgACDhe3/H/UiQ7e0tf5nq4GGjHtmYCKelDJ29Y5WiJ DfUHnx0neOt2KskzwKt3NxDL8YHKzP//gFByrsjzxQXRlOAaPiXxjdt7ucRtUPrGblpj x36wBJWEqAgVns5yKzYoJz/PA4tKCWBQPEZLYssk9PANIwkG+6XOlSa5nXfn4CNY++OJ iX/YPSV4USeTn+XdQ1zvZ/Zh7JEAqDp7CnH7b0Sy4uPVkWuQZ5kzuisBFhIt3SPEGiNQ SDew== 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=ef2KltIf/Jizj+cWsThstfJI8FTNgm2Gv7ZqircULnk=; fh=FsCqQPf0UdRo3SFKLGZflMv7iiUs0vvPVOExuhGSP00=; b=zCjJ61gqX23zUdIFhC2mxy7CfjITK9DRrF5MYfKANzS8GNaMQ0lV6o9aIFYJlwRCvZ WQNc5RFPlGTd9sGSUiSPVhZHPCAmNqu62RghvXF4VT1dNtMiFt7a+078MfpLe+z/l+IU 43oEyRyjs+3dEVq6RPG+AJjEDSUq/zk0WGnxHVL84ep0wY023c8EYUrvI8hpM0Kap3MN vaLkHl/jtnWEKy7iKC5C7Fx2Etr6gd8Jo8EJV6m4JvYuxGlbKr3PXOvTUuMc8nNjk6JP AlbHEimIOqajVaZWJls16sejkzafnG2k62GZ/zPPWaRgJbmxvQbhzqQC3BxLAt7GRfeD iTQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=lpO2oNy6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id a18-20020a17090acb9200b00274d5eb88c4si10088109pju.90.2023.10.09.11.57.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 11:57:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=lpO2oNy6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 83346801B42F; Mon, 9 Oct 2023 11:57:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377392AbjJIS53 (ORCPT + 99 others); Mon, 9 Oct 2023 14:57:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377444AbjJIS51 (ORCPT ); Mon, 9 Oct 2023 14:57:27 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5767A4 for ; Mon, 9 Oct 2023 11:57:22 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-690f7bf73ddso3271005b3a.2 for ; Mon, 09 Oct 2023 11:57:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696877842; x=1697482642; 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=ef2KltIf/Jizj+cWsThstfJI8FTNgm2Gv7ZqircULnk=; b=lpO2oNy6rAUVMqUJwdzK9SfX0IgGOBBDrVu9kPv+W3YBwUBE6DDo2Uis7+f31qOLxe xCjOdkEOGfVkzJVsxZ5cwIbfnkSAkoAVNBF12e/XHsjuPjNnI29nBAJdapMefJbp2uUT 2/iVht4Z0z1D4nN5WcvRnOCc2aq82qvEwGZn4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696877842; x=1697482642; 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=ef2KltIf/Jizj+cWsThstfJI8FTNgm2Gv7ZqircULnk=; b=IRuVWAxVXyM5JmUF2JUbQtHbcM0C7i+1zmN/egOcIs1CSebAoy5MnOZ7BaYwM/NOdz c9kdRjDeuEGzVbQDild3XuSSH4SwaMehGRhEOrSMWm1A+kZgU7jMKZWHdp8GfXKeHor/ 7AGD/EVfH+KyvXcvE8U4krjxy7dcGNEvND+48fL0hNlt2fjfdUFL+atgrfBp0R4NVyTZ 3hwfzP7+11LHajvSM1b5UEds3898me5bX7T2D9o7HgnXmTOxSjDxwraYs9SytUdMgdPa vfjkvdB4jfu1+wAj+G2rzzWsLoehXLppmmY0X4P4RmK+CGPd0XqnOr0dvMlfHoG8Mdn5 YTEg== X-Gm-Message-State: AOJu0Yy6bvIF0FUzFoX8cLVwVAWV+4h5ymZ+zH3Ku9Q1peKCA/xlj6mM VA9KX6PXdaUYrVDbve5gLJV4HQ== X-Received: by 2002:a05:6a20:841b:b0:137:2f8c:fab0 with SMTP id c27-20020a056a20841b00b001372f8cfab0mr16715873pzd.49.1696877842295; Mon, 09 Oct 2023 11:57:22 -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 p18-20020aa78612000000b00689f5940061sm6902037pfn.17.2023.10.09.11.57.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 11:57:21 -0700 (PDT) Date: Mon, 9 Oct 2023 11:57:19 -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: <202310091156.978D4E1@keescook> References: <20231009-strncpy-drivers-net-dsa-lantiq_gswip-c-v1-1-d55a986a14cc@google.com> <202310091134.67A4236E@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202310091134.67A4236E@keescook> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 09 Oct 2023 11:57:31 -0700 (PDT) On Mon, Oct 09, 2023 at 11:34:27AM -0700, Kees Cook wrote: > 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? As I said in the other email, please ignore me. &data is correct. I'm not used to ethtool_sprintf(), clearly. :) My original Reviewed-by stands. Sorry for the noise! -Kees -- Kees Cook