From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS, T_DKIMWL_WL_HIGH,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1762C04A6B for ; Mon, 6 May 2019 14:52:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AA1112053B for ; Mon, 6 May 2019 14:52:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557154339; bh=j9uIuOGdPePJDP+T4YPSAsgoFD0uVap6l6TEKzSmE88=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=wJjWjhaq6T1Q7UmI/xwsPzE2aIIOgl7q8RKEmkoYB5mUJOIXK172GFyn9dW4WgH7Y dc0xNfqVfu/LGayKYhXLFdX8T1YQ5j/t9HK4IURh2RZpufDUgtbi7TOBxksug/FgK6 3J3BbZqTdQQF8FdJ44lZv1xuV4wT2ILXZuwkOAHA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728638AbfEFOs2 (ORCPT ); Mon, 6 May 2019 10:48:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:48816 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728367AbfEFOs1 (ORCPT ); Mon, 6 May 2019 10:48:27 -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 1DF132053B; Mon, 6 May 2019 14:48:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557154106; bh=j9uIuOGdPePJDP+T4YPSAsgoFD0uVap6l6TEKzSmE88=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ibxoVMNVdhTbNGgWgVt8asm9VQJKbTjyJWAxtU95omlPi1eK+cnGkmjHcBqaF1KCz 20GdHDKThsM9+hh7gXlyVWG41CrPk9iE7+ttLLq0O33TC2Ng6wuthvLaHd4KwZkaks fWbOck8/eqtOwK8rYRvVAA6han2nx7dELp+qIOTs= 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.9 07/62] net: phy: marvell: Fix buffer overrun with stats counters Date: Mon, 6 May 2019 16:32:38 +0200 Message-Id: <20190506143051.730821046@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190506143051.102535767@linuxfoundation.org> References: <20190506143051.102535767@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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 @@ -1429,9 +1429,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++) { memcpy(data + i * ETH_GSTRING_LEN, marvell_hw_stats[i].string, ETH_GSTRING_LEN); } @@ -1470,9 +1471,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); }