[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-arm] [PATCH] highbank: validate register offset before access
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: [Qemu-arm] [PATCH] highbank: validate register offset before access |
Date: |
Fri, 10 Nov 2017 10:35:18 -0300 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 |
Hi Prasad, Moguofang.
On 11/09/2017 08:58 AM, P J P wrote:
> From: Prasad J Pandit <address@hidden>
>
> An 'offset' parameter sent to highbank register r/w functions
> could be greater than number(NUM_REGS=0x200) of hb registers,
> leading to an OOB access issue. Add check to avoid it.
>
> Reported-by: Moguofang (Dennis mo) <address@hidden>
> Signed-off-by: Prasad J Pandit <address@hidden>
> ---
> hw/arm/highbank.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/hw/arm/highbank.c b/hw/arm/highbank.c
> index 354c6b25a8..94df151454 100644
> --- a/hw/arm/highbank.c
> +++ b/hw/arm/highbank.c
> @@ -117,6 +117,9 @@ static void hb_regs_write(void *opaque, hwaddr offset,
> }
> }
>
> + if (offset / 4 >= NUM_REGS) {
I'd report that:
qemu_log_mask(LOG_UNIMP, ...
Cc'ing Shawn & Rob since this might also be a LOG_GUEST_ERROR.
> + return;
> + }
> regs[offset/4] = value;
> }
>
> @@ -124,6 +127,10 @@ static uint64_t hb_regs_read(void *opaque, hwaddr offset,
> unsigned size)
> {
> uint32_t *regs = opaque;
> +
> + if (offset / 4 >= NUM_REGS) {
Ditto.
> + return 0;
> + }
>From CODING_STYLE:
Mixed declarations (interleaving statements and declarations within
blocks) are generally not allowed; declarations should be at the
beginning of blocks.
> uint32_t value = regs[offset/4];
>
> if ((offset == 0x100) || (offset == 0x108) || (offset == 0x10C)) {
Regards,
Phil.