From: Matthias Brugger <matthias.bgg@gmail.com>
To: 박용배 <yongbae2@gmail.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>,
Thomas Gleixner <tglx@linutronix.de>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: null pointer dereference error in mtk_timer.c
Date: Thu, 19 Feb 2015 11:12:05 +0100 [thread overview]
Message-ID: <CABuKBeJzETCJCYu61vEnsozxcUueLvPU-vP3OkMhim+ScdTFhQ@mail.gmail.com> (raw)
In-Reply-To: <CAMaOmv5O1Qd1dN9ZaODd9EsVSX+D1f0jfJ_RhMa2R0Pxiuh6_g@mail.gmail.com>
Hi Yongbae,
2015-02-16 8:35 GMT+01:00 박용배 <yongbae2@gmail.com>:
> Hello. My name is Yongbae Park.
>
>
> I would like to report a possible null pointer dereference error at
> mtk_timer_interrupt() in drivers/clocksource/mtk_timer.c (version:
> 3.19-rc5). The null pointer dereference error occurs if the interrupt
> handler mtk_timer_interrupt() accesses evt->dev.event_handler (line 146)
> when evt->dev.event_handler is null and not defined by mtk_timer_init().
>
> mtk_timer_init() first registers mtk_timer_interrupt() as the interrupt
> handler at line 227, and then defines the clockevent handler at line 246. As
> a consequence, the interrupt handler can be executed before the clockevent
> handler definition when an interrupt occurs between line 227 and line 246.
> The detail error scenario is the following:
>
>
>
> 183: static void __init mtk_timer_init(struct device_node *node) {
>
> ...
>
> 227: if (request_irq(evt->dev.irq, mtk_timer_interrupt,
>
> 228: IRQF_TIMER | IRQF_IRQPOLL, "mtk_timer", evt)) {
>
> ...
>
> ------ An interrupt is fired and the interrupt handler is called -------
>
> 140: static irqreturn_t mtk_timer_interrupt(int irq, void *dev_id)
>
> 141: {
>
> 142: struct mtk_clock_event_device *evt = dev_id;
>
> 143:
>
> 144: /* Acknowledge timer0 irq */
>
> 145: writel(GPT_IRQ_ACK(GPT_CLK_EVT), evt->gpt_base +
> GPT_IRQ_ACK_REG);
>
> 146: evt->dev.event_handler(&evt->dev); // evt->dev.event_handler is
> not defined
>
> 147:
>
> 148: return IRQ_HANDLED;
>
> 149: }
>
> ------ The execution of the interrupt handler is finished ------
>
> ...
>
> 246: clockevents_config_and_register(&evt->dev, rate, 0x3,
>
> 247: 0xffffffff);
>
>
>
> To resolve the problem, I think that the interrupt handler should be
> registered after the clock handler registration.
Thanks for your hint. Actually there are two race conditions.
First we register an interrupt handler, before disabling all
interrupts by calling mtk_timer_global_reset (line 227).
An secondly we register clockevents after enabling the interrupts (line 246).
I will provide a patch for this.
Best regards,
Matthias
--
motzblog.wordpress.com
next parent reply other threads:[~2015-02-19 10:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAMaOmv5O1Qd1dN9ZaODd9EsVSX+D1f0jfJ_RhMa2R0Pxiuh6_g@mail.gmail.com>
2015-02-19 10:12 ` Matthias Brugger [this message]
2015-02-16 8:20 null pointer dereference error in mtk_timer.c 박용배
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=CABuKBeJzETCJCYu61vEnsozxcUueLvPU-vP3OkMhim+ScdTFhQ@mail.gmail.com \
--to=matthias.bgg@gmail.com \
--cc=daniel.lezcano@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=yongbae2@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).