From patchwork Tue Nov 20 07:22:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasad Pandit X-Patchwork-Id: 10689927 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 26BD013AD for ; Tue, 20 Nov 2018 07:25:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1032B29C31 for ; Tue, 20 Nov 2018 07:25:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0474F29C9B; Tue, 20 Nov 2018 07:25:42 +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 D900229C31 for ; Tue, 20 Nov 2018 07:25:40 +0000 (UTC) Received: from localhost ([::1]:60584 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gP0Pj-0006HP-NM for patchwork-qemu-devel@patchwork.kernel.org; Tue, 20 Nov 2018 02:25:39 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36483) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gP0Ov-0005qn-To for qemu-devel@nongnu.org; Tue, 20 Nov 2018 02:24:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gP0Or-0008L0-Sb for qemu-devel@nongnu.org; Tue, 20 Nov 2018 02:24:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47812) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gP0Or-0008Jt-N3 for qemu-devel@nongnu.org; Tue, 20 Nov 2018 02:24:45 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 833DF307D85B; Tue, 20 Nov 2018 07:24:44 +0000 (UTC) Received: from localhost.localdomain (unknown [10.33.36.8]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6D53D10021B6; Tue, 20 Nov 2018 07:24:42 +0000 (UTC) From: P J P To: QEMU Developers Date: Tue, 20 Nov 2018 12:52:39 +0530 Message-Id: <20181120072239.512-1-ppandit@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 20 Nov 2018 07:24:44 +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 v1] tpm: check localities index 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: Cheng Feng , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Prasad J Pandit , Stefan Berger 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 mmio device r/w operations, guest could set 'addr' parameter such that 'locty' index exceeds TPM_TIS_NUM_LOCALITIES=5 after setting new 'locty' via 'tpm_tis_new_active_locality'. Add check to avoid OOB access. Reported-by: Cheng Feng Signed-off-by: Prasad J Pandit --- hw/tpm/tpm_tis.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) Update: add assert() calls -> https://lists.gnu.org/archive/html/qemu-devel/2018-11/msg00912.html diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 12f5c9a759..d6bf3ceb26 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -293,6 +293,7 @@ static void tpm_tis_request_completed(TPMIf *ti, int ret) uint8_t locty = s->cmd.locty; uint8_t l; + assert(TPM_TIS_IS_VALID_LOCTY(locty)); if (s->cmd.selftest_done) { for (l = 0; l < TPM_TIS_NUM_LOCALITIES; l++) { s->loc[locty].sts |= TPM_TIS_STS_SELFTEST_DONE; @@ -401,6 +402,7 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr addr, uint32_t avail; uint8_t v; + assert(TPM_TIS_IS_VALID_LOCTY(locty)); if (tpm_backend_had_startup_error(s->be_driver)) { return 0; } @@ -523,6 +525,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr addr, uint16_t len; uint32_t mask = (size == 1) ? 0xff : ((size == 2) ? 0xffff : ~0); + assert(TPM_TIS_IS_VALID_LOCTY(locty)); trace_tpm_tis_mmio_write(size, addr, val); if (locty == 4) { @@ -642,7 +645,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr addr, } } - if (set_new_locty) { + if (set_new_locty && TPM_TIS_IS_VALID_LOCTY(active_locty)) { tpm_tis_new_active_locality(s, active_locty); }