* [PATCH] genirq: Fix NULL pointer dereference in resend_irqs()
@ 2019-09-04 12:46 Yunfeng Ye
0 siblings, 0 replies; only message in thread
From: Yunfeng Ye @ 2019-09-04 12:46 UTC (permalink / raw)
To: tglx; +Cc: Zhiqiang Liu, linux-kernel
Oops occur when running qemu on arm64:
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
As we know, softirq is a asynchronous mechanism. The process of free
irqs does not take resend irq handling into account. Thus, the irq_desc
may be already freed before softirq running, and resend_irqs() does not
check the validation of irq_desc, finally, the Oops occur. Process is as
follows:
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, Oops occur
Fix this by checking for a NULL pointer when get @irq_desc in
resend_irqs().
Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
Reviewed-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
---
kernel/irq/resend.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/kernel/irq/resend.c b/kernel/irq/resend.c
index 95414ad..98c04ca5 100644
--- a/kernel/irq/resend.c
+++ b/kernel/irq/resend.c
@@ -36,6 +36,8 @@ static void resend_irqs(unsigned long arg)
irq = find_first_bit(irqs_resend, nr_irqs);
clear_bit(irq, irqs_resend);
desc = irq_to_desc(irq);
+ if (!desc)
+ continue;
local_irq_disable();
desc->handle_irq(desc);
local_irq_enable();
--
1.8.3.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2019-09-04 12:46 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-04 12:46 [PATCH] genirq: Fix NULL pointer dereference in resend_irqs() Yunfeng Ye
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).