From: Thomas Gleixner <tglx@linutronix.de>
To: Ben Luo <luoben@linux.alibaba.com>
Cc: alex.williamson@redhat.com, linux-kernel@vger.kernel.org,
tao.ma@linux.alibaba.com, gerry@linux.alibaba.com
Subject: Re: [PATCH 1/2] genirq: introduce update_irq_devid()
Date: Thu, 8 Aug 2019 21:56:14 +0200 (CEST) [thread overview]
Message-ID: <alpine.DEB.2.21.1908082138410.2882@nanos.tec.linutronix.de> (raw)
In-Reply-To: <39a5009c77d07c3ce42ef784465c05e36d5f684d.1565263723.git.luoben@linux.alibaba.com>
On Thu, 8 Aug 2019, Ben Luo wrote:
> +int update_irq_devid(unsigned int irq, void *dev_id, void *new_dev_id)
> +{
> + struct irq_desc *desc = irq_to_desc(irq);
> + struct irqaction *action, **action_ptr;
> + unsigned long flags;
> +
> + WARN(in_interrupt(),
> + "Trying to update IRQ %d from IRQ context!\n", irq);
This is broken. The function needs to return on that condition. Actually it
cannot even be called from non-preemptible code.
What's worse is that if the interrupt in question is handled concurrently,
then it will either see the old or the new dev_id and because the interrupt
handler loop runs with desc->lock dropped even more crap can happen because
dev_id can be subject to load and store tearing.
Staring at that, I see that there is the same issue in setup_irq() and
free_irq(). It's actually worse there. I'll have a look.
> + /*
> + * There can be multiple actions per IRQ descriptor, find the right
> + * one based on the dev_id:
> + */
> + action_ptr = &desc->action;
> + for (;;) {
> + action = *action_ptr;
> +
> + if (!action) {
> + WARN(1, "Trying to update already-free IRQ %d\n", irq);
That's wrong in two aspects:
1) The warn should be outside of the locked region.
2) Just having the irq number is not useful for debugging either
when the interrupt is shared.
> + raw_spin_unlock_irqrestore(&desc->lock, flags);
> + chip_bus_sync_unlock(desc);
> + return -ENXIO;
> + }
> +
> + if (action->dev_id == dev_id) {
> + action->dev_id = new_dev_id;
> + break;
> + }
> + action_ptr = &action->next;
> + }
> +
> + raw_spin_unlock_irqrestore(&desc->lock, flags);
> + chip_bus_sync_unlock(desc);
> +
> + /*
> + * Make sure it's not being used on another CPU:
> + * There is a risk of UAF for old *dev_id, if it is
> + * freed in a short time after this func returns
> + */
> + synchronize_irq(irq);
> +
> + return 0;
> +}
> +EXPORT_SYMBOL(update_irq_devid);
EXPORT_SYMBOL_GPL() please.
Thanks,
tglx
next prev parent reply other threads:[~2019-08-08 19:56 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-08 12:07 [PATCH 0/2] introduce update_irq_devid and optimize VFIO irq ops Ben Luo
2019-08-08 12:07 ` [PATCH 1/2] genirq: introduce update_irq_devid() Ben Luo
2019-08-08 19:56 ` Thomas Gleixner [this message]
2019-08-12 2:59 ` luoben
2019-08-08 12:07 ` [PATCH 2/2] vfio_pci: make use of update_irq_devid and optimize irq ops Ben Luo
2019-08-12 5:44 ` Yunsheng Lin
2019-08-12 6:37 ` luoben
2019-08-12 8:52 ` [PATCH v2 0/3] introduce update_irq_devid and optimize VFIO " Ben Luo
2019-08-12 8:52 ` [PATCH v2 1/3] genirq: enhance error recovery code in free irq Ben Luo
2019-08-12 8:52 ` [PATCH v2 2/3] genirq: introduce update_irq_devid() Ben Luo
2019-08-12 8:52 ` [PATCH v2 3/3] vfio_pci: make use of update_irq_devid and optimize irq ops Ben Luo
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=alpine.DEB.2.21.1908082138410.2882@nanos.tec.linutronix.de \
--to=tglx@linutronix.de \
--cc=alex.williamson@redhat.com \
--cc=gerry@linux.alibaba.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luoben@linux.alibaba.com \
--cc=tao.ma@linux.alibaba.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).