HID: intel-ish-hid: pci-ish: Fix use after free bug in ish_remove due to race condition
Message ID | 20230412171441.18958-1-zyytlz.wz@163.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp492798vqo; Wed, 12 Apr 2023 10:28:34 -0700 (PDT) X-Google-Smtp-Source: AKy350ZL3N8JM/QY794yZlD8HxysljKZwLw1gXRwppTg2iHA7WYd2eTAS/SlmlOIh+CNnI62YJxI X-Received: by 2002:aa7:da97:0:b0:505:8bf:e663 with SMTP id q23-20020aa7da97000000b0050508bfe663mr1529824eds.41.1681320513775; Wed, 12 Apr 2023 10:28:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681320513; cv=none; d=google.com; s=arc-20160816; b=YtLi7wH54VvkFWUU1QrR2HVqxDXEbYfyPhRjSoVoNMjZdbLzmiEbcw6Wr16zx5sOwO xqkp5i9A3gKBXufg8HNQt1AJHzRqA+xQM4Zz/jPWtU/uMKiE1ZEjcCdg2AS9j6GXv+6D vpa8VWfWiS40TlNHVg02MUl2wDcs9uBv21Mefoae1Z9QwW97TCPd6P0t0dALkiR3LuOY aR0hNy8pkKlXX2tpYjZhuCqgOInFgiqjsG8Rt3rq7nKr4x7Ytx8D31fu4Y5LevPlfEWt DFFICZKsDhIl62Jw3eXNpIuiNlGmpfvrrAu9LF8cGzG69oWXfeN2h1F1x5uaHvTEvCit oIOg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i16-20020aa7c710000000b0050572338dc4si737003edq.244.2023.04.12.10.28.09; Wed, 12 Apr 2023 10:28:33 -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 S231431AbjDLRRG (ORCPT <rfc822;peter110.wang@gmail.com> + 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 <rfc822;linux-kernel@vger.kernel.org>); 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 <zyytlz.wz@163.com> 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 <zyytlz.wz@163.com> 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762992338867134680?= X-GMAIL-MSGID: =?utf-8?q?1762992338867134680?= |
Series |
HID: intel-ish-hid: pci-ish: Fix use after free bug in ish_remove due to race condition
|
|
Commit Message
Zheng Wang
April 12, 2023, 5:14 p.m. UTC
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 <zyytlz.wz@163.com>
---
drivers/hid/intel-ish-hid/ishtp/bus.c | 1 +
1 file changed, 1 insertion(+)
Comments
Hi, I missed some detail in the patch. bh_hbm_work_fn will call ishtp_hbm_dispatch and access &dev->fw_clients in it. Best regards, Zheng Zheng Wang <zyytlz.wz@163.com> 于2023年4月13日周四 01:17写道: > > 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 <zyytlz.wz@163.com> > --- > 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 >
On Thu, 2023-04-13 at 01:14 +0800, Zheng Wang wrote: > 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 <zyytlz.wz@163.com> Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> It is a extremely rare case, so it is OK to not mark for stable. > --- > 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);
srinivas pandruvada <srinivas.pandruvada@linux.intel.com> 于2023年4月25日周二 23:55写道: > > On Thu, 2023-04-13 at 01:14 +0800, Zheng Wang wrote: > > 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 <zyytlz.wz@163.com> > Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> > > It is a extremely rare case, so it is OK to not mark for stable. Got it, thanks! Best regards, Zheng > > > --- > > 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); >
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);