Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2176391rdb; Mon, 9 Oct 2023 15:47:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE3PmjsYO3XY6IQMV/49jpTpzRZmiIkJwaMtGVc2kwb2krTBcMVGfRCxd4u04LmoJXxJJwC X-Received: by 2002:a17:90b:3ec6:b0:27c:bcb3:55b1 with SMTP id rm6-20020a17090b3ec600b0027cbcb355b1mr3224664pjb.15.1696891671462; Mon, 09 Oct 2023 15:47:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696891671; cv=none; d=google.com; s=arc-20160816; b=csgC7n1EDNAMUHve52tC9swQhwL4g9TE2FhXAlvVNrIntv5KAiecRZzJIoVVjMBmGS odJx8IWWKFHTkbUTUvFJNDg3Lekznb2FqfelognhgrJfh7+0kbfpzdcficgV5EAdPyJ0 Jqhdx/v1I6nUAdJ4domAeKvZIfSpr6Vh3VHcubHFHzUMGsy1pABGKJFruJxhTRfFiU0U /90t7odUFdbc0g7SuGl6dBgKPXFoudjWN4gg1zTPmQJU5FRoWoSH6tbp7sofSS0Q1LtF dO46DPUbOJAJkxTEzeWgtG0XgmSJuQwacg/uEcbh2rm+api3LKVluINlkMQG3NNHghrD q5ow== 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=2JxJfBT4mqTTWnkuNgqYZhhygki461FFicbWyOS8kMU=; fh=GwK11QuIe+n7JbVKLoEM7AfDJaUz/IDzceyzI5NNgS8=; b=yOLpoQkp2nIafAh6tnc67ep0UhnR6TukUki1OhrM4J887TIAfw2GMDH99ht9P+TsdI TZgHsTNPC/3AJvqgV0Kb0cM3yqfRQtcKZ1KXRRtiRXDtqj77CRNgKv3IncqM1BeB5t02 93cbxqi9viTrY/SGr4HLeudsQRWmz0NZs9M55hw2vRwVwdtopm3Tqvazww1ndSUbgTfK Mox+6AOfLiG52wxNl212wIMl7MqWiTU0U513PTeknnYLCoRZWKwuYp8MGEotli+0nnl+ tnZ1rlDFFGmZt4kRdFkVaRRqPNXm1KFVKlTKy1edHh1Ex7bwYjx56pDfCM1nh13p2VVn wF9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=DmPAehzv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id mp18-20020a17090b191200b002791cef6654si12259230pjb.1.2023.10.09.15.47.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 15:47:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=DmPAehzv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 0B2D98076160; Mon, 9 Oct 2023 15:47:49 -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 S1378931AbjJIWrn (ORCPT + 99 others); Mon, 9 Oct 2023 18:47:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378893AbjJIWrk (ORCPT ); Mon, 9 Oct 2023 18:47:40 -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 71939A6 for ; Mon, 9 Oct 2023 15:47:38 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-59f61a639b9so77443127b3.1 for ; Mon, 09 Oct 2023 15:47:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696891657; x=1697496457; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=2JxJfBT4mqTTWnkuNgqYZhhygki461FFicbWyOS8kMU=; b=DmPAehzvoTwkKdspLj51IBwSEzAFLp6fjnm20o3YJ/KuILkutjMKDgPEHiJ2qpCrAh wO7ncqUy8274bSTlhusCsAnGQ70FtjMznmruxDj7lWKaQBbMnSOkaKXO/pl44IiqAhsP XsvIcI+2d1uLlLLrUqdoQ4Gqdx5bTe3xL4ZcLCLaVVWTITDVqXgUouLG0vopNvSBhc8a kDWUynDXQamaethdZsg5I592cMmLhEu6FHLe9QFCuljCYHlp7jB0aJ31DP4OqTfbhgxa tgMLcDS4V/luRjx7R8pfkZ5/gw1TfmkqVO+e/5hSKGDeZxeTQ9f1x0y/PjDIwH9C6xOh Mtbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696891657; x=1697496457; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=2JxJfBT4mqTTWnkuNgqYZhhygki461FFicbWyOS8kMU=; b=JLlU5NNKkGEHWX+8HTOEYukrXofsbHGBHN7Im/wsbhMyeU6TkgTunHzvM/ZLE29SOl OIbsEqeO6lG7X/BQH3NBdySMcZdMNOKYk7wakmpsivwO0Kx+2n2FBpPw5JXc2bELkXlX nh331m21w/oMm/HeA+NrNVHb8dhE+7NyrgC7V797l0bdbE2R7UCNlkXFI9X7UkJsbX5u zpyUhck+nN9krVsQMNHZXlAHEU05dNQqNfnMpXQ3E6yNo4g9K5kl1UNXG70BYZTQF+Xj pA/aIs9PHsiQqeRpig/GYO44UzY47nnsnMxsjSgDO0PWKX1ZgPfZ2GTMJj+BNYotSmUe pLxA== X-Gm-Message-State: AOJu0Yy269wq0f4zyK8h6jIMc4JP3znqAgXQKpeI+vTdud430FYzzUGK sdwFfVx+ktK416N82fxigueWGhWg+ZP4AlpSxQ== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a05:690c:2a0f:b0:5a7:aa51:c08e with SMTP id ei15-20020a05690c2a0f00b005a7aa51c08emr38184ywb.1.1696891657694; Mon, 09 Oct 2023 15:47:37 -0700 (PDT) Date: Mon, 09 Oct 2023 22:47:37 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAAiDJGUC/x3NQQrCQAxA0auUrA2kLQ7qVcTFkKQaLNOSDEUpv buDy7f5f4dQNw24dTu4bha2lIb+1AG/cnkqmjTDQMPYE10xqhdevyhum3pg0YoSGV3zXPWNXuf LmBLy4oqMiTJNJMJnZmjR1XWyz394fxzHDzHi6qqAAAAA X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1696891656; l=1743; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=wtw1m2N4k6i9bXVmmrVL0qb6WJmJ01VqahgGi3xl8qU=; b=KSLRqEm2ZqeXXCS1E3PZL8ukrOE9+X+1GQ0FA+gBqwC/r+hSaMsJlHCmEWNAH5+mcSDLOMho1 qP2UVgg2jHxC9Qn+PsWDNqkGJi73jv5FRKqRIWkKFdYvO/bGMOrfOqe X-Mailer: b4 0.12.3 Message-ID: <20231009-strncpy-drivers-net-dsa-realtek-rtl8366-core-c-v1-1-74e1b5190778@google.com> Subject: [PATCH] net: dsa: realtek: 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 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]); Mon, 09 Oct 2023 15:47:49 -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/rtl8366-core.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/net/dsa/realtek/rtl8366-core.c b/drivers/net/dsa/realtek/rtl8366-core.c index dc5f75be3017..b13766a3acbb 100644 --- a/drivers/net/dsa/realtek/rtl8366-core.c +++ b/drivers/net/dsa/realtek/rtl8366-core.c @@ -395,16 +395,13 @@ void rtl8366_get_strings(struct dsa_switch *ds, int port, u32 stringset, uint8_t *data) { struct realtek_priv *priv = ds->priv; - struct rtl8366_mib_counter *mib; int i; if (port >= priv->num_ports) return; for (i = 0; i < priv->num_mib_counters; i++) { - mib = &priv->mib_counters[i]; - strncpy(data + i * ETH_GSTRING_LEN, - mib->name, ETH_GSTRING_LEN); + ethtool_sprintf(&data, "%s", priv->mib_counters[i].name); } } EXPORT_SYMBOL_GPL(rtl8366_get_strings); --- base-commit: cbf3a2cb156a2c911d8f38d8247814b4c07f49a2 change-id: 20231009-strncpy-drivers-net-dsa-realtek-rtl8366-core-c-60a0f0ddc5cc Best regards, -- Justin Stitt