qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Fabiano Rosas <farosas@linux.ibm.com>
Cc: qemu-devel@nongnu.org, qemu-ppc@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] spapr: fix out of bounds write in spapr_populate_drmem_v2
Date: Thu, 14 Feb 2019 11:15:57 +1100	[thread overview]
Message-ID: <20190214001557.GW1884@umbus.fritz.box> (raw)
In-Reply-To: <20190213172926.21740-1-farosas@linux.ibm.com>

[-- Attachment #1: Type: text/plain, Size: 2046 bytes --]

On Wed, Feb 13, 2019 at 03:29:26PM -0200, Fabiano Rosas wrote:
> buf_len is uint8_t which is not large enough to hold the result of:
> 
>   nr_entries * sizeof(struct sPAPRDrconfCellV2) + sizeof(uint32_t);
> 
> for a nr_entries greater than 10.
> 
> This causes the allocated buffer 'int_buf' to be smaller than expected
> and we eventually overwrite some of glibc's control structures (see
> "chunk" in https://sourceware.org/glibc/wiki/MallocInternals)
> 
> The following error is seen while trying to free int_buf:
> 
>   "free(): invalid next size (fast)"
> 
> Fixes: a324d6f166 "spapr: Support ibm,dynamic-memory-v2 property"
> Signed-off-by: Fabiano Rosas <farosas@linux.ibm.com>

Ouch.  That was always bogus, we just got away with it before.

Applied to ppc-for-4.0.

> ---
>  hw/ppc/spapr.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index 332cba89d4..7c4bf8ed8c 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -687,14 +687,14 @@ static int spapr_populate_drmem_v2(sPAPRMachineState *spapr, void *fdt,
>                                     int offset, MemoryDeviceInfoList *dimms)
>  {
>      MachineState *machine = MACHINE(spapr);
> -    uint8_t *int_buf, *cur_index, buf_len;
> +    uint8_t *int_buf, *cur_index;
>      int ret;
>      uint64_t lmb_size = SPAPR_MEMORY_BLOCK_SIZE;
>      uint64_t addr, cur_addr, size;
>      uint32_t nr_boot_lmbs = (machine->device_memory->base / lmb_size);
>      uint64_t mem_end = machine->device_memory->base +
>                         memory_region_size(&machine->device_memory->mr);
> -    uint32_t node, nr_entries = 0;
> +    uint32_t node, buf_len, nr_entries = 0;
>      sPAPRDRConnector *drc;
>      DrconfCellQueue *elem, *next;
>      MemoryDeviceInfoList *info;

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      parent reply	other threads:[~2019-02-14  0:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-13 17:29 [Qemu-devel] [PATCH] spapr: fix out of bounds write in spapr_populate_drmem_v2 Fabiano Rosas
2019-02-13 19:49 ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
2019-02-14  0:15 ` David Gibson [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=20190214001557.GW1884@umbus.fritz.box \
    --to=david@gibson.dropbear.id.au \
    --cc=farosas@linux.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    /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).