Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1271266rwl; Wed, 12 Apr 2023 10:18:41 -0700 (PDT) X-Google-Smtp-Source: AKy350ZnUB3NLScOIHzUpF0Q/QjJe5oZADTmNi8KU5cdzqMxO8m0VLeRrtHDsrc3xEfIktfyXrt+ X-Received: by 2002:a17:903:2452:b0:1a6:3def:6007 with SMTP id l18-20020a170903245200b001a63def6007mr10415493pls.7.1681319921422; Wed, 12 Apr 2023 10:18:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681319921; cv=none; d=google.com; s=arc-20160816; b=VV9T5uuFXtrzUGJTLlifyf2o0m8hxoSTQYFSxxEYk65OlbtU3tDigTaNusxK0DkXfm qm6wp/yqIvbm6LnIzjVsPsPCj7IfwvFotTBiH+RVcIRL35XqjaxRka3PzOOX0qFIKeg0 /7t6EcclzjKgYWNx2ZHAYhezBH0SRE4SJfEFmk1bZ6+n9eNotN7pTBjoQwR2w54EE1bh faQzqANlgBFY36z9jWlz78ZQQkVYZ33F+DFkCrGoiYAx8tCtmTZoV2UsLaHrLf49NWjZ wgLBJov4hfDb3hs47sBdS4qrUuJJvHSkwLX+oodRxFmDLGJ5RigOYuMid4IG+P/q+1ui KKpw== 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:dkim-signature; bh=Ndk4FAvmShVgKPq5Bqqn4zjD3nCFuFesf1eKwaUQ9VQ=; b=NGcWUC3OlGg0urBG3siUSrPbo1MP6gd4vGJSEsHLLtpnKiYD9XpgDAciVPwWhSJ3cs 6uPiPWlEYG15w6Jl2qG44Gbn32LNcaF39Nr4UXzIMfv0ebNvefxl9huTLAZWJ2f60mqY 6Y6finAPStLrDXygOTMiqY7WBG+JKgIDxn+8o8bl9emfDzX/U0M7slrBNusIEh6zgzQ5 Q4jziuRzy9yljyGY+bcPiPbwzWwIrq3rsoa+rASt1HzdBo+mqi3h0re4MfgCLVnP1vGP IiZ1ervxO6MnoDsjCp2N4+o1joYQrYps1igu8UHyekztPny16ONptuMC6Pp5+lAdEH99 9FiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=CDdTCeui; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jk23-20020a170903331700b001a675f1625csi1322438plb.519.2023.04.12.10.18.29; Wed, 12 Apr 2023 10:18:41 -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=@163.com header.s=s110527 header.b=CDdTCeui; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231392AbjDLRRG (ORCPT + 99 others); Wed, 12 Apr 2023 13:17:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230281AbjDLRRE (ORCPT ); Wed, 12 Apr 2023 13:17:04 -0400 Received: from m12.mail.163.com (m12.mail.163.com [220.181.12.214]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4548B2D54; Wed, 12 Apr 2023 10:16:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=Ndk4F AvmShVgKPq5Bqqn4zjD3nCFuFesf1eKwaUQ9VQ=; b=CDdTCeuiVAiAlf0/ajVoc yPEHs/vnUPmKhUfANerzxZqvstN3/UqRTqxvH+pSzGKHt9nYr6JoyL7CDPmfdlHj 2B1GnrAaOcPdCAxjZZtldxeh+5k19N74Pm3B8njlBwJJZ2oyBTBMc13wvmpG+xL2 iVpSUNgq8mkcyz9jYukUuc= Received: from leanderwang-LC2.localdomain (unknown [111.206.145.21]) by zwqz-smtp-mta-g3-0 (Coremail) with SMTP id _____wAnh08C5zZkPAgtBQ--.24056S2; Thu, 13 Apr 2023 01:14:42 +0800 (CST) From: Zheng Wang To: srinivas.pandruvada@linux.intel.com Cc: jikos@kernel.org, benjamin.tissoires@redhat.com, rafael@kernel.org, hdegoede@redhat.com, gregkh@linuxfoundation.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, hackerzheng666@gmail.com, 1395428693sheep@gmail.com, alex000young@gmail.com, Zheng Wang Subject: [PATCH] HID: intel-ish-hid: pci-ish: Fix use after free bug in ish_remove due to race condition Date: Thu, 13 Apr 2023 01:14:41 +0800 Message-Id: <20230412171441.18958-1-zyytlz.wz@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: _____wAnh08C5zZkPAgtBQ--.24056S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7uFW3uw45CF1fXF4kAry5urg_yoW8Gr1kpF 4aqFy5Cr95XryIkw4kCay5CFyrZ340g3yYgrZ7Gw17XF13uF1DtFy8KFy8WryxXFs5X3yY 9r1xt3yUCFyUZF7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0ziIzuAUUUUU= X-Originating-IP: [111.206.145.21] X-CM-SenderInfo: h2113zf2oz6qqrwthudrp/1tbiXQxOU1WBpNItegABs4 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 In ish_probe, it calls ish_dev_init to init the device. In this function, ishtp_device_init is called and &dev->bh_hbm_work is bound with bh_hbm_work_fn. recv_hbm may be called to start the timer work. If we remove the module which will call ish_remove to make cleanup, there may be an unfinished work. The possible sequence is as follows: Fix it by canceling the work before cleanup in ishtp_bus_remove_all_clients CPU0 CPUc1 |bh_hbm_work_fn ish_remove | ishtp_bus_remove_all_clients | kfree(ishtp_dev->fw_clients); | | |&dev->fw_clients[...] | //use Fixes: 3703f53b99e4 ("HID: intel_ish-hid: ISH Transport layer") Signed-off-by: Zheng Wang --- drivers/hid/intel-ish-hid/ishtp/bus.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/hid/intel-ish-hid/ishtp/bus.c b/drivers/hid/intel-ish-hid/ishtp/bus.c index 81385ab37fa9..ada7cd08dbeb 100644 --- a/drivers/hid/intel-ish-hid/ishtp/bus.c +++ b/drivers/hid/intel-ish-hid/ishtp/bus.c @@ -744,6 +744,7 @@ void ishtp_bus_remove_all_clients(struct ishtp_device *ishtp_dev, */ } spin_unlock_irqrestore(&ishtp_dev->cl_list_lock, flags); + cancel_work_sync(&ishtp_dev->bh_hbm_work); /* Release DMA buffers for client messages */ ishtp_cl_free_dma_buf(ishtp_dev); -- 2.25.1