From patchwork Thu Jul 28 03:49:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Pronin X-Patchwork-Id: 9250649 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 E9814607D3 for ; Thu, 28 Jul 2016 03:50:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DDD701FFBD for ; Thu, 28 Jul 2016 03:50:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D2B832522B; Thu, 28 Jul 2016 03:50:12 +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 48C5A20246 for ; Thu, 28 Jul 2016 03:50:12 +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 1bScKm-0001NR-KJ; Thu, 28 Jul 2016 03:50:08 +0000 Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1bScKl-0001NE-69 for tpmdd-devel@lists.sourceforge.net; Thu, 28 Jul 2016 03:50:07 +0000 Received-SPF: pass (sog-mx-4.v43.ch3.sourceforge.com: domain of chromium.org designates 209.85.192.171 as permitted sender) client-ip=209.85.192.171; envelope-from=apronin@chromium.org; helo=mail-pf0-f171.google.com; Received: from mail-pf0-f171.google.com ([209.85.192.171]) by sog-mx-4.v43.ch3.sourceforge.com with esmtps (TLSv1:AES128-SHA:128) (Exim 4.76) id 1bScKk-0001qZ-7o for tpmdd-devel@lists.sourceforge.net; Thu, 28 Jul 2016 03:50:07 +0000 Received: by mail-pf0-f171.google.com with SMTP id x72so17353344pfd.2 for ; Wed, 27 Jul 2016 20:50:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=qYraoFkJNeKa0DxgxrCHmTeuLVh2bA/GUurmjP8zTDU=; b=ZdsXDc+sKEWlByKy9URZLCG/xadPJP3Ejyy9f1YUHwgeotMo2sf29SuXgKw5DP1D82 h0zdk+0GDtkpPwBvmoCpMOzdgCel1I/8xJb2AHrFluv9RmczfZLUu/6BhP9+Mg6Ux3g+ qbB/nw5dEBiFcHPsgkvip6vb14TGK/HQJ0nEkJkVZsjq5tYz73J5oeOS8SEQR2dIK9Sm HcPkNwGijIseRI12ezjj6GfrzeafsHuEl1weFaM+1Hl3uoFID9qhTp9CHk8WHcemyCS0 D99PymBqZ/S1RLQM88poN1REZ1Nh/utP5QcBNLMsRWNNhvwPfGYe1w1+zErdJ1qhYF15 sVDw== X-Gm-Message-State: AEkoouvTfOT9ZCnzTARxvdLwFdCirikyv0K9Y/crJF7gTTEz5r2MtEdC78x9+9qJGR20TiqL X-Received: by 10.98.60.20 with SMTP id j20mr55592073pfa.114.1469677800543; Wed, 27 Jul 2016 20:50:00 -0700 (PDT) Received: from apronin0.mtv.corp.google.com ([172.22.64.136]) by smtp.gmail.com with ESMTPSA id t80sm12483771pfj.38.2016.07.27.20.49.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 27 Jul 2016 20:50:00 -0700 (PDT) From: Andrey Pronin To: Jarkko Sakkinen Date: Wed, 27 Jul 2016 20:49:56 -0700 Message-Id: <1469677797-74304-2-git-send-email-apronin@chromium.org> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1469677797-74304-1-git-send-email-apronin@chromium.org> References: <1468546745-14646-1-git-send-email-apronin@chromium.org> <1469677797-74304-1-git-send-email-apronin@chromium.org> In-Reply-To: <1468546745-14646-1-git-send-email-apronin@chromium.org> References: <1468546745-14646-1-git-send-email-apronin@chromium.org> X-Headers-End: 1bScKk-0001qZ-7o Cc: Christophe Ricard , dianders@chromium.org, linux-kernel@vger.kernel.org, smbarber@chromium.org, tpmdd-devel@lists.sourceforge.net, dtor@chromium.org Subject: [tpmdd-devel] [PATCH v3 1/2] tpm_tis_core: add optional max xfer size check 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: , MIME-Version: 1.0 Errors-To: tpmdd-devel-bounces@lists.sourceforge.net X-Virus-Scanned: ClamAV using ClamSMTP If tpm reports a bigger burstcnt than allowed by the physical protocol, set burstcnt to the max allowed value. In practice, seen in case of xfer issues (e.g. in spi interface case, lost header causing flow control issues and wrong values returned on read from TPM_STS). Without catching, causes the physical layer to reject xfer. Signed-off-by: Andrey Pronin Reviewed-by: Dmitry Torokhov Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 9 ++++++++- drivers/char/tpm/tpm_tis_core.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index f22caf8..7c4fa0c 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -168,8 +168,15 @@ static int get_burstcount(struct tpm_chip *chip) return rc; burstcnt = (value >> 8) & 0xFFFF; - if (burstcnt) + if (burstcnt) { + if (priv->phy_ops->max_xfer_size && + (burstcnt > priv->phy_ops->max_xfer_size)) { + dev_warn(&chip->dev, + "Bad burstcnt read: %d\n", burstcnt); + burstcnt = priv->phy_ops->max_xfer_size; + } return burstcnt; + } msleep(TPM_TIMEOUT); } while (time_before(jiffies, stop)); return -EBUSY; diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h index 9191aab..58e8b14 100644 --- a/drivers/char/tpm/tpm_tis_core.h +++ b/drivers/char/tpm/tpm_tis_core.h @@ -102,6 +102,7 @@ struct tpm_tis_phy_ops { int (*read16)(struct tpm_tis_data *data, u32 addr, u16 *result); int (*read32)(struct tpm_tis_data *data, u32 addr, u32 *result); int (*write32)(struct tpm_tis_data *data, u32 addr, u32 src); + u16 max_xfer_size; }; static inline int tpm_tis_read_bytes(struct tpm_tis_data *data, u32 addr,