* [PATCH] HID: intel-ish-hid: pci-ish: Fix use after free bug in ish_remove due to race condition
@ 2023-04-12 17:14 Zheng Wang
2023-04-12 17:18 ` Zheng Hacker
2023-04-25 15:55 ` srinivas pandruvada
0 siblings, 2 replies; 4+ messages in thread
From: Zheng Wang @ 2023-04-12 17:14 UTC (permalink / raw)
To: srinivas.pandruvada
Cc: jikos, benjamin.tissoires, rafael, hdegoede, gregkh, linux-input,
linux-kernel, hackerzheng666, 1395428693sheep, alex000young,
Zheng Wang
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] HID: intel-ish-hid: pci-ish: Fix use after free bug in ish_remove due to race condition
2023-04-12 17:14 [PATCH] HID: intel-ish-hid: pci-ish: Fix use after free bug in ish_remove due to race condition Zheng Wang
@ 2023-04-12 17:18 ` Zheng Hacker
2023-04-25 15:55 ` srinivas pandruvada
1 sibling, 0 replies; 4+ messages in thread
From: Zheng Hacker @ 2023-04-12 17:18 UTC (permalink / raw)
To: Zheng Wang
Cc: srinivas.pandruvada, jikos, benjamin.tissoires, rafael, hdegoede,
gregkh, linux-input, linux-kernel, 1395428693sheep, alex000young
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
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] HID: intel-ish-hid: pci-ish: Fix use after free bug in ish_remove due to race condition
2023-04-12 17:14 [PATCH] HID: intel-ish-hid: pci-ish: Fix use after free bug in ish_remove due to race condition Zheng Wang
2023-04-12 17:18 ` Zheng Hacker
@ 2023-04-25 15:55 ` srinivas pandruvada
2023-04-25 17:18 ` Zheng Hacker
1 sibling, 1 reply; 4+ messages in thread
From: srinivas pandruvada @ 2023-04-25 15:55 UTC (permalink / raw)
To: Zheng Wang
Cc: jikos, benjamin.tissoires, rafael, hdegoede, gregkh, linux-input,
linux-kernel, hackerzheng666, 1395428693sheep, alex000young
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);
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] HID: intel-ish-hid: pci-ish: Fix use after free bug in ish_remove due to race condition
2023-04-25 15:55 ` srinivas pandruvada
@ 2023-04-25 17:18 ` Zheng Hacker
0 siblings, 0 replies; 4+ messages in thread
From: Zheng Hacker @ 2023-04-25 17:18 UTC (permalink / raw)
To: srinivas pandruvada
Cc: Zheng Wang, jikos, benjamin.tissoires, rafael, hdegoede, gregkh,
linux-input, linux-kernel, 1395428693sheep, alex000young
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);
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-04-25 17:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-12 17:14 [PATCH] HID: intel-ish-hid: pci-ish: Fix use after free bug in ish_remove due to race condition Zheng Wang
2023-04-12 17:18 ` Zheng Hacker
2023-04-25 15:55 ` srinivas pandruvada
2023-04-25 17:18 ` Zheng Hacker
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).