From patchwork Mon Oct 9 18:29:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Stitt X-Patchwork-Id: 13414258 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DFD59CD611F for ; Mon, 9 Oct 2023 18:29:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: Mime-Version:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=w9udrO6xwYENdyyxnTM+CwXVwngj04D21kd6Dv0GcDE=; b=NsY ydA8v1MbSZ8v7SkOukNOQcmki8JglHunq9ec9ydN856g5iiAj4ucA66bpHMx8rl6T4GzmZJLkijuM Z8e7ZzRlaMxCbOFfuTh97AJHjsT9Wcs3ltHpSxaqgGJRfjsXi2UkWXSnOyEoD04XwnFYp3CwBH8ng HaNwbmqog4bnWyQcbz+dOVZGkMHPuI/ga1nzKYNM9PMa94pWoljl+S+pPneRVhKO95Ff++BTb8TwI x0aVFtHcvRW9SUJEpYuMik9CN9XnscNQ5jpUvN9CjCQB3MIpTk+UXzU6zvTbni/vYF/rD9pDYypbu gJcHfeLbm/9Z/kBTfR15LR1MazPO9lA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qpv0P-00BO9Y-1q; Mon, 09 Oct 2023 18:29:25 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qpv0M-00BO8U-0E for linux-arm-kernel@lists.infradead.org; Mon, 09 Oct 2023 18:29:23 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d81646fcf3eso6533907276.0 for ; Mon, 09 Oct 2023 11:29:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696876160; x=1697480960; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=XDBK5Er15QvjGUwykMjw01laGvht+dhKObLHHzorKRg=; b=bB3R+YUIColrXkxcsjfNYw5smLLCphDxbwzf+VJETW4tdJBrHsUpnbXcN29tw8uSBD 4/yOoLTuFB0gUL8k5835HSa6gdGvm1nBNlc4J6GSh3XzgD7j33JTCwqB5iIYLh/aNVOF yxAKLQYMQS83oBLxcOGCsdKrH0/9VaHe/TDZrqDzJx2Emoxa9OhkVw0Ds9qAnnpxwHH9 Kg8+Yvp7JkrlAF1tnldImWI5Zn/CDNfOPyuyE4Rgu2UuavlezAfIWv+iSbVe0ztEIUBq ph6f4HMQGVjp1VGeHSWazkX4k1H7tCWcImfHVuvbzSsioeJZKvkQc3mRgKoslPqIW6OF zoSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696876160; x=1697480960; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=XDBK5Er15QvjGUwykMjw01laGvht+dhKObLHHzorKRg=; b=JBgtLemzEsTdoI72AtaddQpbSEgE7Rc2UKPBI/BQIk4/Km31GgsO09v2+tEu0/iJNe BzevjqQt08d71ACtvCTaiIbYzVFvRZC204pNtrVILJJLWkC8Wbj8ZStAkiKIvmAiUPJ7 sb4O7EF3CUEQRi3qhHENvlpnqvCHKRG7E0taEFq8qGgfwBsYbVkLX4m5FNizG6jlkx2D Pvw8T9uvqYGuHkGGencJsuAVcA1SBa5Z4oDICpJ7rymfRRvJ8qa6tSb2/16ZFgw4FCWf gmEEROGNeFPQzNrJtceHpW2BAS9huU5SW30DrrMwpmNOUPpPYGn51i7BaL2P6KtVRhqx vOww== X-Gm-Message-State: AOJu0YzOHrgWup9X1NELk48IDPLLZi77NAoI8JkU/VFqALCDlT9EGC1K ULtDEwuZWSZ8kohpnMxyv6jqgM4w/MciyYAi9w== X-Google-Smtp-Source: AGHT+IFEYT/za4QVR6fR/MF5JyjgO5M3AWWvhyO5pPz0UrgbgMOrmr3zJveczQ1Hka+kDj8XsImbs1hJdUTnEIDEMA== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:ad50:0:b0:d78:2c3:e633 with SMTP id l16-20020a25ad50000000b00d7802c3e633mr230976ybe.2.1696876159847; Mon, 09 Oct 2023 11:29:19 -0700 (PDT) Date: Mon, 09 Oct 2023 18:29:19 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAH5GJGUC/x3NPQ6DMAxA4asgz7VkCNCfq6AOUexSD02RHSEQ4 u6NOn7Lewe4mIrDoznAZFXXb65oLw2kd8yzoHI1dNSFluiOXiynZUc2XcUcsxRkj/gp1yEQJuw pRQ63MA49Q80sJi/d/ovpeZ4/gDTkfnIAAAA= X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1696876158; l=1437; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=njDv3GAGmhVrExshk0hx5o9AbY/WD0+6gqoo2bn4Yhg=; b=1J2L7iU0ES7zC7vWFtN9NFGtdF0F81pv/JVQhRo8NZAZIpsJ+gGWhuCDrgOKhESE8tZUUsU3U d4Z2vnQKmFuD4VoXPdHgoaiP7YfJE2TD1dTaO5uvm7QNv0tFHL7+jAu X-Mailer: b4 0.12.3 Message-ID: <20231009-strncpy-drivers-net-dsa-mt7530-c-v1-1-ec6677a6436a@google.com> Subject: [PATCH] net: dsa: mt7530: replace deprecated strncpy with ethtool_sprintf From: Justin Stitt To: " =?utf-8?b?QXLEsW7DpyDDnE5BTA==?= " , Daniel Golle , Landen Chao , DENG Qingfang , Sean Wang , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Matthias Brugger , AngeloGioacchino Del Regno Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-hardening@vger.kernel.org, Justin Stitt X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231009_112922_108069_52FF1D1B X-CRM114-Status: GOOD ( 10.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org `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 Reviewed-by: Kees Cook Acked-by: Daniel Golle Reviewed-by: Florian Fainelli Reviewed-by: AngeloGioacchino Del Regno --- Note: build-tested only. --- drivers/net/dsa/mt7530.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) --- base-commit: cbf3a2cb156a2c911d8f38d8247814b4c07f49a2 change-id: 20231009-strncpy-drivers-net-dsa-mt7530-c-40cad383654d Best regards, -- Justin Stitt diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 035a34b50f31..e00126af8318 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -836,8 +836,7 @@ mt7530_get_strings(struct dsa_switch *ds, int port, u32 stringset, return; for (i = 0; i < ARRAY_SIZE(mt7530_mib); i++) - strncpy(data + i * ETH_GSTRING_LEN, mt7530_mib[i].name, - ETH_GSTRING_LEN); + ethtool_sprintf(&data, "%s", mt7530_mib[i].name); } static void