linux-brain/kernel/irq
Yunfeng Ye 3426b36170 genirq: Prevent NULL pointer dereference in resend_irqs()
commit eddf3e9c7c upstream.

The following crash was observed:

  Unable to handle kernel NULL pointer dereference at 0000000000000158
  Internal error: Oops: 96000004 [#1] SMP
  pc : resend_irqs+0x68/0xb0
  lr : resend_irqs+0x64/0xb0
  ...
  Call trace:
   resend_irqs+0x68/0xb0
   tasklet_action_common.isra.6+0x84/0x138
   tasklet_action+0x2c/0x38
   __do_softirq+0x120/0x324
   run_ksoftirqd+0x44/0x60
   smpboot_thread_fn+0x1ac/0x1e8
   kthread+0x134/0x138
   ret_from_fork+0x10/0x18

The reason for this is that the interrupt resend mechanism happens in soft
interrupt context, which is a asynchronous mechanism versus other
operations on interrupts. free_irq() does not take resend handling into
account. Thus, the irq descriptor might be already freed before the resend
tasklet is executed. resend_irqs() does not check the return value of the
interrupt descriptor lookup and derefences the return value
unconditionally.

  1):
  __setup_irq
    irq_startup
      check_irq_resend  // activate softirq to handle resend irq
  2):
  irq_domain_free_irqs
    irq_free_descs
      free_desc
        call_rcu(&desc->rcu, delayed_free_desc)
  3):
  __do_softirq
    tasklet_action
      resend_irqs
        desc = irq_to_desc(irq)
        desc->handle_irq(desc)  // desc is NULL --> Ooops

Fix this by adding a NULL pointer check in resend_irqs() before derefencing
the irq descriptor.

Fixes: a4633adcdb ("[PATCH] genirq: add genirq sw IRQ-retrigger")
Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/1630ae13-5c8e-901e-de09-e740b6a426a7@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-09-19 09:08:04 +02:00
..
affinity.c genirq/affinity: Don't return with empty affinity masks on error 2019-01-13 10:01:02 +01:00
autoprobe.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
chip.c genirq: Respect IRQCHIP_SKIP_SET_WAKE in irq_chip_set_wake_parent() 2019-04-17 08:37:53 +02:00
cpuhotplug.c genirq/cpuhotplug: Add sanity check for effective affinity mask 2017-10-09 13:26:48 +02:00
debug.h genirq: Guard handle_bad_irq log messages 2018-03-03 10:24:31 +01:00
debugfs.c genirq/debugfs: Triggering of interrupts from userspace 2017-08-18 10:36:24 +02:00
devres.c irq/generic-chip: Provide devm_irq_setup_generic_chip() 2017-06-21 15:53:11 +02:00
dummychip.c Merge branch 'linus' into irq/core 2015-06-05 22:25:01 +02:00
generic-chip.c genirq: generic chip: remove irq_gc_mask_disable_reg_and_ack() 2017-10-13 16:31:05 +01:00
handle.c There has been a fair amount of activity in the docs tree this time 2017-07-03 21:13:25 -07:00
internals.h genirq: Avoid summation loops for /proc/stat 2019-04-05 22:31:35 +02:00
ipi.c genirq/ipi: Fixup checks against nr_cpu_ids 2017-08-20 10:49:05 +02:00
irq_sim.c genirq/irq_sim: Add a devres variant of irq_sim_init() 2017-08-16 16:40:02 +02:00
irqdesc.c genirq: Properly pair kobject_del() with kobject_add() 2019-08-29 08:26:44 +02:00
irqdomain.c irqdomain: Add __rcu annotations to radix tree accessors 2017-09-25 21:23:44 +02:00
Kconfig genirq: Add handle_fasteoi_{level,edge}_irq flow handlers 2017-08-18 11:21:41 +02:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
manage.c genirq: Prevent use-after-free and work list corruption 2019-05-10 17:53:13 +02:00
migration.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
msi.c genirq/msi: Fix populating multiple interrupts 2017-09-06 11:41:20 +02:00
pm.c genirq/PM: Properly pretend disabled state when force resuming interrupts 2017-07-17 22:32:20 +02:00
proc.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
resend.c genirq: Prevent NULL pointer dereference in resend_irqs() 2019-09-19 09:08:04 +02:00
settings.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
spurious.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
timings.c genirq/timings: Add infrastructure for estimating the next interrupt arrival time 2017-06-24 11:44:39 +02:00