Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp425818rdg; Tue, 10 Oct 2023 14:48:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFTy0ndFAPx6nVYnOIs4GaGStlW9jUbc1QUZTdm32nyyC9qBdzApcoMcJpJ8OzwnYl/xMz4 X-Received: by 2002:a05:6a00:1951:b0:68f:ca4a:efd with SMTP id s17-20020a056a00195100b0068fca4a0efdmr17780974pfk.9.1696974515378; Tue, 10 Oct 2023 14:48:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696974515; cv=none; d=google.com; s=arc-20160816; b=CgPsnnYkidO5iHYj+4jQZxZPls85fpjM0OHqCA6nbQXtRnpUXgZBlrvsScFrna7KPb Eca/3GRx7RWLwmvJ+S1INUwbINxFkC3W6Rs7puSQZNlnLU6XSjsAiV8Cl2DWe4zjwskI obhlKSOYM+vtkc2FymO8rtb8RuDzKuqiuKYOOxiXZ7KTu/C67AfshMSxPa839QtVOFPr V5vBWK27kEvWFDgdshw9JJZ06XhPslcn6L8p5Cq2ydewLR/oYsvR2kdDpXvW2IbKy53+ jymbqRSvVUaoTdQvW/jQjQvFk8zq2IEzX364gol/J2MExx/WR9t5IHQ2qMzLScvlFpTp uPxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=RVwIjs7unBVw8/RUbtCg7Be4ufWML8Z8whIdGG4oG9s=; fh=pUuHUirEnWLysLh7gleJdVLD8yQNG7jsiE2tJ/wZ/Oo=; b=cvUGSpq+yy2DGLYpDPnYf43HWHmNzfbmAS6LCxsRjXRyeDJsSBNifowrGieLtSeukr cAY3Yw3cP/r/FMxvlY2/D7EkFIGLtsJZ6zqS9FS+OPFZGmdU6Tdpw6Bz+iBLKVx2Oakc 0qeAdFtwAskDiCD5boVHlKBnU+XqICq5UCPzw+GdaiFCGuncCUpFZ2Z7pRvbzC6vXOj6 agfonPS73n0lfV0bwi7XMU8uBMMxfwDYjqcjYcEORyRMtssk0owjxZlT17zH+znwSj9k URCOexjU19fco+eOQjK+3fkC+uMF2PdVm4YRQzToEDxTR2QRy07Nl8dnH3C8cTjU/HM0 UNsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=gfBu+55B; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id a72-20020a63904b000000b0057744d09d1bsi13108176pge.251.2023.10.10.14.48.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 14:48:35 -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=@google.com header.s=20230601 header.b=gfBu+55B; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id BB62A80DBADE; Tue, 10 Oct 2023 14:48:32 -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 S231857AbjJJVsZ (ORCPT + 99 others); Tue, 10 Oct 2023 17:48:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229778AbjJJVsY (ORCPT ); Tue, 10 Oct 2023 17:48:24 -0400 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61A9F11D for ; Tue, 10 Oct 2023 14:48:21 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-538575a38ffso10073109a12.1 for ; Tue, 10 Oct 2023 14:48:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696974500; x=1697579300; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=RVwIjs7unBVw8/RUbtCg7Be4ufWML8Z8whIdGG4oG9s=; b=gfBu+55BcotZ9nxQs/vpg/tvOKCO6Qy/8Qck1grOA3kV1jVCfmvPbGBzKfWJ9Yf94U yElSDhorEwPyf7aTF/FZTE6e9gq4uC8DmHnTFoRuSaRajRVpGwmG8xSC1bzbUt15zo2Y P+Izz/bZQNonkKVvWPn3Q4nLcwFFCJd68OY2Rbx58fvJpEV0OYs2jUYN4+gE4TMoykn8 7u2AVO1M5D4QZ1bVOLQG048maxHLgekwBeNUqu4e2XnAoyhHy4dzEThMGn073UHYvX7Q bCUii4zeqdA2+p95zbO/ZCpkotAMFga9TEnPvvJ+mTcH5eqomH5+tuMcy0n/s4q9gHO8 mnBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696974500; x=1697579300; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RVwIjs7unBVw8/RUbtCg7Be4ufWML8Z8whIdGG4oG9s=; b=jdAO3RSdWy0jlb3CalWuZ8TU/B32jO+8ejcXcl7Oey9wyLaa9TRj1RZaahHO2E0lD0 6r+Lh06U4vcAfsoZmXrFt5UJvSMZAxisj1b72chZe1edZe6d18Se/RpwPCqW+VHk4bIS YP9h53vA5F8fy+WMjxT8MQ90bhfBRiWzfoSNrINpw3l57PLK2RWfhy4AGCDJxpW/eZDf Pb7MUPTdoBcnEAiTM/vAQAvni3ptLsaEA5Tij0olCK3SOQTEnBzoueyTERIaD9xW0QNX UOVVBNyrkKG3TIAVlBw6GVSogKvWOFFpQnkBivrRh4gQG/K6Ley0ST/B9S6zeRDdez1E ra6w== X-Gm-Message-State: AOJu0YwdGDlzsaFZWnF8uKaRFnTngcmvt6h47RmbpkMRPKcEgCiyNcXo JqObBslG0k4OPMtIWTUr2i0W2C0Ooivj/CQ29BF3rA== X-Received: by 2002:a50:ef0b:0:b0:52f:b00a:99be with SMTP id m11-20020a50ef0b000000b0052fb00a99bemr17506693eds.33.1696974499699; Tue, 10 Oct 2023 14:48:19 -0700 (PDT) MIME-Version: 1.0 References: <20231009-strncpy-drivers-net-dsa-realtek-rtl8365mb-c-v1-1-0537fe9fb08c@google.com> <20231010110717.cw5sqxm5mlzyi2rq@skbuf> In-Reply-To: From: Justin Stitt Date: Tue, 10 Oct 2023 14:48:07 -0700 Message-ID: Subject: Re: [PATCH] net: dsa: realtek: rtl8365mb: replace deprecated strncpy with ethtool_sprintf To: Vladimir Oltean Cc: Linus Walleij , =?UTF-8?Q?Alvin_=C5=A0ipraga?= , Andrew Lunn , Florian Fainelli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.8 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL 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]); Tue, 10 Oct 2023 14:48:32 -0700 (PDT) On Tue, Oct 10, 2023 at 10:36=E2=80=AFAM Justin Stitt wrote: > > On Tue, Oct 10, 2023 at 4:07=E2=80=AFAM Vladimir Oltean wrote: > > > > Hello Justin, > > > > On Mon, Oct 09, 2023 at 10:43:59PM +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 strin= g > > > 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/realtek/rtl8365mb.c | 3 +-- > > > 1 file changed, 1 insertion(+), 2 deletions(-) > > > > > > diff --git a/drivers/net/dsa/realtek/rtl8365mb.c b/drivers/net/dsa/re= altek/rtl8365mb.c > > > index 41ea3b5a42b1..d171c18dd354 100644 > > > --- a/drivers/net/dsa/realtek/rtl8365mb.c > > > +++ b/drivers/net/dsa/realtek/rtl8365mb.c > > > @@ -1303,8 +1303,7 @@ static void rtl8365mb_get_strings(struct dsa_sw= itch *ds, int port, u32 stringset > > > > > > for (i =3D 0; i < RTL8365MB_MIB_END; i++) { > > > struct rtl8365mb_mib_counter *mib =3D &rtl8365mb_mib_co= unters[i]; > > > - > > > - strncpy(data + i * ETH_GSTRING_LEN, mib->name, ETH_GSTR= ING_LEN); > > > + ethtool_sprintf(&data, "%s", mib->name); > > > > Is there any particular reason why you opted for the "%s" printf format > > specifier when you could have simply given mib->name as the single > > argument? This comment applies to all the ethtool_sprintf() patches > > you've submitted. > > Yeah, it causes a -Wformat-security warning for me. I briefly mentioned i= t > in one of my first patches like this [1]. For more context, here's some warnings in the wild: https://lore.kernel.org/netdev/20231003183603.3887546-3-jesse.brandeburg@in= tel.com/ > > [1]: https://lore.kernel.org/all/20231005-strncpy-drivers-net-dsa-lan9303= -core-c-v2-1-feb452a532db@google.com/