Received: by 10.213.65.68 with SMTP id h4csp5151imn; Mon, 19 Mar 2018 17:34:46 -0700 (PDT) X-Google-Smtp-Source: AG47ELsHKPFivrwQ+zXlZJTve93BXrvGPgERW5epOOuHbGVHubED/Cs3gconN+oBwIS9W6UTZaVC X-Received: by 2002:a17:902:6589:: with SMTP id c9-v6mr9989526plk.215.1521506086178; Mon, 19 Mar 2018 17:34:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521506086; cv=none; d=google.com; s=arc-20160816; b=J78hCpJcCl9VfpTBg8OA/ZFo3PqQED5IXKM135aTmDdzKQeJdzmkM8dTNbkCQ9QWhL B9LS6RvoVnpUZTiBh9IZv0HiNQYZL6KfCYLBizPEvkUrNL1OFoW2QnY8iQ7qOnDdnSV/ uLCd7BK+OIGpDOv5dTEohqodSh2P4ozvK8SfYffbmY9TwJbNzLl/bFy/QL5smByTfYNT b/eh9Gj8AwfIKiCiQZMvErs8pZYTxaRgvDo+jP4DyoUVo+GWWpAAoJLNvhNkngVFJZR1 Y+YGMzDKWTfrgxiYyEWXg0zSjbsgZQPH7VAVZfj5G7z7U0c9PVrGrXekfrqVeXJfmUQM YeUA== 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=Y/xC9kEXQHVHh5DpR4pUf69y6tTR958p2Xgsfq1JU1o=; b=NPWyHPK5b4E/ya3XNciqot3K/wgZ7eYB8xgdAwZd1fdM2TN0eFguXwVErrIpl2Ild4 MdEFIxU06KFEm4E5lIMuIKqI9NhUB5sCxwdlWE44jXG48omHBOyUFpLBFQuqhYPX4eRK wemtaOVoPDheNS6kzHOhdq5oZ+Lm7DAQk1aZScWdounEq+dNnhtkcwB6IGpoDytegJu0 Bmc0f4fQ/S1UiJhrsE3z6IE7WkkTL+7ak1N9DE+yQ/50kXr1LPSjWzS1Nsxv1Zdy1YI7 sBCNqmDZ7lfXgAwYsuAYXO4XqJKH9LgxXBvkFv+1cVjF6yo3NIapMSvuOqUrmJVeEODf ocUg== 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 k73si289621pgc.707.2018.03.19.17.34.31; Mon, 19 Mar 2018 17:34:46 -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 S969027AbeCSSP5 (ORCPT + 99 others); Mon, 19 Mar 2018 14:15:57 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:44786 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S968955AbeCSSPw (ORCPT ); Mon, 19 Mar 2018 14:15:52 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id B56801152; Mon, 19 Mar 2018 18:15:51 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Rafael J. Wysocki" , Viresh Kumar , Sasha Levin Subject: [PATCH 4.4 092/134] cpufreq: Fix governor module removal race Date: Mon, 19 Mar 2018 19:06:15 +0100 Message-Id: <20180319171902.578082436@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319171849.024066323@linuxfoundation.org> References: <20180319171849.024066323@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.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: "Rafael J. Wysocki" [ Upstream commit a8b149d32b663c1a4105273295184b78f53d33cf ] It is possible to remove a cpufreq governor module after cpufreq_parse_governor() has returned success in store_scaling_governor() and before cpufreq_set_policy() acquires a reference to it, because the governor list is not protected during that period and nothing prevents the governor from being unregistered then. Prevent that from happening by acquiring an extra reference to the governor module temporarily in cpufreq_parse_governor(), under cpufreq_governor_mutex, and dropping it in store_scaling_governor(), when cpufreq_set_policy() returns. Note that the second cpufreq_parse_governor() call site is fine, because it only cares about the policy member of new_policy. Signed-off-by: Rafael J. Wysocki Acked-by: Viresh Kumar Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/cpufreq/cpufreq.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -551,6 +551,8 @@ static int cpufreq_parse_governor(char * *governor = t; err = 0; } + if (t && !try_module_get(t->owner)) + t = NULL; mutex_unlock(&cpufreq_governor_mutex); } @@ -669,6 +671,10 @@ static ssize_t store_scaling_governor(st return -EINVAL; ret = cpufreq_set_policy(policy, &new_policy); + + if (new_policy.governor) + module_put(new_policy.governor->owner); + return ret ? ret : count; }