From patchwork Fri Oct 26 12:33:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Prasad Pandit X-Patchwork-Id: 10657337 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0316E14E2 for ; Fri, 26 Oct 2018 12:38:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDD082AFF0 for ; Fri, 26 Oct 2018 12:38:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DEC122B012; Fri, 26 Oct 2018 12:38:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3AEA02AFF0 for ; Fri, 26 Oct 2018 12:38:24 +0000 (UTC) Received: from localhost ([::1]:59917 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gG1Nf-0001uC-Ia for patchwork-qemu-devel@patchwork.kernel.org; Fri, 26 Oct 2018 08:38:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52168) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gG1LW-0007we-Hw for qemu-devel@nongnu.org; Fri, 26 Oct 2018 08:36:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gG1LS-00087z-Iy for qemu-devel@nongnu.org; Fri, 26 Oct 2018 08:36:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46484) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gG1LS-000878-Cz for qemu-devel@nongnu.org; Fri, 26 Oct 2018 08:36:06 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F3C6830C9EE7; Fri, 26 Oct 2018 12:36:04 +0000 (UTC) Received: from localhost.localdomain (unknown [10.65.150.231]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 941D460CD8; Fri, 26 Oct 2018 12:36:01 +0000 (UTC) From: P J P To: Qemu Developers Date: Fri, 26 Oct 2018 18:03:58 +0530 Message-Id: <20181026123358.2554-1-ppandit@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 26 Oct 2018 12:36:05 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2] ppc/pnv: check size before data buffer 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: Prasad J Pandit , Alexander Graf , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Moguofang , David Gibson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Prasad J Pandit While performing PowerNV memory r/w operations, the access length 'sz' could exceed the data[4] buffer size. Add check to avoid OOB access. Reported-by: Moguofang Signed-off-by: Prasad J Pandit Reviewed-by: Cédric Le Goater --- hw/ppc/pnv_lpc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) Update v2: add error log message -> https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg05750.html diff --git a/hw/ppc/pnv_lpc.c b/hw/ppc/pnv_lpc.c index d7721320a2..172a915cfc 100644 --- a/hw/ppc/pnv_lpc.c +++ b/hw/ppc/pnv_lpc.c @@ -155,9 +155,15 @@ static void pnv_lpc_do_eccb(PnvLpcController *lpc, uint64_t cmd) /* XXX Check for magic bits at the top, addr size etc... */ unsigned int sz = (cmd & ECCB_CTL_SZ_MASK) >> ECCB_CTL_SZ_LSH; uint32_t opb_addr = cmd & ECCB_CTL_ADDR_MASK; - uint8_t data[4]; + uint8_t data[8]; bool success; + if (sz > sizeof(data)) { + qemu_log_mask(LOG_GUEST_ERROR, + "ECCB: invalid operation at @0x%08x size %d\n", opb_addr, sz); + return; + } + if (cmd & ECCB_CTL_READ) { success = opb_read(lpc, opb_addr, data, sz); if (success) {