From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB6383B7742; Mon, 4 May 2026 14:08:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777903716; cv=none; b=WKIiTzLV1STjDcZJVw/sbrcb83g1zcG9liUY+bl76R9K/DDuUONJHDGJqjL5sap68ygJ66VXR0qWa5lYiUKAULecnWOw3NGB9pxk4tjIfXJzKTk/6tXQw12itYPDyJ+KMsqyQwkTLYsRNIEqNxsnuN87UJZNjnAXDvyFaQO2fBs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777903716; c=relaxed/simple; bh=k829WgxZKRaEG/RaxEL15Ul4To1wbxALnUYu0dNn488=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e16zvsvoqgAyNGZ56PXYJlu+4elBViCX4177Bq/Bd4kUkuDBBB7ynFm49LPSq/9TGmhcvOoJ9WWLUFy2d8mMSBSaMmYY6uCEQddH5EeR0O5w9RwphtWVIUxZcOklSjQDbczp7wNQELFyY7ErP5JToJQcAeFUGiDqgpeSTKbiRHc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=jzCewt3k; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="jzCewt3k" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 718DBC2BCB8; Mon, 4 May 2026 14:08:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1777903716; bh=k829WgxZKRaEG/RaxEL15Ul4To1wbxALnUYu0dNn488=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jzCewt3ka4cUi/XuhUf1UkDtahJbZZ2Bha7pdXkIYNYzjDkPcGVJ/ZxkYJwQA8x2m lpPzgnGqhcdbAVJ0cK6W/FEQE8Ci9wFp52HaGuVfizJBBejhcuT6wYpL+7ph5tP9ED sgVKxMqH+xm9TxGkTerb5pGdeYOZZajvFZb71NSo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Rafael J. Wysocki" Subject: [PATCH 6.18 035/275] thermal: core: Fix thermal zone governor cleanup issues Date: Mon, 4 May 2026 15:49:35 +0200 Message-ID: <20260504135144.241970685@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260504135142.929052779@linuxfoundation.org> References: <20260504135142.929052779@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Rafael J. Wysocki commit 41ff66baf81c6541f4f985dd7eac4494d03d9440 upstream. If thermal_zone_device_register_with_trips() fails after adding a thermal governor to the thermal zone being registered, the governor is not removed from it as appropriate which may lead to a memory leak. In turn, thermal_zone_device_unregister() calls thermal_set_governor() without acquiring the thermal zone lock beforehand which may race with a governor update via sysfs and may lead to a use-after-free in that case. Address these issues by adding two thermal_set_governor() calls, one to thermal_release() to remove the governor from the given thermal zone, and one to the thermal zone registration error path to cover failures preceding the thermal zone device registration. Fixes: e33df1d2f3a0 ("thermal: let governors have private data for each thermal zone") Cc: All applicable Signed-off-by: Rafael J. Wysocki Link: https://patch.msgid.link/5092923.31r3eYUQgx@rafael.j.wysocki Signed-off-by: Greg Kroah-Hartman --- drivers/thermal/thermal_core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -964,6 +964,7 @@ static void thermal_release(struct devic sizeof("thermal_zone") - 1)) { tz = to_thermal_zone(dev); thermal_zone_destroy_device_groups(tz); + thermal_set_governor(tz, NULL); mutex_destroy(&tz->lock); complete(&tz->removal); } else if (!strncmp(dev_name(dev), "cooling_device", @@ -1607,8 +1608,10 @@ thermal_zone_device_register_with_trips( /* sys I/F */ /* Add nodes that are always present via .groups */ result = thermal_zone_create_device_groups(tz); - if (result) + if (result) { + thermal_set_governor(tz, NULL); goto remove_id; + } result = device_register(&tz->device); if (result) @@ -1721,8 +1724,6 @@ void thermal_zone_device_unregister(stru cancel_delayed_work_sync(&tz->poll_queue); - thermal_set_governor(tz, NULL); - thermal_thresholds_exit(tz); thermal_remove_hwmon_sysfs(tz); ida_free(&thermal_tz_ida, tz->id);