From nobody Tue Oct 28 01:56:33 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516156088150866.6446761855833; Tue, 16 Jan 2018 18:28:08 -0800 (PST) Received: from localhost ([::1]:55862 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebdSQ-0000ms-Rp for importer@patchew.org; Tue, 16 Jan 2018 21:28:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45478) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebdQG-0007pF-8O for qemu-devel@nongnu.org; Tue, 16 Jan 2018 21:25:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebdQF-0001GS-4e for qemu-devel@nongnu.org; Tue, 16 Jan 2018 21:25:52 -0500 Received: from ozlabs.org ([2401:3900:2:1::2]:44611) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ebdQE-0001BI-6h; Tue, 16 Jan 2018 21:25:51 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 3zLrY43Dtbz9sDB; Wed, 17 Jan 2018 13:25:44 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1516155944; bh=mkXosWDCw7H04iNw5AoAmf7ZEAGxdKjxz7/ER8G14SE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HDG7j6GXv62hiYekihvWY1NJuOcsIpvQdVNES+R4X7r5B8NEWBWXFPmXvc41jXkaf thVIALw7z7EsV2fACEauVstlrZYIaJiVvj3ll3lDrGD/yoFAYRxEO495wX7Uk9elBS wJ3PK8pg3NuUaTn32pPwtvPqLwxNWeH1hYbOe2/I= From: David Gibson To: peter.maydell@linaro.org Date: Wed, 17 Jan 2018 13:25:04 +1100 Message-Id: <20180117022525.31767-2-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180117022525.31767-1-david@gibson.dropbear.id.au> References: <20180117022525.31767-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PULL 01/22] target/ppc: Yet another fix for KVM-HV HPTE accessors 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: lvivier@redhat.com, surajjs@au1.ibm.com, Alexey Kardashevskiy , joserz@linux.vnet.ibm.com, qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.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) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Alexey Kardashevskiy As stated in the 1ad9f0a464fe commit log, the returned entries are not a whole PTEG. It was not a problem before 1ad9f0a464fe as it would read a single record assuming it contains a whole PTEG but now the code tries reading the entire PTEG and "if ((n - i) < invalid)" produces negative values which then are converted to size_t for memset() and that throws seg fault. This fixes the math. While here, fix the last @i increment as well. Fixes: 1ad9f0a464fe "target/ppc: Fix KVM-HV HPTE accessors" Signed-off-by: Alexey Kardashevskiy Signed-off-by: David Gibson --- target/ppc/kvm.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index 4664a3ce9d..09fcb082d2 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -2667,21 +2667,24 @@ void kvmppc_read_hptes(ppc_hash_pte64_t *hptes, hwa= ddr ptex, int n) =20 hdr =3D (struct kvm_get_htab_header *)buf; while ((i < n) && ((char *)hdr < (buf + rc))) { - int invalid =3D hdr->n_invalid; + int invalid =3D hdr->n_invalid, valid =3D hdr->n_valid; =20 if (hdr->index !=3D (ptex + i)) { hw_error("kvmppc_read_hptes: Unexpected HPTE index %"PRIu32 " !=3D (%"HWADDR_PRIu" + %d", hdr->index, ptex, i= ); } =20 - memcpy(hptes + i, hdr + 1, HASH_PTE_SIZE_64 * hdr->n_valid); - i +=3D hdr->n_valid; + if (n - i < valid) { + valid =3D n - i; + } + memcpy(hptes + i, hdr + 1, HASH_PTE_SIZE_64 * valid); + i +=3D valid; =20 if ((n - i) < invalid) { invalid =3D n - i; } memset(hptes + i, 0, invalid * HASH_PTE_SIZE_64); - i +=3D hdr->n_invalid; + i +=3D invalid; =20 hdr =3D (struct kvm_get_htab_header *) ((char *)(hdr + 1) + HASH_PTE_SIZE_64 * hdr->n_valid); --=20 2.14.3