Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp1010773ybc; Tue, 12 Nov 2019 12:44:26 -0800 (PST) X-Google-Smtp-Source: APXvYqzq31eft2KikKFmOdURMdVmwPhqTvtMTw0hWaFoUvaXYYS4uszDjD7jq+6Wjw2ymchqwG9c X-Received: by 2002:a17:906:86ca:: with SMTP id j10mr14318151ejy.200.1573591466678; Tue, 12 Nov 2019 12:44:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573591466; cv=none; d=google.com; s=arc-20160816; b=sgdamY19SDTi/S16YcShgiWQ8esesCNLgENM+t8T9zk0/gQdQNn7olVpKOdoNOTWpz nfO0uReXMR6V68I6Y2y6q89yzccEm7ZiElWGnbRI/t/LjDABVgpZYIGsTxpOc8aZv9cK sz9NRJQjLp5I2j8XRxWgS3WNiDbewlh9ex5SzsImIB/Aw1yZbBC3IfKhfSTki7AV8Ty9 KPqlbDB4ZtBEOLJo9xa8u14aYnBoIjLrbVNMLzNLz6i2e5sOvTOWCcgjsdSl7+oy7Etq x6XE3FYdKbpIfb1m8mPFv6AaRkODooAIEU5onaTjIuJSdvxanNsf/f0KrYNiAmzuxsMK tUmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:cc:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=YXQx/W19DjRT45sudkGcownKnjElC/pkN1OhsIzM96I=; b=0EreRwuKKtkqAJWLkizBioVSCqp9im+HA7FwI3dsY7USjffxJSUJW5EyyRrMAU7e9g dS8Lp5hIdNIAkESc1PsVRS5Gwd9F1/43AZ4Q+Y2NmqSTDV1SbnjyVFhtGKdRPXFkFZkv ZTkzTNf6ZTZdpImmtEnXYLiPn+sFVFAJBzxMOMGQb6Oe/MK0byfhqb2LeIPzCLw4yivE 0aGMgOmXW2oa4K+4Me9UOe8GrRTFj6nUdxAk+rZZM1nse39eAEm95cOlR7GUcj1D7R71 eNMuLPNrX0RGUOp6c29BjvXuGPAjKDCz3y0XHqlhXOhFQt+upBwTMtu7RIS7N0Bljkvo 4Mew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=hq2cMG+U; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n19si828880ejh.172.2019.11.12.12.44.02; Tue, 12 Nov 2019 12:44:26 -0800 (PST) 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=@google.com header.s=20161025 header.b=hq2cMG+U; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727069AbfKLUm3 (ORCPT + 99 others); Tue, 12 Nov 2019 15:42:29 -0500 Received: from mail-qk1-f201.google.com ([209.85.222.201]:46317 "EHLO mail-qk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726978AbfKLUm2 (ORCPT ); Tue, 12 Nov 2019 15:42:28 -0500 Received: by mail-qk1-f201.google.com with SMTP id x186so11079222qke.13 for ; Tue, 12 Nov 2019 12:42:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:cc; bh=YXQx/W19DjRT45sudkGcownKnjElC/pkN1OhsIzM96I=; b=hq2cMG+Uz05dfP/Fx2OKks757/JeqdQlDjyT1GANKrtXZxgcX/dwHrLtCbo2nf091s vp72Z4yUGit3E53HyROAw7oK6rMU3b+NBm9EN24bTXOzxZlh/hj9Wobe800a6fwDKzvV 5+4SB0qmTSV2l0HoWmFfV28iRcuofohr3vLp9YGcdUf3Xf0T+YwwuoizwIVHYzDcT9v/ Lfxv+eaysYiuh+CUM1eAC9f9SO2h3C07FwAWlFwJU/bKj9KKJF7O5wtwt+z8WovnqXwI ZgGNYc9Ny2NsXIgZcVjAVpMO5CCZH65ufzWAI2CZS7aKLSKSE3VeNGJwbPQX1N1CK5kn xnlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:cc; bh=YXQx/W19DjRT45sudkGcownKnjElC/pkN1OhsIzM96I=; b=Ou8DrmQj+ddsprwGimxjfZt7hUCnELQguMdxofY2QO7SlTHOdpakL2cjc1PwzaAjTz 5Uruc1e0rhRs9yhtSnwJi15zVeuWLv6NS4jGZSBcxR33H7o6KT97CstBfap0DSwE/1Qt FKRN0fPH1egYpNBThcOCBpJggLtYvwAS/B2EvoSV1zs1KllxZ8uakEZaInwsIiv4UF4e J5kQmn2mJYJU4yMuvksJLT9ttbqD3k4YFkBK1uwLWe9i62tMjWjEgRo7tdNwmzu12Z92 jjnrq/1Hesecove7cGO4Ev+PpY01rtbb1r/aWe+3cr55FrB6LcBvQ+y/x5He4rixzea2 91Rg== X-Gm-Message-State: APjAAAUZSmgjPjHi6M8HFyP5Z++h60VnveFYhWcKVO7bA1ODZH5tbJD/ hyyEfATwtaz3AQukKiHbzWHeiRI= X-Received: by 2002:a05:6214:1052:: with SMTP id l18mr29832087qvr.204.1573591347257; Tue, 12 Nov 2019 12:42:27 -0800 (PST) Date: Tue, 12 Nov 2019 12:42:23 -0800 In-Reply-To: <20191112203154.101534-1-wvw@google.com> Message-Id: <20191112204223.115589-1-wvw@google.com> Mime-Version: 1.0 References: <20191112203154.101534-1-wvw@google.com> X-Mailer: git-send-email 2.24.0.432.g9d3f5f5b63-goog Subject: [PATCH v2] thermal: Fix deadlock in thermal thermal_zone_device_check From: Wei Wang Cc: wei.vince.wang@gmail.com, Wei Wang , Zhang Rui , Eduardo Valentin , Daniel Lezcano , Amit Kucheria , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org commit [2] changed cancel_delayed_work to cancel_delayed_work_sync to avoid a use-after-free issue. However, cancel_delayed_work_sync could be called insides the WQ causing deadlock [1]. [1] [54109.642398] c0 1162 kworker/u17:1 D 0 11030 2 0x00000000 [54109.642437] c0 1162 Workqueue: thermal_passive_wq thermal_zone_device_check [54109.642447] c0 1162 Call trace: [54109.642456] c0 1162 __switch_to+0x138/0x158 [54109.642467] c0 1162 __schedule+0xba4/0x1434 [54109.642480] c0 1162 schedule_timeout+0xa0/0xb28 [54109.642492] c0 1162 wait_for_common+0x138/0x2e8 [54109.642511] c0 1162 flush_work+0x348/0x40c [54109.642522] c0 1162 __cancel_work_timer+0x180/0x218 [54109.642544] c0 1162 handle_thermal_trip+0x2c4/0x5a4 [54109.642553] c0 1162 thermal_zone_device_update+0x1b4/0x25c [54109.642563] c0 1162 thermal_zone_device_check+0x18/0x24 [54109.642574] c0 1162 process_one_work+0x3cc/0x69c [54109.642583] c0 1162 worker_thread+0x49c/0x7c0 [54109.642593] c0 1162 kthread+0x17c/0x1b0 [54109.642602] c0 1162 ret_from_fork+0x10/0x18 [54109.643051] c0 1162 kworker/u17:2 D 0 16245 2 0x00000000 [54109.643067] c0 1162 Workqueue: thermal_passive_wq thermal_zone_device_check [54109.643077] c0 1162 Call trace: [54109.643085] c0 1162 __switch_to+0x138/0x158 [54109.643095] c0 1162 __schedule+0xba4/0x1434 [54109.643104] c0 1162 schedule_timeout+0xa0/0xb28 [54109.643114] c0 1162 wait_for_common+0x138/0x2e8 [54109.643122] c0 1162 flush_work+0x348/0x40c [54109.643131] c0 1162 __cancel_work_timer+0x180/0x218 [54109.643141] c0 1162 handle_thermal_trip+0x2c4/0x5a4 [54109.643150] c0 1162 thermal_zone_device_update+0x1b4/0x25c [54109.643159] c0 1162 thermal_zone_device_check+0x18/0x24 [54109.643167] c0 1162 process_one_work+0x3cc/0x69c [54109.643177] c0 1162 worker_thread+0x49c/0x7c0 [54109.643186] c0 1162 kthread+0x17c/0x1b0 [54109.643195] c0 1162 ret_from_fork+0x10/0x18 [54109.644500] c0 1162 cat D 0 7766 1 0x00000001 [54109.644515] c0 1162 Call trace: [54109.644524] c0 1162 __switch_to+0x138/0x158 [54109.644536] c0 1162 __schedule+0xba4/0x1434 [54109.644546] c0 1162 schedule_preempt_disabled+0x80/0xb0 [54109.644555] c0 1162 __mutex_lock+0x3a8/0x7f0 [54109.644563] c0 1162 __mutex_lock_slowpath+0x14/0x20 [54109.644575] c0 1162 thermal_zone_get_temp+0x84/0x360 [54109.644586] c0 1162 temp_show+0x30/0x78 [54109.644609] c0 1162 dev_attr_show+0x5c/0xf0 [54109.644628] c0 1162 sysfs_kf_seq_show+0xcc/0x1a4 [54109.644636] c0 1162 kernfs_seq_show+0x48/0x88 [54109.644656] c0 1162 seq_read+0x1f4/0x73c [54109.644664] c0 1162 kernfs_fop_read+0x84/0x318 [54109.644683] c0 1162 __vfs_read+0x50/0x1bc [54109.644692] c0 1162 vfs_read+0xa4/0x140 [54109.644701] c0 1162 SyS_read+0xbc/0x144 [54109.644708] c0 1162 el0_svc_naked+0x34/0x38 [54109.845800] c0 1162 D 720.000s 1->7766->7766 cat [panic] Fixes commit 1851799e1d29 ("thermal: Fix use-after-free when unregistering thermal zone device") [2] Signed-off-by: Wei Wang --- drivers/thermal/thermal_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index d4481cc8958f..c28271817e43 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -304,7 +304,7 @@ static void thermal_zone_device_set_polling(struct thermal_zone_device *tz, &tz->poll_queue, msecs_to_jiffies(delay)); else - cancel_delayed_work_sync(&tz->poll_queue); + cancel_delayed_work(&tz->poll_queue); } static void monitor_thermal_zone(struct thermal_zone_device *tz) @@ -1414,7 +1414,7 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz) mutex_unlock(&thermal_list_lock); - thermal_zone_device_set_polling(tz, 0); + cancel_delayed_work_sync(&tz->poll_queue); thermal_set_governor(tz, NULL); -- 2.24.0.432.g9d3f5f5b63-goog