Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp244005ybl; Thu, 22 Aug 2019 23:43:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqweqlXpRgNaajfFktPtARoDsLQKILbMWexLuT2YQVxj/x5GSj6DbE94SQUiSUbCSh5UO49w X-Received: by 2002:a17:902:3204:: with SMTP id y4mr3035469plb.156.1566542621382; Thu, 22 Aug 2019 23:43:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566542621; cv=none; d=google.com; s=arc-20160816; b=ua/NoyXXdUhGMSpBs75e1iM29YvyFQ0LALD+L2HhzeZGxSUBTeoHKg49vx4KOp+ixh a18nwydJNO3geCLCs+dKJYNc+PwoBuCOOzCWnBqpfwGAyfDnHwGOBYQZLydAU7FpSQur Y9K2e+OiqZTMPLoCel1T+XNOuPVKFP3M0ZKHxT1IANfFR5j6TWWSJLvoS3kQ6uafO7fv 8PdGAY+UJDtrpiFRMICpq9NcQSgDLi5e7JPk25xVmoTafcDcu7McTD8gfQODLvZ34qKE 3tyywolAK3qv3zAjwJiuFa/sLmdHjGSLvvUqCfyhydQl0qi+AOTsB9pYSt0YHt0989x5 SYfA== 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=Qkv7B7h8bfQ+XObPjpDcjpAU4TKr7MeXP/hN8CX0QHc=; b=v30FHRSSSIPYvBFTGkdI9Rn7AHHabji1H48CCQJ9f08Nbv4+VfwVtK5NB+MbOOwaM1 AEgBIAMuGO1qbC7gU6q6Kxo6GW5J94fV+bJSnNN9iJcwp03S0iUa0uCl/cv2ZPztiQ3o LA7fW27SFiCDAdkcRcdwNXpuPNaMEINbhpbAmWV/3NFeEg5Yyef7r8J5ZZAo8/nAYH1+ nshdk+dm274jeSohu/dgdSpFMFFk/2+DQ8RZIhPwGKDM3eUMU0276+9mxtScrHq3APwv R6mixCiM2n2NQQCewFukyQeNQiLmbcWcjLFnXPmdfFA2Gz5qlPHUsBykcIzpf3Q0vc1j uY8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FGoZvzqZ; 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 c1si1650813pld.348.2019.08.22.23.43.25; Thu, 22 Aug 2019 23:43:41 -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=FGoZvzqZ; 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 S2392824AbfHVRoa (ORCPT + 99 others); Thu, 22 Aug 2019 13:44:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:42712 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403886AbfHVRXQ (ORCPT ); Thu, 22 Aug 2019 13:23:16 -0400 Received: from localhost (wsip-184-188-36-2.sd.sd.cox.net [184.188.36.2]) (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 5B65223402; Thu, 22 Aug 2019 17:23:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566494595; bh=mnf5COArq3hLz3KooqmSQrH21iA5dKmpOGBJor1o/xs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FGoZvzqZBx+haVrtVYLRkqKQSleDOX3L26rh2RQ9AYzFcrXKZc5vW8+BtQmzG0UdZ QpnWRI2/RWIABtjOmUseeYN+dKXrwYoNTTa46oHrHZuSb5fkHfVNKRNcpSZD2iy50s XKTYAl2cGC55FvwVUCVDNQHNvnvZNIUFHz3F9Toc= 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.9 016/103] cpufreq/pasemi: fix use-after-free in pas_cpufreq_cpu_init() Date: Thu, 22 Aug 2019 10:18:04 -0700 Message-Id: <20190822171729.503980454@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190822171728.445189830@linuxfoundation.org> References: <20190822171728.445189830@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 58c933f483004..991b6a3062c4f 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