Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp757155ybt; Fri, 19 Jun 2020 12:59:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbNojZqSqUd0aV0/LO2dtgLgl4bEfMjxgpMveLnOhqefTTLUjjiNyzcCWsD0PS2TqP6LkC X-Received: by 2002:a50:a694:: with SMTP id e20mr4886652edc.144.1592596753405; Fri, 19 Jun 2020 12:59:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592596753; cv=none; d=google.com; s=arc-20160816; b=V90An+vVKvA0n7dmq6U6bXp7JUrDwHUI2JBNfez5DSQWuQnY2ukz71mpw42u1ygd5s 2wsRR0Sj9oHov+jWrzo2g1sonoba6ncZ44TPGZ+AwwpnzQK6mILmF95fv1Oay6ncfXas bLWg/hNINC+vygAxkQmEdAkmcvbF9G4u21jBLozp1R+3+olRl78SR9zdyw1ONEb73CIk dA/mgz8JWFPGrZUVEuG85wQCU+D+h/1mYjJaC5uY3WU1VLgaSLPl6YYJ8xNKsqzbHXJ0 zO2rXESPNZegEv2kgk+J4LeHRQatvTcbg4gKCfCewhwEd6o9v2LIkCcFf68Dpt3Ml8GY G2RQ== 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=V2eKSnoQookYSRLBXa/q14v+KUwi1wbircd/L2B0nLc=; b=TOQNZOpeHyiB+jLtvKqoZldg3gV9Iy8MOLrpyRqTqBMGt828+ahLflPNTUNmgTTPgB KaKo0Irvddn0RdlVwDTSWYCYjVKfAIVTzRhPNZ0gnN30xq48nmsVwEi0HqTla0QYQ/rt OzIp+QZlXSItcHltGDEuUlC/uML1czkYpj/aMP+1uXY81y8eApQAYB70HnXO+Br95C1q A/w28DzXW4xrFFpJuKsbPeID9LL2PbCyceR8nAgY8imdaCF77EvnGOFB4N67XtDBb5F4 0ZmuCE4k19UDBmy5LIH/hp5OrI//ndKJxH/mJVuOeOc3cQ4rV0Kk+VWDowDZ2uWSuuQn qkfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="qwqOXi/g"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m3si4763135edi.593.2020.06.19.12.58.51; Fri, 19 Jun 2020 12:59:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="qwqOXi/g"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388692AbgFSOpT (ORCPT + 99 others); Fri, 19 Jun 2020 10:45:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:36448 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388640AbgFSOpE (ORCPT ); Fri, 19 Jun 2020 10:45:04 -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 014A921556; Fri, 19 Jun 2020 14:45:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592577904; bh=lC9ferR9X4gmT4FMRJp5dYkyPXSIP4zs76hVyxo4wis=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qwqOXi/gqljt8ACnt+7yKmHtRcZvLvoM1yET358bNuZx3HMdeEvvvugiHE7Nf7arT U3gLW0XAvQdts8j3JU11WE7LJc9GZaTC3PGB4elgppZ670kAS5eeospzP8Y6K/D6Od VSucUzDn15btMSMjXhyUMF/KFjCsALHUkmZjnXok= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Erhard F." , Michael Ellerman Subject: [PATCH 4.9 120/128] drivers/macintosh: Fix memleak in windfarm_pm112 driver Date: Fri, 19 Jun 2020 16:33:34 +0200 Message-Id: <20200619141626.462641831@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141620.148019466@linuxfoundation.org> References: <20200619141620.148019466@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 From: Michael Ellerman commit 93900337b9ac2f4eca427eff6d187be2dc3b5551 upstream. create_cpu_loop() calls smu_sat_get_sdb_partition() which does kmalloc() and returns the allocated buffer. In fact it's called twice, and neither buffer is freed. This results in a memory leak as reported by Erhard: unreferenced object 0xc00000047081f840 (size 32): comm "kwindfarm", pid 203, jiffies 4294880630 (age 5552.877s) hex dump (first 32 bytes): c8 06 02 7f ff 02 ff 01 fb bf 00 41 00 20 00 00 ...........A. .. 00 07 89 37 00 a0 00 00 00 00 00 00 00 00 00 00 ...7............ backtrace: [<0000000083f0a65c>] .smu_sat_get_sdb_partition+0xc4/0x2d0 [windfarm_smu_sat] [<000000003010fcb7>] .pm112_wf_notify+0x104c/0x13bc [windfarm_pm112] [<00000000b958b2dd>] .notifier_call_chain+0xa8/0x180 [<0000000070490868>] .blocking_notifier_call_chain+0x64/0x90 [<00000000131d8149>] .wf_thread_func+0x114/0x1a0 [<000000000d54838d>] .kthread+0x13c/0x190 [<00000000669b72bc>] .ret_from_kernel_thread+0x58/0x64 unreferenced object 0xc0000004737089f0 (size 16): comm "kwindfarm", pid 203, jiffies 4294880879 (age 5552.050s) hex dump (first 16 bytes): c4 04 01 7f 22 11 e0 e6 ff 55 7b 12 ec 11 00 00 ...."....U{..... backtrace: [<0000000083f0a65c>] .smu_sat_get_sdb_partition+0xc4/0x2d0 [windfarm_smu_sat] [<00000000b94ef7e1>] .pm112_wf_notify+0x1294/0x13bc [windfarm_pm112] [<00000000b958b2dd>] .notifier_call_chain+0xa8/0x180 [<0000000070490868>] .blocking_notifier_call_chain+0x64/0x90 [<00000000131d8149>] .wf_thread_func+0x114/0x1a0 [<000000000d54838d>] .kthread+0x13c/0x190 [<00000000669b72bc>] .ret_from_kernel_thread+0x58/0x64 Fix it by rearranging the logic so we deal with each buffer separately, which then makes it easy to free the buffer once we're done with it. Fixes: ac171c46667c ("[PATCH] powerpc: Thermal control for dual core G5s") Cc: stable@vger.kernel.org # v2.6.16+ Reported-by: Erhard F. Signed-off-by: Michael Ellerman Tested-by: Erhard F. Link: https://lore.kernel.org/r/20200423060038.3308530-1-mpe@ellerman.id.au Signed-off-by: Greg Kroah-Hartman --- drivers/macintosh/windfarm_pm112.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) --- a/drivers/macintosh/windfarm_pm112.c +++ b/drivers/macintosh/windfarm_pm112.c @@ -133,14 +133,6 @@ static int create_cpu_loop(int cpu) s32 tmax; int fmin; - /* Get PID params from the appropriate SAT */ - hdr = smu_sat_get_sdb_partition(chip, 0xC8 + core, NULL); - if (hdr == NULL) { - printk(KERN_WARNING"windfarm: can't get CPU PID fan config\n"); - return -EINVAL; - } - piddata = (struct smu_sdbp_cpupiddata *)&hdr[1]; - /* Get FVT params to get Tmax; if not found, assume default */ hdr = smu_sat_get_sdb_partition(chip, 0xC4 + core, NULL); if (hdr) { @@ -153,6 +145,16 @@ static int create_cpu_loop(int cpu) if (tmax < cpu_all_tmax) cpu_all_tmax = tmax; + kfree(hdr); + + /* Get PID params from the appropriate SAT */ + hdr = smu_sat_get_sdb_partition(chip, 0xC8 + core, NULL); + if (hdr == NULL) { + printk(KERN_WARNING"windfarm: can't get CPU PID fan config\n"); + return -EINVAL; + } + piddata = (struct smu_sdbp_cpupiddata *)&hdr[1]; + /* * Darwin has a minimum fan speed of 1000 rpm for the 4-way and * 515 for the 2-way. That appears to be overkill, so for now, @@ -175,6 +177,9 @@ static int create_cpu_loop(int cpu) pid.min = fmin; wf_cpu_pid_init(&cpu_pid[cpu], &pid); + + kfree(hdr); + return 0; }