From patchwork Wed Feb 13 19:12:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 1041548 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="bR8aR38b"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 4408LY3DQFz9s1l for ; Thu, 14 Feb 2019 06:13:09 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732944AbfBMTNI (ORCPT ); Wed, 13 Feb 2019 14:13:08 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:40265 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726384AbfBMTNH (ORCPT ); Wed, 13 Feb 2019 14:13:07 -0500 Received: by mail-wm1-f68.google.com with SMTP id q21so3618846wmc.5 for ; Wed, 13 Feb 2019 11:13:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=wstDew/WDcOPTQqrG4xKmosenQTBnHfR/YddfGheNN0=; b=bR8aR38bmDjUWYeIdEvXuC49/V7zUiiSzufe35EDXok9Hw8WC8fK0g5u3twXY+YhNd 019UrnFhHJs0YPGOmONCWGvrKLop6Sloe13fKhQ09XLXttRR0uwT7y18sNb8KMOtT9Vn U/IdKpzSiUW4/bXHNOGXX5T8XAJli3D+bZgj/6yHEDa3L2M+62zVjaS5k3Ef+Szb4Zt7 7+6xvkYqxn2kyiepmcLFmHzgtcDSrxtngeGS8rOhKIeH/yt8eqyG+B01b6n0JGHujWDb A8AwNMpZJ5zy+WSRzA32aDPzB63HyENcA5j9UJsAxadqIUKm3s6wGMMVP1ys/8bTvjpd jaHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=wstDew/WDcOPTQqrG4xKmosenQTBnHfR/YddfGheNN0=; b=h/dslb7qsZ2gxXOD8KLHnBFwGKxjeDQ4qSa1mhOciRhY8sceMLLM2xkxKrHUK0uCCv IzbrS7TvrqAU8d8dJKwhdCgyZTYSr18OpAvj7+dkitCdpdp2iJLiTpZsTBS4c8PfQXFa SPx1C496/PWnVypWnMOiG7NuISqedN/5qGxzOY0G6VLwCSK+Zd5vPsAkHRqYR6EBDRK1 7KbJSaZJR4YINkePbQrfasdaa03x6XdruScYqjo0YStudAP9jbJ85g7zpCzkNcI0Wb40 AECRwZFejE0REpu1pnnKYOv9XSiRT/hslrxNT5Jky1u9oyg/h8GsJoz2OG+jzXNJuPuK IrAA== X-Gm-Message-State: AHQUAuaA+/higmt0apWMM4/GbY6h3A+Sihd/6GSuDgQpuhCP3jVHw163 Ty2TynqWwCNAVFvsMrZGYbyf2jG3 X-Google-Smtp-Source: AHgI3IZTY259Gpa2jfrzPWFdzgDh8Zl+2OkXvyi87u11Xiq6Tubwixwt+Cjrf3a7JA5H6FPiNj4wJw== X-Received: by 2002:a7b:c2a9:: with SMTP id c9mr1633089wmk.44.1550085185002; Wed, 13 Feb 2019 11:13:05 -0800 (PST) Received: from ?IPv6:2003:ea:8bf1:e200:a96a:7a3b:9f9b:531c? (p200300EA8BF1E200A96A7A3B9F9B531C.dip0.t-ipconnect.de. [2003:ea:8bf1:e200:a96a:7a3b:9f9b:531c]) by smtp.googlemail.com with ESMTPSA id j33sm41943wre.91.2019.02.13.11.13.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Feb 2019 11:13:04 -0800 (PST) Subject: [PATCH net 2/2] net: phy: fix potential race in the phylib state machine From: Heiner Kallweit To: Andrew Lunn , Florian Fainelli , David Miller Cc: Russell King - ARM Linux , "netdev@vger.kernel.org" References: <2a39271d-3b9e-e425-98b4-b2a24074e806@gmail.com> Message-ID: <1094ff3a-0d7a-dc96-8a19-a5102e08fa79@gmail.com> Date: Wed, 13 Feb 2019 20:12:54 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0 MIME-Version: 1.0 In-Reply-To: <2a39271d-3b9e-e425-98b4-b2a24074e806@gmail.com> Content-Language: en-US Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Russell reported the following race in the phylib state machine (quoting from his mail): if (phy_polling_mode(phydev) && phy_is_started(phydev)) phy_queue_state_machine(phydev, PHY_STATE_TIME); state = PHY_UP thread 0 thread 1 phy_disconnect() +-phy_is_started() phy_is_started() | `-phy_stop() +-phydev->state = PHY_HALTED `-phy_stop_machine() `-cancel_delayed_work_sync() phy_queue_state_machine() `-mod_delayed_work() At this point, the phydev->state_queue() has been added back onto the system workqueue despite phy_stop_machine() having been called and cancel_delayed_work_sync() called on it. Fix this by protecting the complete operation in thread 0. Fixes: 2b3e88ea6528 ("net: phy: improve phy state checking") Reported-by: Russell King - ARM Linux admin Signed-off-by: Heiner Kallweit Reviewed-by: Florian Fainelli --- drivers/net/phy/phy.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 602816d70281..c5675df5fc6f 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -985,8 +985,10 @@ void phy_state_machine(struct work_struct *work) * state machine would be pointless and possibly error prone when * called from phy_disconnect() synchronously. */ + mutex_lock(&phydev->lock); if (phy_polling_mode(phydev) && phy_is_started(phydev)) phy_queue_state_machine(phydev, PHY_STATE_TIME); + mutex_unlock(&phydev->lock); } /**