From nobody Thu Sep 19 01:25:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 155050287538393.66200492760697; Mon, 18 Feb 2019 07:14:35 -0800 (PST) Received: from localhost ([127.0.0.1]:60260 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvkcq-0007g1-AD for importer@patchew.org; Mon, 18 Feb 2019 10:14:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39083) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvjxl-0006NC-ED for qemu-devel@nongnu.org; Mon, 18 Feb 2019 09:32:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gvjxh-00032a-UH for qemu-devel@nongnu.org; Mon, 18 Feb 2019 09:32:03 -0500 Received: from ozlabs.org ([203.11.71.1]:56343) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gvjxe-0002e1-DR; Mon, 18 Feb 2019 09:32:00 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 4435rh2Bqmz9sQr; Tue, 19 Feb 2019 01:30:59 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1550500260; bh=brDQQNFYdNPYgfXa/ylCfYanWecZd6LOX5kZrN5US9A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HB6EeU5g1L7GF5VWQ3vrsm4U/McMaWTc+IxYQn+BWQBz59ebLJcB6+IcgnGf5EBfA 3XiCWkwSvvf8ThBYkX/T1U0Y6vXqMJOkC3rmmy48dHj3TdlrbzZNwU1/7gq9+O+OmF tLvMvZpKLAMYUbI2s2RfNexZ2lWMlSgd600n+Bdo= From: David Gibson To: peter.maydell@linaro.org Date: Tue, 19 Feb 2019 01:30:20 +1100 Message-Id: <20190218143049.17142-15-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190218143049.17142-1-david@gibson.dropbear.id.au> References: <20190218143049.17142-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 203.11.71.1 Subject: [Qemu-devel] [PULL 14/43] spapr: fix out of bounds write in spapr_populate_drmem_v2 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fabiano Rosas , groug@kaod.org, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, clg@kaod.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Fabiano Rosas 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 Message-Id: <20190213172926.21740-1-farosas@linux.ibm.com> Reviewed-by: Greg Kurz Signed-off-by: David Gibson --- 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 850cfe28c4..abf9ebce59 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 =3D MACHINE(spapr); - uint8_t *int_buf, *cur_index, buf_len; + uint8_t *int_buf, *cur_index; int ret; uint64_t lmb_size =3D SPAPR_MEMORY_BLOCK_SIZE; uint64_t addr, cur_addr, size; uint32_t nr_boot_lmbs =3D (machine->device_memory->base / lmb_size); uint64_t mem_end =3D machine->device_memory->base + memory_region_size(&machine->device_memory->mr); - uint32_t node, nr_entries =3D 0; + uint32_t node, buf_len, nr_entries =3D 0; sPAPRDRConnector *drc; DrconfCellQueue *elem, *next; MemoryDeviceInfoList *info; --=20 2.20.1