From: Yunfeng Ye <yeyunfeng@huawei.com>
To: <tglx@linutronix.de>
Cc: Zhiqiang Liu <liuzhiqiang26@huawei.com>, <linux-kernel@vger.kernel.org>
Subject: [PATCH] genirq: Fix NULL pointer dereference in resend_irqs()
Date: Wed, 4 Sep 2019 20:46:25 +0800 [thread overview]
Message-ID: <1630ae13-5c8e-901e-de09-e740b6a426a7@huawei.com> (raw)
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
reply other threads:[~2019-09-04 12:46 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1630ae13-5c8e-901e-de09-e740b6a426a7@huawei.com \
--to=yeyunfeng@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=liuzhiqiang26@huawei.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).