qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: AlexChen <alex.chen@huawei.com>
To: Jiaxun Yang <jiaxun.yang@flygoat.com>
Cc: zhengchuan@huawei.com, chenhc@lemote.com,
	QEMU <qemu-devel@nongnu.org>,
	zhang.zhanghailiang@huawei.com
Subject: Re: [PATCH] hw/intc: Fix incorrect calculation of core in liointc_read() and liointc_write()
Date: Tue, 3 Nov 2020 22:05:35 +0800	[thread overview]
Message-ID: <5FA163AF.2020007@huawei.com> (raw)
In-Reply-To: <ad70d1f3-ba98-3977-f2ac-a14d03c7e7ba@flygoat.com>

On 2020/11/3 17:53, Jiaxun Yang wrote:
> 
> 
> 在 2020/11/3 17:32, AlexChen 写道:
>> According to the loongson spec
>> (http://www.loongson.cn/uploadfile/cpu/3B1500/Loongson_3B1500_cpu_user_1.pdf)
>> and the macro definition(#define R_PERCORE_ISR(x) (0x40 + 0x8 * x)), we know
>> that the ISR size of per CORE is 8, so here we need to divide
>> (addr - R_PERCORE_ISR(0)) by 8, not 4.
> Hi Alex
> 
> Thanks!
> 
> That was my fault.. Per Core ISA is rarely used by kernel..
> 
> Reviewed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
>> Reported-by: Euler Robot <euler.robot@huawei.com>
> Btw:
> How can you discover this by robot?
> Huawei owns real artifical intelligence technology lol :-)
> 
> 

Thanks for your review.
EulerRobot is a virtualization software quality automation project that
integrates some tools and test suites such as gcc/clang make test, qemu ut,
qtest, coccinelle scripts and avocado-vt.
The code checking tool found there was a potential array out of bounds at
'r = p->per_core_isr[core]', since 'core' may be 7 which is bigger than
'per_core_isr' array size 3.
So we found this bug.

Thanks,
Alex

> - Jiaxun
>> Signed-off-by: Alex Chen <alex.chen@huawei.com>
>> ---
>>   hw/intc/loongson_liointc.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/hw/intc/loongson_liointc.c b/hw/intc/loongson_liointc.c
>> index 30fb375b72..fbbfb57ee9 100644
>> --- a/hw/intc/loongson_liointc.c
>> +++ b/hw/intc/loongson_liointc.c
>> @@ -130,7 +130,7 @@ liointc_read(void *opaque, hwaddr addr, unsigned int size)
>>
>>       if (addr >= R_PERCORE_ISR(0) &&
>>           addr < R_PERCORE_ISR(NUM_CORES)) {
>> -        int core = (addr - R_PERCORE_ISR(0)) / 4;
>> +        int core = (addr - R_PERCORE_ISR(0)) / 8;
>>           r = p->per_core_isr[core];
>>           goto out;
>>       }
>> @@ -173,7 +173,7 @@ liointc_write(void *opaque, hwaddr addr,
>>
>>       if (addr >= R_PERCORE_ISR(0) &&
>>           addr < R_PERCORE_ISR(NUM_CORES)) {
>> -        int core = (addr - R_PERCORE_ISR(0)) / 4;
>> +        int core = (addr - R_PERCORE_ISR(0)) / 8;
>>           p->per_core_isr[core] = value;
>>           goto out;
>>       }
> .
> 



  reply	other threads:[~2020-11-03 14:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-03  9:32 [PATCH] hw/intc: Fix incorrect calculation of core in liointc_read() and liointc_write() AlexChen
2020-11-03  9:53 ` Jiaxun Yang
2020-11-03 14:05   ` AlexChen [this message]
2020-11-03 14:26     ` Philippe Mathieu-Daudé
2020-11-03 12:28 ` Philippe Mathieu-Daudé
2020-11-03 15:40   ` Jiaxun Yang
2020-11-03 17:15     ` Philippe Mathieu-Daudé
2020-11-04  4:17       ` chen huacai
2020-11-05  1:56         ` chen huacai
2020-11-03 12:55 ` Philippe Mathieu-Daudé

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=5FA163AF.2020007@huawei.com \
    --to=alex.chen@huawei.com \
    --cc=chenhc@lemote.com \
    --cc=jiaxun.yang@flygoat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=zhang.zhanghailiang@huawei.com \
    --cc=zhengchuan@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;
as well as URLs for NNTP newsgroup(s).