From: luoben <luoben@linux.alibaba.com>
To: Thomas Gleixner <tglx@linutronix.de>
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: Mon, 12 Aug 2019 10:59:48 +0800 [thread overview]
Message-ID: <46a5b5ea-8832-470b-2577-d7412e6a9cbd@linux.alibaba.com> (raw)
In-Reply-To: <alpine.DEB.2.21.1908082138410.2882@nanos.tec.linutronix.de>
在 2019/8/9 上午3:56, Thomas Gleixner 写道:
> 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.
ok, will return with an error code in v2 in this case
>
>> + /*
>> + * 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.
will take care in v2
>> + 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, will use EXPORT_SYMBOL_GPL in v2
>
> Thanks,
>
> tglx
Thanks,
Ben
next prev parent reply other threads:[~2019-08-12 2:59 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
2019-08-12 2:59 ` luoben [this message]
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=46a5b5ea-8832-470b-2577-d7412e6a9cbd@linux.alibaba.com \
--to=luoben@linux.alibaba.com \
--cc=alex.williamson@redhat.com \
--cc=gerry@linux.alibaba.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tao.ma@linux.alibaba.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).