From patchwork Tue Nov 6 05:21:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasad Pandit X-Patchwork-Id: 10669661 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 0BDE815E9 for ; Tue, 6 Nov 2018 05:25:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF9A82A012 for ; Tue, 6 Nov 2018 05:25:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CEEDA2A05C; Tue, 6 Nov 2018 05:25:02 +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 66CBC2A04D for ; Tue, 6 Nov 2018 05:25:02 +0000 (UTC) Received: from localhost ([::1]:39056 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJtrJ-0004p5-B9 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 06 Nov 2018 00:25:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45130) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJtqG-0004FC-6p for qemu-devel@nongnu.org; Tue, 06 Nov 2018 00:23:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJtqD-0006kY-2O for qemu-devel@nongnu.org; Tue, 06 Nov 2018 00:23:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46056) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJtqC-0006k7-Ti for qemu-devel@nongnu.org; Tue, 06 Nov 2018 00:23:53 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 85167A70A; Tue, 6 Nov 2018 05:23:51 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-104.sin2.redhat.com [10.67.116.104]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 287351948B; Tue, 6 Nov 2018 05:23:47 +0000 (UTC) From: P J P To: Qemu Developers Date: Tue, 6 Nov 2018 10:51:43 +0530 Message-Id: <20181106052144.31841-1-ppandit@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 06 Nov 2018 05:23:51 +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 1/2] 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: 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. Add check to avoid OOB access. Reported-by: Cheng Feng Signed-off-by: Prasad J Pandit --- hw/tpm/tpm_tis.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 12f5c9a759..20126dd838 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -293,6 +293,10 @@ static void tpm_tis_request_completed(TPMIf *ti, int ret) uint8_t locty = s->cmd.locty; uint8_t l; + if (locty >= TPM_TIS_NUM_LOCALITIES) { + return; + } + if (s->cmd.selftest_done) { for (l = 0; l < TPM_TIS_NUM_LOCALITIES; l++) { s->loc[locty].sts |= TPM_TIS_STS_SELFTEST_DONE; @@ -401,7 +405,8 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr addr, uint32_t avail; uint8_t v; - if (tpm_backend_had_startup_error(s->be_driver)) { + if (tpm_backend_had_startup_error(s->be_driver) + || locty >= TPM_TIS_NUM_LOCALITIES) { return 0; } @@ -530,7 +535,8 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr addr, return; } - if (tpm_backend_had_startup_error(s->be_driver)) { + if (tpm_backend_had_startup_error(s->be_driver) + || locty >= TPM_TIS_NUM_LOCALITIES) { return; } From patchwork Tue Nov 6 05:21:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasad Pandit X-Patchwork-Id: 10669659 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 E8B6D14BD for ; Tue, 6 Nov 2018 05:25:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5E902A012 for ; Tue, 6 Nov 2018 05:25:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C4D492A0B0; Tue, 6 Nov 2018 05:25:02 +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 6681E2A012 for ; Tue, 6 Nov 2018 05:25:02 +0000 (UTC) Received: from localhost ([::1]:39055 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJtrJ-0004p3-5O for patchwork-qemu-devel@patchwork.kernel.org; Tue, 06 Nov 2018 00:25:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45129) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJtqG-0004FB-6s for qemu-devel@nongnu.org; Tue, 06 Nov 2018 00:23:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJtqE-0006l3-EK for qemu-devel@nongnu.org; Tue, 06 Nov 2018 00:23:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51544) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJtqE-0006ko-9L for qemu-devel@nongnu.org; Tue, 06 Nov 2018 00:23:54 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A3E5E307DABF; Tue, 6 Nov 2018 05:23:53 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-104.sin2.redhat.com [10.67.116.104]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 13E091948B; Tue, 6 Nov 2018 05:23:51 +0000 (UTC) From: P J P To: Qemu Developers Date: Tue, 6 Nov 2018 10:51:44 +0530 Message-Id: <20181106052144.31841-2-ppandit@redhat.com> In-Reply-To: <20181106052144.31841-1-ppandit@redhat.com> References: <20181106052144.31841-1-ppandit@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Tue, 06 Nov 2018 05:23:53 +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 2/2] tpm: use loop iterator to set sts data field 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 , 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 When TIS request is done, set 'sts' data field across all localities. Signed-off-by: Prasad J Pandit Reviewed-by: Stefan Berger --- hw/tpm/tpm_tis.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 20126dd838..58d90645bc 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -299,7 +299,7 @@ static void tpm_tis_request_completed(TPMIf *ti, int ret) if (s->cmd.selftest_done) { for (l = 0; l < TPM_TIS_NUM_LOCALITIES; l++) { - s->loc[locty].sts |= TPM_TIS_STS_SELFTEST_DONE; + s->loc[l].sts |= TPM_TIS_STS_SELFTEST_DONE; } }