Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp302760rdg; Tue, 10 Oct 2023 10:37:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFUvSBRsu2p2cDClvEfd8hYnsGi4tu03UBUAbQjlEicJmIsWH5fHYgF/eIibtu6L/rubAhX X-Received: by 2002:a05:6a00:1388:b0:68c:a81:4368 with SMTP id t8-20020a056a00138800b0068c0a814368mr19507458pfg.6.1696959440140; Tue, 10 Oct 2023 10:37:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696959440; cv=none; d=google.com; s=arc-20160816; b=pYdgN2uthYnM6dtzBjDhwy1PLndaRdBJYbwrnMqoZ5mpxa7ne7nj16rITAN6wG1w7t Qn3nBR8r/4RAs+JY6KRELVWig4v0b4hBHsT99L2+JNKTdvzPiBE5XyGnFXR1S8THAzr1 /vuAftCRAnsmmOwDzsF9z75BmUFUcCojBMUaYDF6UkZBIfySYbOPM+tSk5IzfdXeMKwl idJPxy9UJv4eppnYQU0iX/imDDmSsVChYuS4tjMFRgtVQKAlBXRWveI2kQrErUHkauJC EjHT2L+ToU5oZXlmOPwm1dK8ggyCBBWbRkWUcTVHMCEb+unQmLQ6RZRqf9PbeeAe26Cv +B6w== 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=ZWNVXhOMB/X7Db/z1zWLDue+XTDYtJ9T9vo+cNZEfhw=; fh=pUuHUirEnWLysLh7gleJdVLD8yQNG7jsiE2tJ/wZ/Oo=; b=wDhXbgqPzJQL8iiErKD8P7IWQvH46ULRHPOFuiQtoaKjge/sAPNMGkg6DlVolIvhcS w4DaJTCPjcF35QnkmNsV1Vr4A7mLNFKM1PJjeJFT1FJVL/mY5ZDkEREZ6HW/h+9Fo9Jz QqfjTagd9ZMSMfulSfcBBpLScPOA6XGGtWeef6kzbkGeWoGE2bAjLlv34CWLYvqFTOlo Osvke+0hWWuBkK4Oc7vfbwuD10UkWx54CB1OcH1oyBs6L4dyP5YiADZucWdSCYUTLCkb 7+K+wyAhpp5MtrBnObgZv0+aI56punqJr+20GqzBcTBnWoRiIq33dRz3O5dcqR/xJQc0 l0pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=1zzlZH8c; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id i135-20020a636d8d000000b0059b85f72144si2141012pgc.372.2023.10.10.10.37.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 10:37:20 -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=@google.com header.s=20230601 header.b=1zzlZH8c; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 561A7823F4CA; Tue, 10 Oct 2023 10:37:03 -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 S232131AbjJJRgx (ORCPT + 99 others); Tue, 10 Oct 2023 13:36:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232397AbjJJRgw (ORCPT ); Tue, 10 Oct 2023 13:36:52 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58D8B9E for ; Tue, 10 Oct 2023 10:36:50 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-538e8eca9c1so10347618a12.3 for ; Tue, 10 Oct 2023 10:36:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696959409; x=1697564209; 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=ZWNVXhOMB/X7Db/z1zWLDue+XTDYtJ9T9vo+cNZEfhw=; b=1zzlZH8cXHkHdZRDMVCSWZMTfaqJJcf9gxAfzNtj+qEkReE6HIZ8Ss0tDAGAyf6Bng L927lSmBL0nPZ6LXlLe0oyUG4UhHj5Jgu+uaYEK6boTmxza+qnbyLa2hv7WAGZmI4+DB f+cUi5/y7Q1fxilYLgSuFB3UPYvwHYSaMA98VKEV0oM5iDc2LO5y0oVeII2giaBoppi9 vjD7vSRvj5uTvQAdDgJYU7A/TpjXplrWUM0OUCrNZ6SWN3z016TqdXwZxne0+4cbF2PY l5YmKTDsxn7aVOhylIWtgM7Kh95S5r46H+a1qjQ9aHPDblTU0L/i5QoqkjTG+PSjp+cd EgcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696959409; x=1697564209; 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=ZWNVXhOMB/X7Db/z1zWLDue+XTDYtJ9T9vo+cNZEfhw=; b=PJKa/7b2P3jpKf9PmpLmJ3Q5g/xz+oxu4xW/FYGABvPztUAsp6sobemVKpD+LKNGwA Wmu8hqKUwsQf70SudG+YaEVxmdOWOzMAoGk0BoORlh5TvsuhB32U6uoL+2KB6MxkMqrt 79of4mT0YeyA/xG/cya4FntDCp4XX9mNgsfsMtdmj0jnY/2Ap4LCE1qH/BzxzggRG5SN DKEmOUfBq3Jcc78R0fARtgbWz+YbgTlxZLrh/9HjrvlanzoeS/ilrB2zzTASE6Jdpna0 CgHIki5ZrpXXkPTE+Ml00x7JykjUFiDODD9vtyQddfDwdoRiA7WPbmnSt17bG8VfdZpB lPpQ== X-Gm-Message-State: AOJu0YznoF8XVyvy7dkvrS1f/3KftI4nTTQjYTr5i3Tq7XS1Bvm5QUSE ArTRlCls3engGdkEpm/fOoZO8SI/DK1ngdVR8X8Akw== X-Received: by 2002:aa7:dad2:0:b0:533:5e56:bef2 with SMTP id x18-20020aa7dad2000000b005335e56bef2mr17194800eds.10.1696959408584; Tue, 10 Oct 2023 10:36:48 -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: <20231010110717.cw5sqxm5mlzyi2rq@skbuf> From: Justin Stitt Date: Tue, 10 Oct 2023 10:36:36 -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 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]); Tue, 10 Oct 2023 10:37:03 -0700 (PDT) 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 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#st= rncpy-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/real= tek/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_swit= ch *ds, int port, u32 stringset > > > > for (i =3D 0; i < RTL8365MB_MIB_END; i++) { > > struct rtl8365mb_mib_counter *mib =3D &rtl8365mb_mib_coun= ters[i]; > > - > > - strncpy(data + i * ETH_GSTRING_LEN, mib->name, ETH_GSTRIN= G_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 it in one of my first patches like this [1]. [1]: https://lore.kernel.org/all/20231005-strncpy-drivers-net-dsa-lan9303-c= ore-c-v2-1-feb452a532db@google.com/