Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp601480rdg; Thu, 12 Oct 2023 15:28:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHgSNaW8vzZgDA8G48Vu8hI1xmCZ9N+uyJnXWeUYKA6NFkSsDayvX35soCokStjfmoEc9KM X-Received: by 2002:a17:902:d50c:b0:1bb:94ed:20a with SMTP id b12-20020a170902d50c00b001bb94ed020amr27837357plg.24.1697149686361; Thu, 12 Oct 2023 15:28:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697149686; cv=none; d=google.com; s=arc-20160816; b=LJPR31p8T2vYUXQMCYgufNy6w9sQFlmZt0eQbfYxFvBq5i/1u8Ju6+rZAF6/0ffHYf lsCW/uWo6c7saYiKW3p9cG2rvgkM78M8yqOvqlWgmOk2/PCmUM9m4FILdxTcgCedx69b QiZ+eQgjuwmAXYV8pPFoHHH0Bn/mcAwR5D2vwOdoxPf8tk2R/jgynrHlWiz3Wkdpo5z/ rq2VJ0Rui+aPlDKCgfY+YxnajBGFczTr2ON6C4QuTsBEPfeyodWBu6/b6ZbY35COCJv7 nDdRIVY0ELHalYpXz0wAFgbfE2kgDpnD7lay8FQKomEI5GO+fkITWs3fKGJVcgbckWzO B7OQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=rZYpAvmIgIMiNPsdg/lY35j3EeR/rUqwRQrzCZkd3d0=; fh=jNFzfs0LVcNPJYpz3MO9rP5uq1TU3TrcBg7mkF9EWrg=; b=C79vBPmprE3YbhCVENy5vmrMOjk/F7cCbOJxQ0sVRnGXiv9fEH348bCJ5QWWmO8203 up6eAS/UDZZ4dRQwgPo1WqX452rAcc9fSdNU2kg3W7Q365IS6niVk6Ycu2Ed/YNql1Ii 2F3xkiZZnYmxdI/CTHOmht4RQ6p4fXEPl09KH9msBJwQ8tPNEY2m9E+uj+HhiRhQG9DO QpUEpK0p9St/ezhdMYZNV2WdS6qJwhB7yQIhEQ7pPCr/1DAnEUyBWUxW7dJiOHgsjuEY pEtLoKLafo3H1DwwwxrDauc7f57rqjwQIToRE4JW8U7lbqxFrgpogL1Lr0GZRXk3HTS3 INVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=z0hOqJQA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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. [23.128.96.31]) by mx.google.com with ESMTPS id kb14-20020a170903338e00b001bb95a5cb9fsi637800plb.522.2023.10.12.15.28.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 15:28:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=z0hOqJQA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 07E6583E1ADE; Thu, 12 Oct 2023 15:28:04 -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 S1443001AbjJLW14 (ORCPT + 99 others); Thu, 12 Oct 2023 18:27:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442949AbjJLW1z (ORCPT ); Thu, 12 Oct 2023 18:27:55 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 000E5CA for ; Thu, 12 Oct 2023 15:27:53 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d8b2eec15d3so2158161276.1 for ; Thu, 12 Oct 2023 15:27:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697149673; x=1697754473; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=rZYpAvmIgIMiNPsdg/lY35j3EeR/rUqwRQrzCZkd3d0=; b=z0hOqJQAGcLilxNgiHT9cMELbFMFkG17er1m8n/oQ8MsVcVffzAje5T4EpZKz8d+cv vsx3Qb6bz2QKuV0JWv5QDQ174OzMuXM+6vZDhBAwc7Sf5RxtZmokXG3qA8uEBdNC6Nv2 w3KUTbjj156Hck9EMxBGBM1JnDXKNuAJ4cUrvz8Js73DKWPkH4mQTxdwAGK9nfPblTv+ RM7L0tOanYbNO7+drkC2XzL2V+MsOL0dURSX3Uy9hmr+v9Y1AzjqJxbTV4Yvwedjcz+a /hvVT+9/Qmsyrom9EzDM3gFhwfo9D04cFR0VgtWYHQzNiRp9xApV0n8NUEHAQmD/dZUq DI4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697149673; x=1697754473; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=rZYpAvmIgIMiNPsdg/lY35j3EeR/rUqwRQrzCZkd3d0=; b=DSKRbVq1v6Mz9LrGjBPe4NKJAVnFVTvR+qk1AfQ/Vwfbmw4eFvI95SAY5mLKrXqeAA sWIlE1sp4r+4CABCFcnWMuftIKmzu7Fj6ZeRlcFNMev3PFK8dqyk1Qahrz1LmHkTz3f3 ok4fAuNcH8NQ+QmTdl5AAo+Q1J99RdScl4LTDJZQrleGN+k3cRFEIUjvzgUwpBZzp9vZ wKWSe8Z6lap955Twgn0dcWm+9s+50+PtHW4PgkCIwhidmIDckuzMxobj1GKKNj8joSkW QMWN0ehkSAa397+/l7x9TKXToAzlqhLtyYLv1G+u3ocPa3Mn8AqBbZYqofM7D/bf32YD BaOA== X-Gm-Message-State: AOJu0YzI3D2sgyK0mNTtnfrZew8qbpqw5gSu/7H98YtApCY/3SOXcKxm t32ls1il+A9MaMjaTyC1duF89DwgFmqbROyzng== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:8a0d:0:b0:d81:582b:4661 with SMTP id g13-20020a258a0d000000b00d81582b4661mr526282ybl.8.1697149673145; Thu, 12 Oct 2023 15:27:53 -0700 (PDT) Date: Thu, 12 Oct 2023 22:27:52 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAOdyKGUC/x3NMQqAMAxA0atIZgO2IopXEQdtU81gLYmIIt7d4 viW/x9QEiaFvnhA6GTlPWaYsgC3TnEhZJ8NtrK1qYxFPSS6dKMXPkkUIx2Y1ht1U4cO28aH0LX zNDc15EgSCnz9g2F83w8DaSpFcAAAAA== X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1697149672; l=1565; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=5QhySr/Q36zDeZ98j7zPXD0GUeZwX1jIeAwMYdxCyJY=; b=KrpFlNS4TYnLFKZYhQfQ//GmLAMKDMsDyCpew83lBGhmjSjQwft46M0mgguiqwpB6z88nBcuU Ds7ihe1nXe0DZ4uk2R64dfZCwG7NdZ7DIULPlIejpSdriFk3YldG2FT X-Mailer: b4 0.12.3 Message-ID: <20231012-strncpy-drivers-net-phy-smsc-c-v1-1-00528f7524b3@google.com> Subject: [PATCH] net: phy: smsc: replace deprecated strncpy with ethtool_sprintf From: Justin Stitt To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Justin Stitt Content-Type: text/plain; charset="utf-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable 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]); Thu, 12 Oct 2023 15:28:04 -0700 (PDT) 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 dedicated helper function. 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. Found with: $ rg "strncpy\(" --- drivers/net/phy/smsc.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/net/phy/smsc.c b/drivers/net/phy/smsc.c index c88edb19d2e7..1c7306a1af13 100644 --- a/drivers/net/phy/smsc.c +++ b/drivers/net/phy/smsc.c @@ -507,10 +507,8 @@ static void smsc_get_strings(struct phy_device *phydev, u8 *data) { int i; - for (i = 0; i < ARRAY_SIZE(smsc_hw_stats); i++) { - strncpy(data + i * ETH_GSTRING_LEN, - smsc_hw_stats[i].string, ETH_GSTRING_LEN); - } + for (i = 0; i < ARRAY_SIZE(smsc_hw_stats); i++) + ethtool_sprintf(&data, "%s", smsc_hw_stats[i].string); } static u64 smsc_get_stat(struct phy_device *phydev, int i) --- base-commit: cbf3a2cb156a2c911d8f38d8247814b4c07f49a2 change-id: 20231012-strncpy-drivers-net-phy-smsc-c-75dff87bab53 Best regards, -- Justin Stitt