Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2265151ybl; Thu, 19 Dec 2019 10:40:27 -0800 (PST) X-Google-Smtp-Source: APXvYqyrcdDiIGIeH7QpslGjH0Fu7C8OQwAhLLbMaJ7pz7WlgIBDB93A40Y85eLyAGz2y9nKJ4Nl X-Received: by 2002:a05:6830:2102:: with SMTP id i2mr8475037otc.123.1576780827345; Thu, 19 Dec 2019 10:40:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576780827; cv=none; d=google.com; s=arc-20160816; b=vcuXYIMN8P73Br6z3K46wt44osDODQA7NnxIZz7otBOHnTTZDrXSNwzkOdDAnwK+tp bSijHDl965Vx1Sx5tfHyG7adiFuatvPvNy1mnHho9DDmS/pkqXHNDl1Q417E63m8uol3 T1p7F03h1XvusewOkT6fjdK35q9GXyIJ1CVlIZmu+XfDIYiKd50z9R6c/eJ1kSdYaC8b 9cUwBmkCvGIbfVsMSyVjegD+WyY1MN2Sa2CEj1NT69iApDJuGEPnI6zXJd5ha8rsXtE4 YEunEqfrbE5CPp0h7Qj+34xT+45+BJoCdbld7R3XKEVET0sH285lUgrcqEp6vB2HpVEP BvCQ== 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=wD24ljEkp/yAkIoTkBDX3vnnrZn2e3Jkh/ndQl6O2f8=; b=TfEPVWKQBI75UhcbN220ogAtDsBW+zK+6dgL+xdT8Bt1Y4LN22btqPvVGrrc5GZyu1 De8DLb5zAlwU57K5x6xmF9MT8tstut2NRzCtRtIpZCXhQvnF43sIOpRxW9af+3o/fUlj 1q0TRjdQZpmTM20TmGbBSlHJx+HED91mZTJDBFTK6uabhlP91GIy423jveaD2U0rYdgn 8Z5gr64c39bFz2FHPVCzTn7eAysqFVHcHZW2CtXbHQCvynU1AmS4l4z7XrEb9e+E1XQV agl503Kqv2yysrh2wPpb+HcyEl43zgs4dmUVhMg1IVXdkN5hHj2U4kVvakbgYW5FM8gF Fh7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=B12UgAR3; 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 r10si3699437otn.241.2019.12.19.10.40.16; Thu, 19 Dec 2019 10:40:27 -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=@kernel.org header.s=default header.b=B12UgAR3; 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 S1727990AbfLSSiN (ORCPT + 99 others); Thu, 19 Dec 2019 13:38:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:56092 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727982AbfLSSiL (ORCPT ); Thu, 19 Dec 2019 13:38:11 -0500 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 5D7182467B; Thu, 19 Dec 2019 18:38:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576780690; bh=3ZyAPUm1rma+krZZR9nHCMrR33Sf/hOUqdACeRulWU8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B12UgAR3Cwp4oZu7aJckRtCsU98n+9BeMTMApU+dUIA+Q9mV5hTyu5invl3/Q6uT/ tyEkKmdbc37JtMgEhO4uUtLea9cMRrlNv/xDaCH+O4upPPiVKZWbQu0diMhopEikFU SZWCxxPE/EZqX2O61IvZe0S8YAlZwzL5viu6bJA4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wei Wang , Zhang Rui Subject: [PATCH 4.4 070/162] thermal: Fix deadlock in thermal thermal_zone_device_check Date: Thu, 19 Dec 2019 19:32:58 +0100 Message-Id: <20191219183212.081144679@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191219183150.477687052@linuxfoundation.org> References: <20191219183150.477687052@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: Wei Wang commit 163b00cde7cf2206e248789d2780121ad5e6a70b upstream. 1851799e1d29 ("thermal: Fix use-after-free when unregistering thermal zone device") 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. [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: 1851799e1d29 ("thermal: Fix use-after-free when unregistering thermal zone device") Cc: stable@vger.kernel.org Signed-off-by: Wei Wang Signed-off-by: Zhang Rui Signed-off-by: Greg Kroah-Hartman --- drivers/thermal/thermal_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -402,7 +402,7 @@ static void thermal_zone_device_set_poll mod_delayed_work(system_freezable_wq, &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) @@ -2002,7 +2002,7 @@ void thermal_zone_device_unregister(stru mutex_unlock(&thermal_list_lock); - thermal_zone_device_set_polling(tz, 0); + cancel_delayed_work_sync(&tz->poll_queue); if (tz->type[0]) device_remove_file(&tz->device, &dev_attr_type);