Received: by 10.213.65.68 with SMTP id h4csp473884imn; Fri, 16 Mar 2018 08:51:12 -0700 (PDT) X-Google-Smtp-Source: AG47ELuCdTXYjA6MFn8nw13oWrsQCnEUbxwb8SFbaN+4JfmS3aLXKcYmJ2+8NR0GyHcGY+LAayL+ X-Received: by 10.98.206.1 with SMTP id y1mr1990334pfg.196.1521215472405; Fri, 16 Mar 2018 08:51:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521215472; cv=none; d=google.com; s=arc-20160816; b=uOqWai3TWb3mW6KPcuiwyFXTi/jISG6nGwZKkZsVY+mYbHu37GPXo5VQWBcoukbSE/ Ugcs+emhMU5VN0t/w6opVsY0VSapySZQhmj1g0gy0SZTPxzpOufA04cOxn5eCxX8QwGL N8GZVNVP0C9jNhNyF3QYDm8tDJIVCQD3qX+o+MRVO4U4s9MKG8/OwdWoq3UhRxVxpcKn awAtUeksbx1my+3aKq/Iuyo1jJ+Uf+4Ee/XuzZvirQWujDzUQGmhuetvAm59ljYXhZ6R hpC34lZUmDKAgWmKaqCsWicTAdQ0m19F9K3KkKfLLNiHAMctzmHywfm7NqcLk3CWvuOH CTvQ== 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=krizd8V4gWSxAhx4q0OGrizbtycx97prRk3N6E99zIQ=; b=mIUf5MuufSmvzVANt14Lty/XT1Caxpv6IhKOdcchje3PhEq/izoTt5nP+/qthEanVr kEDU3SH4BNkVkM5C7hJplWiZ/Z315rhKG2ZX95VO2FdjifufIieQKRDu/M+wmTBraNHo jbyAjKwbNIRURBDQTci3E5n1spqf3bBCBQao0poOCD5fdr7tfEvpGEhinMWGas+5ruQJ iJiEUm7tYzjUlj7qijRW5ZwE08cVbHj0XmAa4Nosm5XCCxcxWCkcj6FUryV7UgF1eXz1 IsjMD91SrF4s1tfKKqkxvbRmOAjg7BpG3PT4JVGxFP67WDtiPCwpdYq3abdzwHdLMI6+ YNgQ== 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 bb12-v6si6225669plb.164.2018.03.16.08.50.57; Fri, 16 Mar 2018 08:51: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 S964977AbeCPPsK (ORCPT + 99 others); Fri, 16 Mar 2018 11:48:10 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46098 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965433AbeCPPom (ORCPT ); Fri, 16 Mar 2018 11:44:42 -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 EACB7F1A; Fri, 16 Mar 2018 15:44:41 +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.15 076/128] cpufreq: Fix governor module removal race Date: Fri, 16 Mar 2018 16:23:37 +0100 Message-Id: <20180316152340.471679903@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180316152336.199007505@linuxfoundation.org> References: <20180316152336.199007505@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.15-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 @@ -637,6 +637,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); } @@ -765,6 +767,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; }