Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp336275yba; Sat, 4 May 2019 03:29:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqwO+GzDyi7EwYD6rBEYXR+lmJ+pVsIuEek/Sd9vU37JCmijcqaX/7902gcGlf+MOM1r9v/p X-Received: by 2002:a62:41cd:: with SMTP id g74mr18634254pfd.216.1556965791598; Sat, 04 May 2019 03:29:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556965791; cv=none; d=google.com; s=arc-20160816; b=PSsSuDAwGAY8OL7SZNuxDKGWDkAukyip+GmU9vK6sTsH7kiOlZSaQTpAOPnR0gYE9a 6eYAuxHX5N+c9f2HBfJOQRHG2Z/fbsyOPgpBApmeKxzUKOGghpzWCerN32FuAtPdPXeK DOOb76jiyMywZjoGPbN2Uj4Tm1R+Jf/nJVAoLD96VYpTlHsJA1UfcOnVoJ6z5eKhv/AX WHZVLjio6lSxLKRtAYTXG0B+3xu51yaS35t/iFgvVDUySOF8t/NNRhrIBUx9EIYTmqLH RAo3yPTYmSjIaXEK/rlHbqwm9DpILNmM9oZBU6IamOPCOjZVnr8vi1EE2x8loFK/5a4x 966g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=eW2B5KJ42atFHPawZ4zu/QWFYDASGyQRpcxpNP/CIJU=; b=Q84pwfDss22kLIq9JI+SCxoXR2ZE/cTjIVLGmx6S0SSbeVsVhBr3tuhCDPHdoa/3FK vF2m5aipR68Yl2+gd1ccs+4DiiRSnFXew9I6YLxgvOQR2IKfjGfeBoGVyrJdjhnWG+SZ xnXcIZ44TgoaR09j1C2veh1uQIppEgiAqnVVxWLuEdXqJJbNSVNeD2WVZPT7Lq5yu7RL l+p7XmmeMCHpxDyV8GUu5F6T/LIMJtHLLBkOf5qg+nffxBZ4WhV6pAEGNj6w8DnBWx9F 1RRYtMBQPV46m62B59SlQbDv33CXvDysE+MoF6TpwTCmeBBElxce7Q5NxpvSVRz4cOLf 2pUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Fv0gC/+h"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d11si6605972pgj.84.2019.05.04.03.29.36; Sat, 04 May 2019 03:29:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Fv0gC/+h"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728398AbfEDK2M (ORCPT + 99 others); Sat, 4 May 2019 06:28:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:38710 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727656AbfEDK2A (ORCPT ); Sat, 4 May 2019 06:28:00 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E3A6B20862; Sat, 4 May 2019 10:27:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556965679; bh=WFS88EiI+PETvXFOkUQbVWA8h6wva8dWzl4HlfrSz2w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fv0gC/+hazwQla6Ahx/vSr+0SIetUsXxDRVUcfULreuDCtg3xdpB0LDtwYWuqIdEb 2oVtye6gB6ghCoaIQCjRXizNrGFgqMu4xyGZZGgyyRb75fO7A6gdyyw6jTzzfiDNYQ iAwuLu3OdEthynYCz6Mqbs44Gx001rPhxIAdYGag= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrew Lunn , Florian Fainelli , "David S. Miller" Subject: [PATCH 4.19 09/23] net: phy: marvell: Fix buffer overrun with stats counters Date: Sat, 4 May 2019 12:25:11 +0200 Message-Id: <20190504102451.858845315@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190504102451.512405835@linuxfoundation.org> References: <20190504102451.512405835@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrew Lunn [ Upstream commit fdfdf86720a34527f777cbe0d8599bf0528fa146 ] marvell_get_sset_count() returns how many statistics counters there are. If the PHY supports fibre, there are 3, otherwise two. marvell_get_strings() does not make this distinction, and always returns 3 strings. This then often results in writing past the end of the buffer for the strings. Fixes: 2170fef78a40 ("Marvell phy: add field to get errors from fiber link.") Signed-off-by: Andrew Lunn Reviewed-by: Florian Fainelli Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/phy/marvell.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/drivers/net/phy/marvell.c +++ b/drivers/net/phy/marvell.c @@ -1513,9 +1513,10 @@ static int marvell_get_sset_count(struct static void marvell_get_strings(struct phy_device *phydev, u8 *data) { + int count = marvell_get_sset_count(phydev); int i; - for (i = 0; i < ARRAY_SIZE(marvell_hw_stats); i++) { + for (i = 0; i < count; i++) { strlcpy(data + i * ETH_GSTRING_LEN, marvell_hw_stats[i].string, ETH_GSTRING_LEN); } @@ -1543,9 +1544,10 @@ static u64 marvell_get_stat(struct phy_d static void marvell_get_stats(struct phy_device *phydev, struct ethtool_stats *stats, u64 *data) { + int count = marvell_get_sset_count(phydev); int i; - for (i = 0; i < ARRAY_SIZE(marvell_hw_stats); i++) + for (i = 0; i < count; i++) data[i] = marvell_get_stat(phydev, i); }