Skip to content

Commit 361655a

Browse files
committed
mISDN: fix use-after-free bugs in l1oip timer handlers
jira VULN-168 cve CVE-2022-3565 commit-author Duoming Zhou <[email protected]> commit 2568a7e 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: 3712b42 ("Add layer1 over IP support") Signed-off-by: Duoming Zhou <[email protected]> Reviewed-by: Leon Romanovsky <[email protected]> Signed-off-by: David S. Miller <[email protected]> (cherry picked from commit 2568a7e) Signed-off-by: Greg Rose <[email protected]>
1 parent 6fbe7a7 commit 361655a

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

drivers/isdn/mISDN/l1oip.h

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ struct l1oip {
5959
int bundle; /* bundle channels in one frm */
6060
int codec; /* codec to use for transmis. */
6161
int limit; /* limit number of bchannels */
62+
bool shutdown; /* if card is released */
6263

6364
/* timer */
6465
struct timer_list keep_tl;

drivers/isdn/mISDN/l1oip_core.c

+7-6
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ l1oip_socket_send(struct l1oip *hc, u8 localcodec, u8 channel, u32 chanmask,
289289
p = frame;
290290

291291
/* restart timer */
292-
if (time_before(hc->keep_tl.expires, jiffies + 5 * HZ))
292+
if (time_before(hc->keep_tl.expires, jiffies + 5 * HZ) && !hc->shutdown)
293293
mod_timer(&hc->keep_tl, jiffies + L1OIP_KEEPALIVE * HZ);
294294
else
295295
hc->keep_tl.expires = jiffies + L1OIP_KEEPALIVE * HZ;
@@ -615,7 +615,9 @@ l1oip_socket_parse(struct l1oip *hc, struct sockaddr_in *sin, u8 *buf, int len)
615615
goto multiframe;
616616

617617
/* restart timer */
618-
if (time_before(hc->timeout_tl.expires, jiffies + 5 * HZ) || !hc->timeout_on) {
618+
if ((time_before(hc->timeout_tl.expires, jiffies + 5 * HZ) ||
619+
!hc->timeout_on) &&
620+
!hc->shutdown) {
619621
hc->timeout_on = 1;
620622
mod_timer(&hc->timeout_tl, jiffies + L1OIP_TIMEOUT * HZ);
621623
} else /* only adjust timer */
@@ -1246,11 +1248,10 @@ release_card(struct l1oip *hc)
12461248
{
12471249
int ch;
12481250

1249-
if (timer_pending(&hc->keep_tl))
1250-
del_timer(&hc->keep_tl);
1251+
hc->shutdown = true;
12511252

1252-
if (timer_pending(&hc->timeout_tl))
1253-
del_timer(&hc->timeout_tl);
1253+
del_timer_sync(&hc->keep_tl);
1254+
del_timer_sync(&hc->timeout_tl);
12541255

12551256
cancel_work_sync(&hc->workq);
12561257

0 commit comments

Comments
 (0)