From patchwork Mon Mar 20 14:23:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin King X-Patchwork-Id: 9634287 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5F1EE602D6 for ; Mon, 20 Mar 2017 14:23:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5349128449 for ; Mon, 20 Mar 2017 14:23:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 478B728451; Mon, 20 Mar 2017 14:23:55 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B91F028449 for ; Mon, 20 Mar 2017 14:23:54 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1cpyDw-0006xI-RS; Mon, 20 Mar 2017 14:23:52 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1cpyDw-0006xD-7B for tpmdd-devel@lists.sourceforge.net; Mon, 20 Mar 2017 14:23:52 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by sog-mx-1.v43.ch3.sourceforge.com with esmtp (Exim 4.76) id 1cpyDv-0001LZ-7U for tpmdd-devel@lists.sourceforge.net; Mon, 20 Mar 2017 14:23:52 +0000 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1cpyDh-0003dM-67; Mon, 20 Mar 2017 14:23:37 +0000 From: Colin King To: Peter Huewe , Marcel Selhorst , Jarkko Sakkinen , Jason Gunthorpe , tpmdd-devel@lists.sourceforge.net Date: Mon, 20 Mar 2017 14:23:36 +0000 Message-Id: <20170320142336.10997-1-colin.king@canonical.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 X-Headers-End: 1cpyDv-0001LZ-7U Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [tpmdd-devel] [PATCH] tpm2: fix off-by-one comparison and out-of-bounds read error X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Tpm Device Driver maintainance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: tpmdd-devel-bounces@lists.sourceforge.net X-Virus-Scanned: ClamAV using ClamSMTP From: Colin Ian King The comparison of an out of range index into space->context_tbl is off-by-one and should be using >= rather than > in the comparison. Detected by CoverityScan, CID#1419694 ("Out-of-bounds read") Fixes: 849246e7ce9ce ("tpm2: add session handle context saving and restoring to the space code") Signed-off-by: Colin Ian King --- drivers/char/tpm/tpm2-space.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/char/tpm/tpm2-space.c b/drivers/char/tpm/tpm2-space.c index d36d81e07076..009934269514 100644 --- a/drivers/char/tpm/tpm2-space.c +++ b/drivers/char/tpm/tpm2-space.c @@ -229,7 +229,7 @@ static bool tpm2_map_to_phandle(struct tpm_space *space, void *handle) int i; i = 0xFFFFFF - (vhandle & 0xFFFFFF); - if (i > ARRAY_SIZE(space->context_tbl) || !space->context_tbl[i]) + if (i >= ARRAY_SIZE(space->context_tbl) || !space->context_tbl[i]) return false; phandle = space->context_tbl[i];