Commit 03fc0e31 authored by Duoming Zhou's avatar Duoming Zhou Committed by Xiang Yang
Browse files

mISDN: hfcpci: Fix use-after-free bug in hfcpci_softirq

mainline inclusion
from mainline-v6.1-rc1
commit 175302f6
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/I9UNYW
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=175302f6b79ebbb207c2d58d6d3e679465de23b0



--------------------------------

The function hfcpci_softirq() is a timer handler. If it
is running, the timer_pending() will return 0 and the
del_timer_sync() in HFC_cleanup() will not be executed.
As a result, the use-after-free bug will happen. The
process is shown below:

    (cleanup routine)          |        (timer handler)
HFC_cleanup()                  | hfcpci_softirq()
 if (timer_pending(&hfc_tl))   |
   del_timer_sync()            |
 ...                           | ...
 pci_unregister_driver(hc)     |
  driver_unregister            |  driver_for_each_device
   bus_remove_driver           |   _hfcpci_softirq
    driver_detach              |   ...
     put_device(dev) //[1]FREE |
                               |    dev_get_drvdata(dev) //[2]USE

The device is deallocated is position [1] and used in
position [2].

Fix by removing the "timer_pending" check in HFC_cleanup(),
which makes sure that the hfcpci_softirq() have finished
before the resource is deallocated.

Fixes: 009fc857 ("mISDN: fix possible use-after-free in HFC_cleanup()")
Signed-off-by: default avatarDuoming Zhou <duoming@zju.edu.cn>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarXiang Yang <xiangyang3@huawei.com>
parent c96c2b4f
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -2350,7 +2350,6 @@ HFC_init(void)
static void __exit
HFC_cleanup(void)
{
	if (timer_pending(&hfc_tl))
	del_timer_sync(&hfc_tl);

	pci_unregister_driver(&hfc_driver);