From patchwork Mon Oct 17 13:09:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 216 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1439273wrs; Mon, 17 Oct 2022 06:11:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM573OS11Ze4/F80p1f/2FyiAXwp1Uwy78O+o8Am5Da+VNW80JBII6qKsJYqR3hkyt7XOW/G X-Received: by 2002:a17:90b:3d8:b0:20a:8e90:8e8c with SMTP id go24-20020a17090b03d800b0020a8e908e8cmr13398960pjb.138.1666012309623; Mon, 17 Oct 2022 06:11:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666012309; cv=none; d=google.com; s=arc-20160816; b=Y/O+0sGkv5ExliqnbRUqSPZn5pByi7Dl72xGQdx2871Z/O3BRfc2i8l5WMN/T6aKSc qjfAYuWNnsSOsx/q2vy3ywfo4A8kVUnm5mZllquMpTID6UzZjS9hvMWfv/+He4yKCTm6 QgNgudlNqHYS0yJkBujB0pNmmuMKKxiGT5oVHsPZxW6U1esp9dr7Ixw5uOYwyhxN0ke5 jVqHoYNBlGVcrkf9T39Ay6Fq4UjBbs2LgDHNDHA3KqHePxQcgD9rXoF0OTIS78/fLwyi rrXaLaJPGIvHyUv89G1CKG7rmFC+6KnlKQh4/uEqz3j713g42DP6NCfzTyOVT0XDI/si IJbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=asfx+wgkxvJPbTs13K/0EwEbD7Yq5Qo6s+tsNBTt1s8=; b=RDIk41Hr9eX+Sbv6oReLqCe250Qh2v5mA17ds2ZPdYOYZJI6F+XRek+mPIP1FUGTUr YeUtAg0w+9A43g9WFcgWQ5Av84gxUEAiowP1fbWHySUMxVxpJzVNP2d4+1CBzZ4UM+yC hY2y1BSNujYp+p2dfbJE546jMRPgpHsgeEIGyHZNi8LYy5nB08WH6PbT7PIe6kVju8pP 8zFrh1TgzcS2ZebHLAJ+n1Qx4hPx4QjFcugDDniveZxaoMKNR0dnVzhRhbheyar9y/Np ytPozsCNizrPeU16pYgfJqMLOvOiRfYoyRfWfKdY6gSmz5fKmZfccw0mWbm+3LVJU3PU pwRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=QV3Lq2NY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g66-20020a636b45000000b00462848edc12si11937777pgc.809.2022.10.17.06.11.03; Mon, 17 Oct 2022 06:11:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=QV3Lq2NY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229913AbiJQNJ1 (ORCPT + 99 others); Mon, 17 Oct 2022 09:09:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229801AbiJQNJT (ORCPT ); Mon, 17 Oct 2022 09:09:19 -0400 Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9E98C50; Mon, 17 Oct 2022 06:09:14 -0700 (PDT) Received: by mail-oi1-x22d.google.com with SMTP id n130so12006667oia.6; Mon, 17 Oct 2022 06:09:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc:subject:date:message-id:reply-to; bh=asfx+wgkxvJPbTs13K/0EwEbD7Yq5Qo6s+tsNBTt1s8=; b=QV3Lq2NYdMmnxtyeg6kYTKhOuLkISsgy8JIab5P9gHsVp20UGbmq++4PM1/Hwj01y8 4uodYGCTFmo4WgvKzZcw/5jNrmEaCRpPgMFUemijjBReRkp4i/HVbXyPCalDtW5MX3vG ebydNoXULTjYKq9DukZ6Y3B/cUeE/fSO/MEOrUxolBnL45Gk/L1scu5kgiXaTtsMYPP1 x4DFSG4A6fQNZivwhaP94rB7RLMQvn6sCVaVi08PvZ0zDjTGETDMGSbW42SO7rtUwj5w nfyiQ/JvX97EwoKT3Z4SgEld0cAWEvcHrB46DSQWIdseqHKprs4RyRuxle+CVwNJxYxl SKDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=asfx+wgkxvJPbTs13K/0EwEbD7Yq5Qo6s+tsNBTt1s8=; b=XMx+llYP7z5Nv4Nt941xREJXrD+5bg7HzYwHjXcnyl88obBQM41B2+x+yIymBisdCR PYmpYbn4QmeRuK431OknNZh2ulQxG705lWH0XH0q8fbiDoMyS2cmFi+v/8WWxOQXa4/y 0tRstJRIj3GKLnLsQK/in1EpEbAhkghBRYcurEem/tNn7XS3gxo1pqU6wf2Njp84srtx CldnBXF40g4+RUFnUuj2Fmnv8buOnn6VqeMyqC+5+TeOz7e4937lwAORFA1GbMQJX1f9 CngrSG/Kzyaf5DST6LpQ8AUvuC6eJdUVzLwv/0/UwKOTNiLXDZyv4gIqDRE+qWf6VaOE R3sQ== X-Gm-Message-State: ACrzQf10sZ5tm6VkzjShnunBDd/rFtbP0eV6YTJMV6bShtaSqPNuROIL Bgd/9G7kXcA9Le0TsyCS2Ts= X-Received: by 2002:a54:4001:0:b0:355:385e:c07b with SMTP id x1-20020a544001000000b00355385ec07bmr2302726oie.36.1666012154049; Mon, 17 Oct 2022 06:09:14 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id r41-20020a056808212900b0034fd36e95bfsm4311478oiw.31.2022.10.17.06.09.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 06:09:13 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: "Rafael J . Wysocki" Cc: Daniel Lezcano , Amit Kucheria , Zhang Rui , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Guenter Roeck Subject: [PATCH 0/9] thermal/core: Protect thermal device operations against removal Date: Mon, 17 Oct 2022 06:09:01 -0700 Message-Id: <20221017130910.2307118-1-linux@roeck-us.net> X-Mailer: git-send-email 2.36.2 MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746940523559450543?= X-GMAIL-MSGID: =?utf-8?q?1746940523559450543?= Accesses to thermal zones, and with it to thermal zone device operations, are still possible after the thermal zone device has been unregistered. For example, thermal_zone_get_temp() can be called from temp_show() in thermal_sysfs.c if the sysfs attribute was opened before the thermal device was unregistered. This is problematic and may result in crashes since the operations data structure and the underlying code may be gone when the calls are made. The following series solves the problem by protecting accesses to thermal device operations with the thermal device mutex, and by verifying that the thermal device is still registered after the mutex has been acquired. This was previously sent as RFC/RFT as single patch [1]. The code was reworked to match thermal subsystem changes made between v6.0 and v6.1, and it was split into several patches to simplify review. [1] https://lore.kernel.org/linux-pm/20221004033936.1047691-1-linux@roeck-us.net/ ---------------------------------------------------------------- Guenter Roeck (9): thermal/core: Destroy thermal zone device mutex in release function thermal/core: Delete device under thermal device zone lock thermal/core: Ensure that thermal device is registered in thermal_zone_get_temp thermal/core: Move parameter validation from __thermal_zone_get_temp to thermal_zone_get_temp thermal/core: Introduce locked version of thermal_zone_device_update thermal/core: Protect hwmon accesses to thermal operations with thermal zone mutex thermal/core: Protect sysfs accesses to thermal operations with thermal zone mutex thermal/core: Remove thermal_zone_set_trips() thermal/core: Protect thermal device operations against thermal device removal drivers/thermal/thermal_core.c | 76 ++++++++++++++++++++++++-------------- drivers/thermal/thermal_core.h | 3 +- drivers/thermal/thermal_helpers.c | 65 ++++++++++++++++++++++----------- drivers/thermal/thermal_hwmon.c | 14 +++++-- drivers/thermal/thermal_sysfs.c | 77 +++++++++++++++++++++++++++++++++------ 5 files changed, 169 insertions(+), 66 deletions(-)