From: Ben Hutchings <ben@decadent.org.uk>
To: Edward Cree <ecree@solarflare.com>, tglx@linutronix.de
Cc: linux-kernel@vger.kernel.org, psodagud@codeaurora.org
Subject: Re: [PATCH] genirq: fix reference leaks on irq affinity notifiers
Date: Sun, 15 Mar 2020 20:29:16 +0000 [thread overview]
Message-ID: <17c4273e4f72ebdf1ca838d75fc6ed93fcdc7287.camel@decadent.org.uk> (raw)
In-Reply-To: <24f5983f-2ab5-e83a-44ee-a45b5f9300f5@solarflare.com>
[-- Attachment #1: Type: text/plain, Size: 2596 bytes --]
On Fri, 2020-03-13 at 20:33 +0000, Edward Cree wrote:
> The handling of notify->work did not properly maintain notify->kref in two
> cases:
> 1) where the work was already scheduled, another irq_set_affinity_locked()
> would get the ref and (no-op-ly) schedule the work. Thus when
> irq_affinity_notify() ran, it would drop the original ref but not the
> additional one.
> 2) when cancelling the (old) work in irq_set_affinity_notifier(), if there
> was outstanding work a ref had been got for it but was never put.
This makes sense, but...
> Fix both by checking the return values of the work handling functions
> (schedule_work() for (1) and cancel_work_sync() for (2)) and put the
> extra ref if the return value indicates preexisting work.
>
> Fixes: cd7eab44e994 ("genirq: Add IRQ affinity notifiers")
> Fixes: 59c39840f5ab ("genirq: Prevent use-after-free and work list corruption")
> Signed-off-by: Edward Cree <ecree@solarflare.com>
...since the pending work item holds a reference to the notification
state, it's still not clear to me why or whether "genirq: Prevent use-
after-free and work list corruption" was needed.
If it's reasonable to cancel_work_sync() when removing a notifier, I
think we can remove the kref and call the release function directly.
Ben.
> ---
> kernel/irq/manage.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
> index 7eee98c38f25..b3aa1db895e6 100644
> --- a/kernel/irq/manage.c
> +++ b/kernel/irq/manage.c
> @@ -323,7 +323,10 @@ int irq_set_affinity_locked(struct irq_data *data, const struct cpumask *mask,
>
> if (desc->affinity_notify) {
> kref_get(&desc->affinity_notify->kref);
> - schedule_work(&desc->affinity_notify->work);
> + if (!schedule_work(&desc->affinity_notify->work))
> + /* Work was already scheduled, drop our extra ref */
> + kref_put(&desc->affinity_notify->kref,
> + desc->affinity_notify->release);
> }
> irqd_set(data, IRQD_AFFINITY_SET);
>
> @@ -423,7 +426,9 @@ irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *notify)
> raw_spin_unlock_irqrestore(&desc->lock, flags);
>
> if (old_notify) {
> - cancel_work_sync(&old_notify->work);
> + if (cancel_work_sync(&old_notify->work))
> + /* Pending work had a ref, put that one too */
> + kref_put(&old_notify->kref, old_notify->release);
> kref_put(&old_notify->kref, old_notify->release);
> }
>
--
Ben Hutchings
Humour is the best antidote to reality.
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2020-03-15 20:29 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-13 20:33 Edward Cree
2020-03-15 20:29 ` Ben Hutchings [this message]
2020-03-17 10:58 ` Edward Cree
2020-03-17 14:56 ` Ben Hutchings
2020-03-17 19:25 ` Thomas Gleixner
2020-03-21 16:38 ` [tip: irq/urgent] genirq: Fix " tip-bot2 for Edward Cree
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=17c4273e4f72ebdf1ca838d75fc6ed93fcdc7287.camel@decadent.org.uk \
--to=ben@decadent.org.uk \
--cc=ecree@solarflare.com \
--cc=linux-kernel@vger.kernel.org \
--cc=psodagud@codeaurora.org \
--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
all inboxes | Powered by JetHome®