Commit e6962297 authored by Edward Cree's avatar Edward Cree Committed by Kelsey Skunberg

genirq: Fix reference leaks on irq affinity notifiers

BugLink: https://bugs.launchpad.net/bugs/1873852

commit df81dfcf upstream.

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.
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: cd7eab44 ("genirq: Add IRQ affinity notifiers")
Fixes: 59c39840 ("genirq: Prevent use-after-free and work list corruption")
Signed-off-by: default avatarEdward Cree <ecree@solarflare.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Acked-by: default avatarBen Hutchings <ben@decadent.org.uk>
Link: https://lkml.kernel.org/r/24f5983f-2ab5-e83a-44ee-a45b5f9300f5@solarflare.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
Signed-off-by: default avatarKelsey Skunberg <kelsey.skunberg@canonical.com>
parent d66ac275
...@@ -226,7 +226,11 @@ int irq_set_affinity_locked(struct irq_data *data, const struct cpumask *mask, ...@@ -226,7 +226,11 @@ int irq_set_affinity_locked(struct irq_data *data, const struct cpumask *mask,
if (desc->affinity_notify) { if (desc->affinity_notify) {
kref_get(&desc->affinity_notify->kref); 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); irqd_set(data, IRQD_AFFINITY_SET);
...@@ -326,7 +330,10 @@ irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *notify) ...@@ -326,7 +330,10 @@ irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *notify)
raw_spin_unlock_irqrestore(&desc->lock, flags); raw_spin_unlock_irqrestore(&desc->lock, flags);
if (old_notify) { 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); kref_put(&old_notify->kref, old_notify->release);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment