Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1160847imm; Wed, 1 Aug 2018 11:11:12 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeMRGQOqGGlWMZJ73QsA2siGPRIq55rbnQ164jox7J/D/ln0gh/GCrAv+tYADhiGDn64Wgk X-Received: by 2002:a62:f0d:: with SMTP id x13-v6mr27568315pfi.123.1533147072521; Wed, 01 Aug 2018 11:11:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533147072; cv=none; d=google.com; s=arc-20160816; b=DTwoJbloUUCGNdPBKABt943b0PpAufBuHw4lJx+thZyuthW6r6dPHXiQS0bwb5C4bK 99tMF2+aKTap+ss2yIRlcwuU1UlT/WHIh05F0ZgMrwu+o+1Gqc8QTo4umKe5Yms8lw28 f3vb/hKd8cFfNnYEJ2XwXiB5f8BEb+OMMHmTkxpNv9zNV2pH2e+8hgbqTemifnAt+NXw hok0WSRTGQcHQvd211Lxw/ygZqQwrzoWChmsu2amrpbys24JUKM+Km3tvuwESAj8iAuB /sMRztQpgqmtA7jny1GTqkePny5x8oMML190LfKJQRbKA8MC3VUtJMgzEQeBZl/Ewb4F s3Ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=BG0VdT7bzqa7A3Ayb9fhi7S+YS+7v4f8IYdQeZ0R9JE=; b=zf6b3+/YT9SpTkjf5srj1IIJ/WNlMHH8DA8BSgJoUjntmWZ8CzyWXaT8kLwFJsCWIq vzNRIlqJyz9ekw/b/0PdVpRU7JTscuhQCOuXVNUP3cK31b5B0wS65LOgLWHk9hzvYk5U fcldGzys7poK/FBGo0waNlkfkcIWBJDE4Jq6LIU6LBJ4F7k6FzGYu8afTdLafyOCId0z blHPHyWKhRGQs1o/zrxjIfe7lhbH68M+0rqR0X9iR9Zp4KUVF54cGRmZcF1zJeagg6QZ oMk6igVFF6tpbyhX5sA7BKXPfsqPYjNR9n1b5VLywBusfMOabsVcDyiowJhmmTLnM/YB VTBA== ARC-Authentication-Results: i=1; mx.google.com; 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 m13-v6si16740492pgh.360.2018.08.01.11.10.58; Wed, 01 Aug 2018 11:11:12 -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; 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 S2387424AbeHAT5G (ORCPT + 99 others); Wed, 1 Aug 2018 15:57:06 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:49794 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405732AbeHATIf (ORCPT ); Wed, 1 Aug 2018 15:08:35 -0400 Received: from localhost (D57E6652.static.ziggozakelijk.nl [213.126.102.82]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id CB09113D7; Wed, 1 Aug 2018 17:16:13 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Hellwig , Bjorn Helgaas , Johannes Thumshirn , Keith Busch , Sasha Levin Subject: [PATCH 4.14 088/246] PCI: Prevent sysfs disable of device while driver is attached Date: Wed, 1 Aug 2018 18:49:58 +0200 Message-Id: <20180801165015.925372188@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801165011.700991984@linuxfoundation.org> References: <20180801165011.700991984@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Christoph Hellwig [ Upstream commit 6f5cdfa802733dcb561bf664cc89d203f2fd958f ] Manipulating the enable_cnt behind the back of the driver will wreak complete havoc with the kernel state, so disallow it. Signed-off-by: Christoph Hellwig Signed-off-by: Bjorn Helgaas Reviewed-by: Johannes Thumshirn Acked-by: Keith Busch Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/pci/pci-sysfs.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -305,13 +305,16 @@ static ssize_t enable_store(struct devic if (!capable(CAP_SYS_ADMIN)) return -EPERM; - if (!val) { - if (pci_is_enabled(pdev)) - pci_disable_device(pdev); - else - result = -EIO; - } else + device_lock(dev); + if (dev->driver) + result = -EBUSY; + else if (val) result = pci_enable_device(pdev); + else if (pci_is_enabled(pdev)) + pci_disable_device(pdev); + else + result = -EIO; + device_unlock(dev); return result < 0 ? result : count; }