From: Lukas Wunner <lukas@wunner.de>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
Mika Westerberg <mika.westerberg@linux.intel.com>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH] genirq: Synchronize only with single thread on free_irq()
Date: Fri, 22 Jun 2018 10:01:25 +0200 [thread overview]
Message-ID: <20180622080125.GA13709@wunner.de> (raw)
In-Reply-To: <alpine.DEB.2.21.1806212217571.1591@nanos.tec.linutronix.de>
On Thu, Jun 21, 2018 at 10:21:44PM +0200, Thomas Gleixner wrote:
> On Thu, 24 May 2018, Lukas Wunner wrote:
> > static int irq_wait_for_interrupt(struct irqaction *action)
> > {
> > - set_current_state(TASK_INTERRUPTIBLE);
> > + for (;;) {
> > + set_current_state(TASK_INTERRUPTIBLE);
> >
> > - while (!kthread_should_stop()) {
> > + if (kthread_should_stop()) {
> > + /* may need to run one last time. */
> > + if (test_and_clear_bit(IRQTF_RUNTHREAD,
> > + &action->thread_flags)) {
> > + __set_current_state(TASK_RUNNING);
> > + return 0;
> > + }
> > + __set_current_state(TASK_RUNNING);
> > + return -1;
> > + }
> >
> > if (test_and_clear_bit(IRQTF_RUNTHREAD,
> > &action->thread_flags)) {
> > @@ -766,10 +776,7 @@ static int irq_wait_for_interrupt(struct irqaction *action)
> > return 0;
> > }
> > schedule();
> > - set_current_state(TASK_INTERRUPTIBLE);
> > }
> > - __set_current_state(TASK_RUNNING);
> > - return -1;
> > }
> >
> > /*
> > @@ -990,7 +997,7 @@ static int irq_thread(void *data)
> > /*
> > * This is the regular exit path. __free_irq() is stopping the
> > * thread via kthread_stop() after calling
> > - * synchronize_irq(). So neither IRQTF_RUNTHREAD nor the
> > + * synchronize_hardirq(). So neither IRQTF_RUNTHREAD nor the
> > * oneshot mask bit can be set. We cannot verify that as we
> > * cannot touch the oneshot mask at this point anymore as
> > * __setup_irq() might have given out currents thread_mask
> > @@ -1595,7 +1602,7 @@ static struct irqaction *__free_irq(struct irq_desc *desc, void *dev_id)
> > unregister_handler_proc(irq, action);
> >
> > /* Make sure it's not being used on another CPU: */
> > - synchronize_irq(irq);
> > + synchronize_hardirq(irq);
>
> So after that, action can be freed and when the thread above tries to
> access it. Nice Use After Free. That needs more thought.
No, after that, kthread_stop() is called which blocks until the IRQ
thread has completed. Only then is the action freed.
Thanks,
Lukas
next prev parent reply other threads:[~2018-06-22 8:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-24 20:45 [PATCH] genirq: Synchronize only with single thread on free_irq() Lukas Wunner
2018-06-21 20:21 ` Thomas Gleixner
2018-06-22 8:01 ` Lukas Wunner [this message]
2018-06-22 19:44 ` Thomas Gleixner
2018-06-22 20:11 ` Thomas Gleixner
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=20180622080125.GA13709@wunner.de \
--to=lukas@wunner.de \
--cc=bhelgaas@google.com \
--cc=bigeasy@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=mika.westerberg@linux.intel.com \
--cc=tglx@linutronix.de \
/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).