From patchwork Mon May 18 17:36:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 225609 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=-6.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,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 72DFAC433E1 for ; Mon, 18 May 2020 18:22:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 49B8020657 for ; Mon, 18 May 2020 18:22:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589826164; bh=BGrUQXV/yqAhlRe7H5uRdVG7HYZS4HWVg5llJ9rmNZ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=TEekvrIjEWcV1jDaYOyUDRRunYTOeudiCmJ6Byvl1gdF0dWqIwScBE3XusY7zSxIo aHfKmW2JuvgsgCmdFSmfBqW+u1IfhomePrt8A820stHmVLiTC/OtVs5gvUQcO7rLBo WumbHuc/BiukDxe5+LXBP1vCngzQ6z+8mSnu+rA8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730185AbgERSWk (ORCPT ); Mon, 18 May 2020 14:22:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:52240 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730643AbgERRuM (ORCPT ); Mon, 18 May 2020 13:50:12 -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 0258C20715; Mon, 18 May 2020 17:50:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589824212; bh=BGrUQXV/yqAhlRe7H5uRdVG7HYZS4HWVg5llJ9rmNZ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RaPoVRr9iVvTCxDaw48YFsuy4Br8pDvvf2ccmy+z/vEjAh2NfweyvdmPSrAXFd50l 8dtUhl3nWvxRjEvYJJWDkxHJFrvTqxyG18W+KdiBnkUAVkfy3lRHDBQime/l5wbOWL 4erSdQEDh/BKVOs+v0lYt30x+iqcFvkW36H/uwNM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Florian Fainelli , "David S. Miller" Subject: [PATCH 4.14 080/114] net: phy: micrel: Use strlcpy() for ethtool::get_strings Date: Mon, 18 May 2020 19:36:52 +0200 Message-Id: <20200518173516.999983111@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200518173503.033975649@linuxfoundation.org> References: <20200518173503.033975649@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Florian Fainelli commit 55f53567afe5f0cd2fd9e006b174c08c31c466f8 upstream. Our statistics strings are allocated at initialization without being bound to a specific size, yet, we would copy ETH_GSTRING_LEN bytes using memcpy() which would create out of bounds accesses, this was flagged by KASAN. Replace this with strlcpy() to make sure we are bound the source buffer size and we also always NUL-terminate strings. Fixes: 2b2427d06426 ("phy: micrel: Add ethtool statistics counters") Signed-off-by: Florian Fainelli Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/phy/micrel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/net/phy/micrel.c +++ b/drivers/net/phy/micrel.c @@ -674,8 +674,8 @@ static void kszphy_get_strings(struct ph int i; for (i = 0; i < ARRAY_SIZE(kszphy_hw_stats); i++) { - memcpy(data + i * ETH_GSTRING_LEN, - kszphy_hw_stats[i].string, ETH_GSTRING_LEN); + strlcpy(data + i * ETH_GSTRING_LEN, + kszphy_hw_stats[i].string, ETH_GSTRING_LEN); } }