From patchwork Sun Mar 26 21:08:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 9645219 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 83F7E602C8 for ; Sun, 26 Mar 2017 21:08:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75F8127F80 for ; Sun, 26 Mar 2017 21:08:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A3B427F9F; Sun, 26 Mar 2017 21:08:27 +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 vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B989B27F80 for ; Sun, 26 Mar 2017 21:08:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751609AbdCZVI0 (ORCPT ); Sun, 26 Mar 2017 17:08:26 -0400 Received: from mga03.intel.com ([134.134.136.65]:16260 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751570AbdCZVI0 (ORCPT ); Sun, 26 Mar 2017 17:08:26 -0400 Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Mar 2017 14:08:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,228,1486454400"; d="scan'208";a="70769844" Received: from mahnkopf-mobl1.ger.corp.intel.com (HELO localhost) ([10.252.49.92]) by orsmga004.jf.intel.com with ESMTP; 26 Mar 2017 14:08:21 -0700 From: Jarkko Sakkinen To: tpmdd-devel@lists.sourceforge.net Cc: linux-security-module@vger.kernel.org, Jarkko Sakkinen , Peter Huewe , Marcel Selhorst , Jarkko Sakkinen , Jason Gunthorpe , linux-kernel@vger.kernel.org (open list) Subject: [PATCH] tpm: do handle area size validation only when TPM space used Date: Mon, 27 Mar 2017 00:08:15 +0300 Message-Id: <20170326210815.21252-1-jarkko.sakkinen@iki.fi> X-Mailer: git-send-email 2.9.3 Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP In order to not cause backwards compatibility issues with /dev/tpm0 disable handle area size validation if tpm_transmit is not called with a TPM space. Signed-off-by: Jarkko Sakkinen --- drivers/char/tpm/tpm-interface.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c index bf0c3fa..158c1db 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -328,7 +328,9 @@ unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, } EXPORT_SYMBOL_GPL(tpm_calc_ordinal_duration); -static bool tpm_validate_command(struct tpm_chip *chip, const u8 *cmd, +static bool tpm_validate_command(struct tpm_chip *chip, + struct tpm_space *space, + const u8 *cmd, size_t len) { const struct tpm_input_header *header = (const void *)cmd; @@ -340,6 +342,9 @@ static bool tpm_validate_command(struct tpm_chip *chip, const u8 *cmd, if (len < TPM_HEADER_SIZE) return false; + if (!space) + return true; + if (chip->flags & TPM_CHIP_FLAG_TPM2 && chip->nr_commands) { cc = be32_to_cpu(header->ordinal); @@ -386,7 +391,7 @@ ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space, unsigned long stop; bool need_locality; - if (!tpm_validate_command(chip, buf, bufsiz)) + if (!tpm_validate_command(chip, space, buf, bufsiz)) return -EINVAL; if (bufsiz > TPM_BUFSIZE)