From nobody Sun Apr 28 23:41:24 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1510387959217600.2089590554707; Sat, 11 Nov 2017 00:12:39 -0800 (PST) Received: from localhost ([::1]:44792 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDQtr-0006mK-4F for importer@patchew.org; Sat, 11 Nov 2017 03:12:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45267) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDQsw-0006RE-FG for qemu-devel@nongnu.org; Sat, 11 Nov 2017 03:11:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eDQsv-0006fl-C4 for qemu-devel@nongnu.org; Sat, 11 Nov 2017 03:11:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36514) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eDQsq-0006dC-TD; Sat, 11 Nov 2017 03:11:21 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CD5A26A7E6; Sat, 11 Nov 2017 08:11:18 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-27.ams2.redhat.com [10.36.116.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 404375D6A5; Sat, 11 Nov 2017 08:11:14 +0000 (UTC) From: P J P To: Qemu Developers Date: Sat, 11 Nov 2017 13:41:11 +0530 Message-Id: <20171111081111.32724-1-ppandit@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Sat, 11 Nov 2017 08:11:19 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v1] highbank: validate register offset before access 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: Rob Herring , Prasad J Pandit , Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Shawn Guo , Moguofang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Prasad J Pandit An 'offset' parameter sent to highbank register r/w functions could be greater than number(NUM_REGS=3D0x200) of hb registers, leading to an OOB access issue. Add check to avoid it. Reported-by: Moguofang (Dennis mo) Signed-off-by: Prasad J Pandit Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/arm/highbank.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) Update: log error message(via qemu_log_mask) before returning -> https://lists.gnu.org/archive/html/qemu-devel/2017-11/msg01914.html diff --git a/hw/arm/highbank.c b/hw/arm/highbank.c index 354c6b25a8..8494dc6a48 100644 --- a/hw/arm/highbank.c +++ b/hw/arm/highbank.c @@ -34,6 +34,7 @@ #include "hw/ide/ahci.h" #include "hw/cpu/a9mpcore.h" #include "hw/cpu/a15mpcore.h" +#include "qemu/log.h" =20 #define SMP_BOOT_ADDR 0x100 #define SMP_BOOT_REG 0x40 @@ -117,14 +118,26 @@ static void hb_regs_write(void *opaque, hwaddr offset, } } =20 + if (offset / 4 >=3D NUM_REGS) { + qemu_log_mask(LOG_GUEST_ERROR, + "highbank: bad write offset 0x%x\n", (uint32_t)offse= t); + return; + } regs[offset/4] =3D value; } =20 static uint64_t hb_regs_read(void *opaque, hwaddr offset, unsigned size) { + uint32_t value; uint32_t *regs =3D opaque; - uint32_t value =3D regs[offset/4]; + + if (offset / 4 >=3D NUM_REGS) { + qemu_log_mask(LOG_GUEST_ERROR, + "highbank: bad read offset 0x%x\n", (uint32_t)offset= ); + return 0; + } + value =3D regs[offset/4]; =20 if ((offset =3D=3D 0x100) || (offset =3D=3D 0x108) || (offset =3D=3D 0= x10C)) { value |=3D 0x30000000; --=20 2.13.6