Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1069652ybl; Wed, 14 Aug 2019 10:12:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqw8URVPgj+n3FRy2PKLIhkYhFNxp810/cQ+LxefCv16jvYtwMSiIU8JZCutiREvrL/11KP7 X-Received: by 2002:aa7:8c4c:: with SMTP id e12mr1009651pfd.258.1565802747213; Wed, 14 Aug 2019 10:12:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565802747; cv=none; d=google.com; s=arc-20160816; b=HWpYKJIYzexdKr71gl3xn+fyDkWOLGWvNikfVgBe/rw1g/yNmKWRZKpbEGFbiuitpm wmDY5LO7BYXE1XGKDNiH71j2f7hHZreaY8rj2wq67XPTQT7p+eOpp9tmlk0zYpgEW2WM k6IE/vefQd2hwtIM7pzHFdwlQaMOEVxpRzbrZlCdS5tV5E7Mn3Z4A5+dIOcMAfz7uKrF BsNsUjYzOEW/TZDP1fuRtTQ+tqIAAo8Xcfd9nMssoCRa4ffHsMIAvcb6k5rUlmvn0rjY IuMwjzY0UTix9ckecYKRhIfQtqJ7ADXB7AMkJotA/foZxT9a1TVv85vSi2qowIr46K8b FdGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/dkPuw7cvKZ4pZrO/p7J5pi7sGd4hDcOD65fnqufbN8=; b=HleaX3el3Wd/57A6f69W80tTdMUF7SAWOtLvt2lNnLecZLpVufda6F/tfanFWXmxOB awGNVZ0spEm8PCoMOIA7Iy+DjTCeauHGFvGXQPpygK4uSQLDEep4rXb28Tf+7W6cs8tQ aJO8a/b6NFhx0Wx3pf4M3lgTCqb+rI4u9jrxOxHX36Uo4Be3YK2cwodi9xnSYkyxsBN9 haMWFBpJONyWeFmXSUCXbw+L/vam/fQ1XVJM7pB2MFflHr1GBVEqkuyW9rFyrTwFVvJv uQ2cQj440R88ke/qcRAQq2sfbQFLKGJ1gkn6PkL/24ZZEMHMly5LCMfDmLG38JSqQETp I4jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Zv/vWS+D"; 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 g5si233503plp.435.2019.08.14.10.12.11; Wed, 14 Aug 2019 10:12:27 -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; dkim=pass header.i=@kernel.org header.s=default header.b="Zv/vWS+D"; 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 S1730472AbfHNRKW (ORCPT + 99 others); Wed, 14 Aug 2019 13:10:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:32830 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730129AbfHNRKO (ORCPT ); Wed, 14 Aug 2019 13:10:14 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CDEDB21721; Wed, 14 Aug 2019 17:10:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565802613; bh=z+l4k8YVxe4Yc6ZWRwN/1i/2eo+/MBIo06KInJLfnGw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zv/vWS+DZFEKYODviMCXFeT+7t0GTbZsWCIltCeyL/ngirERFhUdlvfS5QCdLer1x tevAq1AAeJSpysv7cyWOUK1V9RG20eYAQp4j7nToDnvigEUsHGiBajYBj3Av3tN3o0 pyH7ecL7e9QoRFbePgTu6Qpo9LMLL2bDGX5b0JpU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wen Yang , Viresh Kumar , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 4.19 50/91] cpufreq/pasemi: fix use-after-free in pas_cpufreq_cpu_init() Date: Wed, 14 Aug 2019 19:01:13 +0200 Message-Id: <20190814165751.692297707@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190814165748.991235624@linuxfoundation.org> References: <20190814165748.991235624@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit e0a12445d1cb186d875410d093a00d215bec6a89 ] The cpu variable is still being used in the of_get_property() call after the of_node_put() call, which may result in use-after-free. Fixes: a9acc26b75f6 ("cpufreq/pasemi: fix possible object reference leak") Signed-off-by: Wen Yang Acked-by: Viresh Kumar Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- drivers/cpufreq/pasemi-cpufreq.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/drivers/cpufreq/pasemi-cpufreq.c b/drivers/cpufreq/pasemi-cpufreq.c index c7710c149de85..a0620c9ec0649 100644 --- a/drivers/cpufreq/pasemi-cpufreq.c +++ b/drivers/cpufreq/pasemi-cpufreq.c @@ -145,10 +145,18 @@ static int pas_cpufreq_cpu_init(struct cpufreq_policy *policy) int err = -ENODEV; cpu = of_get_cpu_node(policy->cpu, NULL); + if (!cpu) + goto out; + max_freqp = of_get_property(cpu, "clock-frequency", NULL); of_node_put(cpu); - if (!cpu) + if (!max_freqp) { + err = -EINVAL; goto out; + } + + /* we need the freq in kHz */ + max_freq = *max_freqp / 1000; dn = of_find_compatible_node(NULL, NULL, "1682m-sdc"); if (!dn) @@ -185,16 +193,6 @@ static int pas_cpufreq_cpu_init(struct cpufreq_policy *policy) } pr_debug("init cpufreq on CPU %d\n", policy->cpu); - - max_freqp = of_get_property(cpu, "clock-frequency", NULL); - if (!max_freqp) { - err = -EINVAL; - goto out_unmap_sdcpwr; - } - - /* we need the freq in kHz */ - max_freq = *max_freqp / 1000; - pr_debug("max clock-frequency is at %u kHz\n", max_freq); pr_debug("initializing frequency table\n"); @@ -212,9 +210,6 @@ static int pas_cpufreq_cpu_init(struct cpufreq_policy *policy) return cpufreq_generic_init(policy, pas_freqs, get_gizmo_latency()); -out_unmap_sdcpwr: - iounmap(sdcpwr_mapbase); - out_unmap_sdcasr: iounmap(sdcasr_mapbase); out: -- 2.20.1