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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B612FC433F5 for ; Mon, 1 Nov 2021 09:38:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9DAA760232 for ; Mon, 1 Nov 2021 09:38:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233713AbhKAJki (ORCPT ); Mon, 1 Nov 2021 05:40:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:43582 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233646AbhKAJhr (ORCPT ); Mon, 1 Nov 2021 05:37:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4468C61353; Mon, 1 Nov 2021 09:26:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1635758802; bh=L0e9MjlUSI+T7GeM+QozspY/hywwhA4+PDtzbxM3ylQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tBF6lM5JSJr5Fv/DnVUdkmkPb5Bp7YHSKm+2PgzPN9Zdx5iANoU3ev4ub0nMoehHf FYkeDZOl4BUPEupTpuTbvjAakbl3PMOMjgOC7Oms+vo/QLbe74Wl3jkrwPgVzCyKit hptKno0Pr24Zb55SfxMjdGOTVl4WOI5VQ+JItiFc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Walter Stoll , Andrew Lunn , "David S. Miller" Subject: [PATCH 5.10 64/77] phy: phy_ethtool_ksettings_set: Lock the PHY while changing settings Date: Mon, 1 Nov 2021 10:17:52 +0100 Message-Id: <20211101082525.050743740@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211101082511.254155853@linuxfoundation.org> References: <20211101082511.254155853@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Andrew Lunn commit af1a02aa23c37045e6adfcf074cf7dbac167a403 upstream. There is a race condition where the PHY state machine can change members of the phydev structure at the same time userspace requests a change via ethtool. To prevent this, have phy_ethtool_ksettings_set take the PHY lock. Fixes: 2d55173e71b0 ("phy: add generic function to support ksetting support") Reported-by: Walter Stoll Suggested-by: Walter Stoll Tested-by: Walter Stoll Signed-off-by: Andrew Lunn Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/phy/phy.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -814,6 +814,7 @@ int phy_ethtool_ksettings_set(struct phy duplex != DUPLEX_FULL))) return -EINVAL; + mutex_lock(&phydev->lock); phydev->autoneg = autoneg; if (autoneg == AUTONEG_DISABLE) { @@ -830,8 +831,9 @@ int phy_ethtool_ksettings_set(struct phy phydev->mdix_ctrl = cmd->base.eth_tp_mdix_ctrl; /* Restart the PHY */ - phy_start_aneg(phydev); + _phy_start_aneg(phydev); + mutex_unlock(&phydev->lock); return 0; } EXPORT_SYMBOL(phy_ethtool_ksettings_set);