From patchwork Tue Apr 25 10:27:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 98185 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp1879637qgf; Tue, 25 Apr 2017 03:28:06 -0700 (PDT) X-Received: by 10.98.102.153 with SMTP id s25mr28469854pfj.257.1493116086529; Tue, 25 Apr 2017 03:28:06 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x8si21910231plm.99.2017.04.25.03.28.06; Tue, 25 Apr 2017 03:28:06 -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 S1429537AbdDYK1t (ORCPT + 6 others); Tue, 25 Apr 2017 06:27:49 -0400 Received: from mail-pf0-f169.google.com ([209.85.192.169]:33251 "EHLO mail-pf0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1429486AbdDYK1d (ORCPT ); Tue, 25 Apr 2017 06:27:33 -0400 Received: by mail-pf0-f169.google.com with SMTP id a188so25110844pfa.0 for ; Tue, 25 Apr 2017 03:27:33 -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=xdlkp0d/Wl5FBZc7FOz0cYv8c3a2qgYNRohnkblWy2Y=; b=Rd3Y6uCSIIArPGAizr6SNi8/SSErHAvFVBD1jbOxRua3BaWtktsKbI5Gsrv9yACgzN TN2e2nv3k/q5aQgcRgrQCqGswN9/1NRLWE8tzK4i33CgPPCDIRwP6TR1lIMH8Yp1qLiY 751Ks2P5LKwKeldAgMabINl3Kb9Km6R86nW5U= 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=xdlkp0d/Wl5FBZc7FOz0cYv8c3a2qgYNRohnkblWy2Y=; b=P03l0a0IwowZNY2SEg6U06EWNtgjecCfmCsF/fVB88fCpYIfuDZ73W82Cp9Khkq2PY ZED3V1Fk46gRjQCS66URX+ieKnLnCt1HAeeG1BBVvZjkj7inGxRBBk9J5vo94XRhR1Sf VUfbuwxX966XdgdeDevw3lK21QFUG2v68s4PBCAKOLHvn2Fcp86oUTzieeJ5slpa7BJA UsnQw9CvZv68nh8gBCHOLP4meb8KS5drshrUbLt/8jG24oFOSUtGN3I8wKjZuRiZ3f/H 00qidZw+1FTPQ7t9X4GAruB1Apm7dyB74/FRoTQMquwDxqCRyozzH/x8khRi3jpFpN92 bIkQ== X-Gm-Message-State: AN3rC/7BFdnYhZPwfpTJlZ3OLt3OEgDpAAqZSA1pcFAmk3OVosICT40t qy0C0aIjbQNg83Th X-Received: by 10.84.174.131 with SMTP id r3mr37753832plb.136.1493116051967; Tue, 25 Apr 2017 03:27:31 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id 76sm21715499pgf.28.2017.04.25.03.27.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Apr 2017 03:27:31 -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 V4 01/17] thermal: cpu_cooling: Avoid accessing potentially freed structures Date: Tue, 25 Apr 2017 15:57:08 +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 Tested-by: Lukasz Luba --- 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);