]> git.baikalelectronics.ru Git - kernel.git/commit
mISDN: fix use-after-free bugs in l1oip timer handlers
authorDuoming Zhou <duoming@zju.edu.cn>
Wed, 28 Sep 2022 13:39:38 +0000 (21:39 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Oct 2022 11:22:25 +0000 (13:22 +0200)
commit9e4696e7d36d77ca6191a73a9f502adb2eee31fc
tree99f86c5b9a7efee4225eb7ecc24a703fcb1ffc5a
parente744b90901c7f7fa8f08901f22e073f88f45ceec
mISDN: fix use-after-free bugs in l1oip timer handlers

[ Upstream commit bc274242030378eecbfe656d0c6f867edd30b2f8 ]

The l1oip_cleanup() traverses the l1oip_ilist and calls
release_card() to cleanup module and stack. However,
release_card() calls del_timer() to delete the timers
such as keep_tl and timeout_tl. If the timer handler is
running, the del_timer() will not stop it and result in
UAF bugs. One of the processes is shown below:

    (cleanup routine)          |        (timer handler)
release_card()                 | l1oip_timeout()
 ...                           |
 del_timer()                   | ...
 ...                           |
 kfree(hc) //FREE              |
                               | hc->timeout_on = 0 //USE

Fix by calling del_timer_sync() in release_card(), which
makes sure the timer handlers have finished before the
resources, such as l1oip and so on, have been deallocated.

What's more, the hc->workq and hc->socket_thread can kick
those timers right back in. We add a bool flag to show
if card is released. Then, check this flag in hc->workq
and hc->socket_thread.

Fixes: f5842134c3d2 ("Add layer1 over IP support")
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/isdn/mISDN/l1oip.h
drivers/isdn/mISDN/l1oip_core.c