From patchwork Wed Apr 19 05:28:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 97590 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp159090qgf; Tue, 18 Apr 2017 22:30:42 -0700 (PDT) X-Received: by 10.84.196.100 with SMTP id k91mr1517235pld.165.1492579841905; Tue, 18 Apr 2017 22:30:41 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 63si1298751pgi.231.2017.04.18.22.30.41; Tue, 18 Apr 2017 22:30:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759676AbdDSFak (ORCPT + 6 others); Wed, 19 Apr 2017 01:30:40 -0400 Received: from mail-pg0-f53.google.com ([74.125.83.53]:33464 "EHLO mail-pg0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759808AbdDSFah (ORCPT ); Wed, 19 Apr 2017 01:30:37 -0400 Received: by mail-pg0-f53.google.com with SMTP id 63so7406385pgh.0 for ; Tue, 18 Apr 2017 22:30:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=R/nCdBoYFzlttycp21aPwBW7xgWIZPpWNbAyzQbNzcA=; b=jFyG8ehwzoLgfi6VwPRPDB9oU4QFnvybN78u2DGx1XhovabIjtXiS8nRPg/NfSX2St P42fx8RGEAj0xUBHPZbCN9iiVAKIobgla0/NVeXF5hwgqwHd9D85EjRdV1lcYpnd68WC sIQxgrAy3y15PuF4PKjqZCW1mzepfptVRYcos= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=R/nCdBoYFzlttycp21aPwBW7xgWIZPpWNbAyzQbNzcA=; b=aeRMW1US8orYA6EiIjypUtHD/tHkEmg64vpLEMwrjKNrASbGtJrP/akO19jLqwzWIy cvSpO7uMvIyIu4Lw4MSU0k+W1bYPd7boX5EyCY45uCoiOqzjYNWE+T+BqfzCTMUU0v2e k4Kbp6q1mJ/8p5foW+g0OUMAb7LE/y7wEalivwmYcwzjbRl139E2SZ9GNmgw6t8PV9fD eWW9zP/wtVXG0MVbsbWociOHsN8DrVpoCcq7MgR13Rda2vcJJuqGUhojaxh7vqOjO35k 3amI6xUSlq/yXNRmkYjzL4YFnxiFW1V4BdkjjXg3XYbLdo2+KouCH8qIn8b4a2HFGLEo Uq9g== X-Gm-Message-State: AN3rC/5iSAQe/e9L4ARLHe3AiajBql+kNPxN7ZHGF9MtY1vzVhVwkYfV MysugI0gLSRA0RI9 X-Received: by 10.99.1.138 with SMTP id 132mr1204361pgb.236.1492579837086; Tue, 18 Apr 2017 22:30:37 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id d3sm1667272pgc.37.2017.04.18.22.30.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Apr 2017 22:30:36 -0700 (PDT) From: Viresh Kumar To: Javi Merino , Zhang Rui , Eduardo Valentin , Lukasz Luba , Amit Daniel Kachhap , Viresh Kumar Cc: linaro-kernel@lists.linaro.org, Rafael Wysocki , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , Punit Agrawal , "4 . 2+" Subject: [PATCH V3 01/17] thermal: cpu_cooling: Avoid accessing potentially freed structures Date: Wed, 19 Apr 2017 10:58:56 +0530 Message-Id: X-Mailer: git-send-email 2.12.0.432.g71c3a4f4ba37 In-Reply-To: References: In-Reply-To: References: Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org After the lock is dropped, it is possible that the cpufreq_dev gets freed before we call get_level() and that can cause kernel to crash. Drop the lock after we are done using the structure. Cc: 4.2+ # 4.2+ Fixes: 02373d7c69b4 ("thermal: cpu_cooling: fix lockdep problems in cpu_cooling") Signed-off-by: Viresh Kumar --- drivers/thermal/cpu_cooling.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) -- 2.12.0.432.g71c3a4f4ba37 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 69d0f430b2d1..be29489dd247 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -153,8 +153,10 @@ unsigned long cpufreq_cooling_get_level(unsigned int cpu, unsigned int freq) mutex_lock(&cooling_list_lock); list_for_each_entry(cpufreq_dev, &cpufreq_dev_list, node) { if (cpumask_test_cpu(cpu, &cpufreq_dev->allowed_cpus)) { + unsigned long level = get_level(cpufreq_dev, freq); + mutex_unlock(&cooling_list_lock); - return get_level(cpufreq_dev, freq); + return level; } } mutex_unlock(&cooling_list_lock);