Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2175226rdb; Mon, 9 Oct 2023 15:44:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEQOP8hZLLcRpbogVcuHQKtNPPsoxCzB3JBDlPMUCmUFY6ohyr7cDZCcZRKySPhfVK1895C X-Received: by 2002:a92:c24d:0:b0:351:98a:16c6 with SMTP id k13-20020a92c24d000000b00351098a16c6mr21836186ilo.27.1696891455850; Mon, 09 Oct 2023 15:44:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696891455; cv=none; d=google.com; s=arc-20160816; b=reWnzE7V3D5x5ln33PlWK4l8vKnaYv+dIRqEFeDarkoL27VWAQKGQ9CsCfl2pA2F9r gy/sdjndRHLRP9cSIghg6uPCtyWcuxr+ObQgz14aDu1fli/mkfIRbN3UaGMZh2N7rMF/ EQpxpnVydaIOm3c7WUY5zKCFoNDjf/cjskuA250uhKWpUOfxMAAmWVbY/MgejkJy+3lJ zFDil/4ofdE6CmMLBy/lt+G+pKdkcILPb+5feWk/qf8X7mJ2g3NCz488+ZqztW31iUsY 4MUw/mcP0kV5Z/4jpbGMTQdyy0X10ac/C4DXpNDtSgd0HsdOHTz5qXGshDiy/DWN7fzn xCXw== 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=lcEkRtI6p90rXcCOvkouPghb3M9m0aVLP4AHp4xDips=; fh=GwK11QuIe+n7JbVKLoEM7AfDJaUz/IDzceyzI5NNgS8=; b=pbUyChsKJmJXGNgVvkmafNJIZRTMdZ7QUE1xO3fuAR5NS+ifQaoVFn6uG2zy5bDEp9 nj+39okaDRuvRWE/y9vNBGKvX0x6L9jRRR87LXKeiIiqqaXiXZMv6xrFY0SA89Xcccg1 +tUYsBmjcO9Ifn2xziLjwx+NfRdANO/7GSvj88CJyExWgiDKMXC4FNuc6JBu9T7ZrRly /X88lpjfimf89Ah9RqPbfAiobQYE3/Q65RtFqBpUofLF30GBKOqG9dbGVszBobIyCmTO oCEt9Yh4Wmn+/Rx/EdePZm2zRDw7grE44wbVHRD3sySo6pguvqC9bkQlgSE69P1wFUz9 oztg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Rwa4I42W; 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 t189-20020a6381c6000000b00573e6013bc4si10364704pgd.851.2023.10.09.15.44.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 15:44:15 -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=Rwa4I42W; 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 F2BEC81C9993; Mon, 9 Oct 2023 15:44:12 -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 S1378912AbjJIWoF (ORCPT + 99 others); Mon, 9 Oct 2023 18:44:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378893AbjJIWoC (ORCPT ); Mon, 9 Oct 2023 18:44:02 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AC049E for ; Mon, 9 Oct 2023 15:44:01 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a7b3ae01c0so8479597b3.3 for ; Mon, 09 Oct 2023 15:44:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696891440; x=1697496240; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=lcEkRtI6p90rXcCOvkouPghb3M9m0aVLP4AHp4xDips=; b=Rwa4I42WxiXXdptfUjSOUyqNZhDMOnOI1l+KC1YWHpvGJDOs3o17zdVc5WqhTsapfk ao99ZcqBhVR5+QVPTGcaozDvyDqEh6/C6nExnGFY7MsqUwj85VcrnAjJH6bqxqkqChTi OGEfpoPmbqez+38JL6xq9RUSrraHwKJ8Tjwjql/ODJt1/4k7SsCp15mL0vTJfjB+GSDZ x/1Lkklz3prHhrjlvsOU03vL9XpiMvnUbApv8zCyqIqwrtZWRECR7xQpRMN/FtCJauPL iZn3VqmxtIDxDbJ49LmpkiWZ/vpjWsQdbFETqwKWFpKZAKOm72JMTW8FXtg0j79iQUkw SD3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696891440; x=1697496240; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=lcEkRtI6p90rXcCOvkouPghb3M9m0aVLP4AHp4xDips=; b=dH8Izq7vDo9SD5TasqEZ2XXxYexnMXaOgBip/x3EyfobGa7IyMTWxCy/T+ZazhHMtK j4GLh/dhCJOs+riXANkr8imGXw3aWRsH/p2pd2rc+cwNkps2wRT1rO3tCvBeID3BnODn 8qE94W7vlHHtosaLon5bYpaUUZRc+JxEoE4CR/iWujPxZtiWUa+OmJ0wemwGNi3B4q6R LLCmtEOfb3hoesnpFAC2IMefjf1bPq3xc9MVd1sjqxzgMiXAZy5kspswQl/kEzRvAGO8 Fh+PTG3aTFxe9oZLasrgejNPQs7KsRWK63CiP7wfhAbIede0G7sZ7i4bSw8Hbuatw3OM BLYA== X-Gm-Message-State: AOJu0Yz6h6Cg8+AOjvzevIM6XJxMrftx67S5mv6eAR4e6MutsPzFBSYi gyVJU3FlzzpJEu9jrMfiqpbyUJbCPdhyuZR+8w== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:c3:0:b0:d9a:45e7:b8bc with SMTP id 186-20020a2500c3000000b00d9a45e7b8bcmr25189yba.4.1696891440537; Mon, 09 Oct 2023 15:44:00 -0700 (PDT) Date: Mon, 09 Oct 2023 22:43:59 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAC6CJGUC/x3NTQrCQAxA4auUrA0krRb1KuJifqIG61iSoSild 3dw+W3eW8HFVBzO3Qomi7q+SwPvOkiPUO6Cmpuhp35gohN6tZLmL2bTRcyxSMXsAU3CVOWJVqf jMB5eERPGyDTKPjFTglacTW76+d8u1237AVexKdp9AAAA X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1696891439; l=1543; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=t6ppbaGIRSBsCeLAwhf3icSi3QggQapCJpuQhPkWhCk=; b=FWHhhun5aGED0QoILNdMciMZW3HTaYxCbuwQE2GB9YVe3/t5D443MOnBAm6QN6t6igpdopFpI UblLVj3B+mDBhtxxWYA5eMKhHFTTQGn4GjNgywTjOiej/yfypbDcEFq X-Mailer: b4 0.12.3 Message-ID: <20231009-strncpy-drivers-net-dsa-realtek-rtl8365mb-c-v1-1-0537fe9fb08c@google.com> Subject: [PATCH] net: dsa: realtek: rtl8365mb: replace deprecated strncpy with ethtool_sprintf From: Justin Stitt To: Linus Walleij , "=?utf-8?q?Alvin_=C5=A0ipraga?=" , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "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=-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]); Mon, 09 Oct 2023 15:44:13 -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 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/realtek/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_switch *ds, int port, u32 stringset for (i = 0; i < RTL8365MB_MIB_END; i++) { struct rtl8365mb_mib_counter *mib = &rtl8365mb_mib_counters[i]; - - strncpy(data + i * ETH_GSTRING_LEN, mib->name, ETH_GSTRING_LEN); + ethtool_sprintf(&data, "%s", mib->name); } } --- base-commit: cbf3a2cb156a2c911d8f38d8247814b4c07f49a2 change-id: 20231009-strncpy-drivers-net-dsa-realtek-rtl8365mb-c-bb106e4c110c Best regards, -- Justin Stitt