Skip to content

Commit 2568a7e

Browse files
stonezdmdavem330
authored andcommitted
mISDN: fix use-after-free bugs in l1oip timer handlers
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]>
1 parent 6ad1c94 commit 2568a7e

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

drivers/isdn/mISDN/l1oip.h

Lines changed: 1 addition & 0 deletions
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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ l1oip_socket_send(struct l1oip *hc, u8 localcodec, u8 channel, u32 chanmask,
275275
p = frame;
276276

277277
/* restart timer */
278-
if (time_before(hc->keep_tl.expires, jiffies + 5 * HZ))
278+
if (time_before(hc->keep_tl.expires, jiffies + 5 * HZ) && !hc->shutdown)
279279
mod_timer(&hc->keep_tl, jiffies + L1OIP_KEEPALIVE * HZ);
280280
else
281281
hc->keep_tl.expires = jiffies + L1OIP_KEEPALIVE * HZ;
@@ -601,7 +601,9 @@ l1oip_socket_parse(struct l1oip *hc, struct sockaddr_in *sin, u8 *buf, int len)
601601
goto multiframe;
602602

603603
/* restart timer */
604-
if (time_before(hc->timeout_tl.expires, jiffies + 5 * HZ) || !hc->timeout_on) {
604+
if ((time_before(hc->timeout_tl.expires, jiffies + 5 * HZ) ||
605+
!hc->timeout_on) &&
606+
!hc->shutdown) {
605607
hc->timeout_on = 1;
606608
mod_timer(&hc->timeout_tl, jiffies + L1OIP_TIMEOUT * HZ);
607609
} else /* only adjust timer */
@@ -1232,11 +1234,10 @@ release_card(struct l1oip *hc)
12321234
{
12331235
int ch;
12341236

1235-
if (timer_pending(&hc->keep_tl))
1236-
del_timer(&hc->keep_tl);
1237+
hc->shutdown = true;
12371238

1238-
if (timer_pending(&hc->timeout_tl))
1239-
del_timer(&hc->timeout_tl);
1239+
del_timer_sync(&hc->keep_tl);
1240+
del_timer_sync(&hc->timeout_tl);
12401241

12411242
cancel_work_sync(&hc->workq);
12421243

0 commit comments

Comments
 (0)