Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1073062ybl; Wed, 14 Aug 2019 10:15:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqzLOKvur3uBslXGpvgQoLAzALCPhSFgDRSmm5Q3PnFZ9+fkCHS7LN/Oj6x9YZmQR7/6NTQf X-Received: by 2002:a17:902:1aa:: with SMTP id b39mr411288plb.333.1565802931521; Wed, 14 Aug 2019 10:15:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565802931; cv=none; d=google.com; s=arc-20160816; b=D3JHXOLEMVIwYJS2fQE9UyXO65t4+LnH8pMGIlgfmHlsXsUmZLWn9pZ6v1Mv1UZobq JiJHF8jhnrU1qL8ZOJlSsdfC7eBvrXxK2tPGD0VGK8HZByfpjAfs13r6im8dyCDqnm5h Iiaz+vk/QIoHy5yE3BdEobnLzG48IcMnCw1Z3EWnau7rjYvOTanoGcTGIkYMZN9iFxby j338zTugj44nKR5XtkZgPbwJvwZ3KufN2VACP0idkHwRq9acg/Jcxdq5Dr+k/5ixagDb 7RkgJyI3DLNCUAZ4siHP5znID25pUrBoQ8kerCJZABdxQxaYdVHQz0ovG4isddbCr1+0 PAkQ== 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=Gge1sdOIv/MoiliszOXRhzK4b+GjgfYBnhMhCb6D00I=; b=gSq4J6GpOoFiGgzbYm++UlzkbphV8B+L7uU2dzOoQ4IL9QDvl3PmX7ziIon8L0xf59 GJ23CGmS3YHV7vhsqN0SGixNUFXodQccO+kkAeW2Y6ic/hZ6E63z6fDlHlar6c53WPG1 jJmRQU02T5OMXzNK6UYdYvN5JjM0O/59gXPfcYp6tRKcIc3hY7aOx4h8A/mM4jzfio6/ l9MtqGWjlD1tACr0mPz67YpPKhqf10jPb5+27kZNetZ8FTIeTJIcLEPq4eZukf6DdQy+ 0KtqcZCaa5o7jL1/LgtB0Y7zGhxqK4nhAtg2RwzHa3fQaLNMDxKurvNkmikScO6amaxI 9SWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="l+2/ozER"; 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 t15si173623pgv.546.2019.08.14.10.15.15; Wed, 14 Aug 2019 10:15:31 -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="l+2/ozER"; 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 S1730642AbfHNRNc (ORCPT + 99 others); Wed, 14 Aug 2019 13:13:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:37786 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730888AbfHNRNb (ORCPT ); Wed, 14 Aug 2019 13:13:31 -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 E7C8220665; Wed, 14 Aug 2019 17:13:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565802810; bh=mys8FQso6TzX4lHjO1asflVuGbZOM4DUn8kKeE0Momg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l+2/ozER0xfy88szvhOFtIbIIVdkOd9s5a41z8nogm4Duic8s12YvBEzGCLPfe0Am wtkjKLktE54nJ69BJjdC+LfoURz2+sVrvPstFJDsXJ0L6S6TGiv2/MO90AGoxTU58K RxwEexgg047stXtBOLwLJnFGODQMnlu7Hane0oLo= 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.14 34/69] cpufreq/pasemi: fix use-after-free in pas_cpufreq_cpu_init() Date: Wed, 14 Aug 2019 19:01:32 +0200 Message-Id: <20190814165747.834330702@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190814165744.822314328@linuxfoundation.org> References: <20190814165744.822314328@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 8456492124f0c..d1bdd8f622476 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