From: duoming@zju.edu.cn
To: "Leon Romanovsky" <leon@kernel.org>
Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
isdn@linux-pingi.de, kuba@kernel.org
Subject: Re: [PATCH V2] mISDN: fix use-after-free bugs in l1oip timer handlers
Date: Wed, 28 Sep 2022 21:35:36 +0800 (GMT+08:00) [thread overview]
Message-ID: <548ffa37.fbc8f.183844f5a63.Coremail.duoming@zju.edu.cn> (raw)
In-Reply-To: <YzQX4mVT18TT/uoe@unreal>
Hello,
On Wed, 28 Sep 2022 12:46:10 +0300 Leon Romanovsky wrote:
> On Fri, Sep 23, 2022 at 10:25:14PM +0800, Duoming Zhou wrote:
> > 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 use del_timer_sync(&hc->keep_tl)
> > and cancel_work_sync(&hc->keep_tl) twice to stop keep_tl timer
> > and hc->workq. Then, we add del_timer_sync(&hc->timeout_tl)
> > behind l1oip_socket_close() to stop timeout_tl timer.
> >
> > Fixes: 3712b42d4b1b ("Add layer1 over IP support")
> > Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
> > ---
> > Changes in v2:
> > - Solve the problem that timers could be restarted by other threads.
> >
> > drivers/isdn/mISDN/l1oip_core.c | 11 +++++------
> > 1 file changed, 5 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/isdn/mISDN/l1oip_core.c b/drivers/isdn/mISDN/l1oip_core.c
> > index 2c40412466e..7b89d98a781 100644
> > --- a/drivers/isdn/mISDN/l1oip_core.c
> > +++ b/drivers/isdn/mISDN/l1oip_core.c
> > @@ -1232,17 +1232,16 @@ release_card(struct l1oip *hc)
> > {
> > int ch;
> >
> > - if (timer_pending(&hc->keep_tl))
> > - del_timer(&hc->keep_tl);
> > -
> > - if (timer_pending(&hc->timeout_tl))
> > - del_timer(&hc->timeout_tl);
> > -
> > + del_timer_sync(&hc->keep_tl);
> > + cancel_work_sync(&hc->workq);
> > + del_timer_sync(&hc->keep_tl);
> > cancel_work_sync(&hc->workq);
>
> It is racy, the call twice to del_timer_sync and cancel_work_sync
> doesn't solve "the problem that timers could be restarted by other
> threads."
Thank you for your reply! I will add a bool flag in struct l1oip to judge
whether the card is released and check this flag in other threads.
Best regards,
Duoming Zhou
prev parent reply other threads:[~2022-09-28 13:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-23 14:25 Duoming Zhou
2022-09-28 9:46 ` Leon Romanovsky
2022-09-28 13:35 ` duoming [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=548ffa37.fbc8f.183844f5a63.Coremail.duoming@zju.edu.cn \
--to=duoming@zju.edu.cn \
--cc=isdn@linux-pingi.de \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®