public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: "chenjun (AM)" <chenjun102@huawei.com>
To: Will Deacon <will@kernel.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"catalin.marinas@arm.com" <catalin.marinas@arm.com>,
	"xuqiang (M)" <xuqiang36@huawei.com>
Subject: Re: [PATCH] arm64/smp: check !ipi_desc[i] in arch_show_interrupts
Date: Wed, 15 Jun 2022 12:03:17 +0000	[thread overview]
Message-ID: <188b4432206b464d93776d80c23081bb@huawei.com> (raw)
In-Reply-To: 20220609152003.GC3289@willie-the-truck

在 2022/6/9 23:20, Will Deacon 写道:
> On Fri, May 27, 2022 at 08:22:36AM +0000, Chen Jun wrote:
>> There is a potential dereferencing null pointer issue in
>> arch_show_interrupts.
>>
>> Problem 1:
>> int arch_show_interrupts(struct seq_file *p, int prec)
>>          for (i = 0; i < NR_IPI; i++) {
>>                  seq_printf(p, "%10u ", irq_desc_kstat_cpu(ipi_desc[i],
>> 			cpu));
>>
>> Only ipi_desc[0..nr_ipi - 1] are initialized in set_smp_ipi_range.
>> and ipi_desc[nr_ipi..NR_IPI] are NULL.
>> irq_desc_kstat_cpu will dereference NULL pointer.
>> For now, the problem can not be triggered, because NR_IPI is always
>> equal to nr_ipi.
>>
>> Problem 2:
>> If request_percpu_irq failed in set_smp_ipi_range, ipi_desc[i]
>> would be NULL.
>> irq_desc_kstat_cpu will dereference NULL pointer.
>>
>> check !ipi_desc[i] (as arm does) to avoid the problem.
>>
>> Signed-off-by: Chen Jun <chenjun102@huawei.com>
>> ---
>>   arch/arm64/kernel/smp.c | 3 +++
>>   1 file changed, 3 insertions(+)
>>
>> diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c
>> index 62ed361a4376..3d54f464428b 100644
>> --- a/arch/arm64/kernel/smp.c
>> +++ b/arch/arm64/kernel/smp.c
>> @@ -781,6 +781,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
>>   	unsigned int cpu, i;
>>   
>>   	for (i = 0; i < NR_IPI; i++) {
>> +		if (!ipi_desc[i])
>> +			continue;
> 
> Why not just use nr_ipi instead of NR_IPI?

Yee, that is what I do at first. But I noticed that:

void __init set_smp_ipi_range(int ipi_base, int n)
     for (i = 0; i < nr_ipi; i++) {
         err = request_percpu_irq(ipi_base + i, ipi_handler,
                                  "IPI", &cpu_number);
         WARN_ON(err);
         ipi_desc[i] = irq_to_desc(ipi_base + i);

If request_percpu_irq return a error, I not sure if ipi_desc[i] makes sense.

> 
> Will
> 

-- 
Regards
Chen Jun

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

      reply	other threads:[~2022-06-15 12:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-27  8:22 [PATCH] arm64/smp: check !ipi_desc[i] in arch_show_interrupts Chen Jun
2022-06-09 15:20 ` Will Deacon
2022-06-15 12:03   ` chenjun (AM) [this message]

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=188b4432206b464d93776d80c23081bb@huawei.com \
    --to=chenjun102@huawei.com \
    --cc=catalin.marinas@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=will@kernel.org \
    --cc=xuqiang36@huawei.com \
    /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