From patchwork Wed Jun 8 00:45:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ed Swierk X-Patchwork-Id: 9162953 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 A676A60831 for ; Wed, 8 Jun 2016 00:46:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 985C82837E for ; Wed, 8 Jun 2016 00:46:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D17028372; Wed, 8 Jun 2016 00:46:56 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable 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 EB10028372 for ; Wed, 8 Jun 2016 00:46:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754176AbcFHAqi (ORCPT ); Tue, 7 Jun 2016 20:46:38 -0400 Received: from mail-pf0-f177.google.com ([209.85.192.177]:36295 "EHLO mail-pf0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754162AbcFHAqg (ORCPT ); Tue, 7 Jun 2016 20:46:36 -0400 Received: by mail-pf0-f177.google.com with SMTP id t190so9076231pfb.3 for ; Tue, 07 Jun 2016 17:46:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skyportsystems.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=u5Uhqsor9O4hZHLZwGvID68OqMgCiY1+nxorM2KmAoY=; b=Cuha6OAJ5HklK0xLpcD2kLhkaJfPlwHMqrsd3k0Q5DLaakohdxWHYdaVsAsd+sv9Ph YrsNLuYLSxvgx3EIQMQwfJ3Om9gOe6lGUQnXZ8GV1LVA4DiXIwmZBmqbxoyp/UE+OEd/ PThvq9i0ohlEnYA3Xw/y/suuUFrInehVnRCTo= 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; bh=u5Uhqsor9O4hZHLZwGvID68OqMgCiY1+nxorM2KmAoY=; b=OMyOwf917gBRSA7gjAyRNSVfbJVnoAyj6FGnXS6wjhImdChaZcEqzTo+Rlq3xBvIJR Xhn511/14jpdXNbfVdh1WsF2g1K9FYqQK2pU+7iMcLZTBqH7vlWgWUGcCM/6nDe4zgZN Xy0gEISCm5zhqSNjKuS67s4ZgPEh+2ozSm6v+PMuqudQMyYtj+KiMmOLJHVsE0icKFCL lnxZZRCDAIrCmBiwzhxUQITgpp9BuqSsxtKjtcp86F8lm3/SiBiru+k+G7DHDoGBXAnJ WGmqEZoHpiXrKdgSiI16x4O2cxYvnvslBO2bqQDj+5IUq79UoDmc5MlRQfI6oBnJxM94 hk2Q== X-Gm-Message-State: ALyK8tLfpImO/uf8r+sU4U7w+cqgj2RSwERIKH9yJTnnQrTCIKXZu+OVPjoUzPSLvHvDPCiW X-Received: by 10.98.73.27 with SMTP id w27mr2444830pfa.137.1465346795067; Tue, 07 Jun 2016 17:46:35 -0700 (PDT) Received: from eswierk-sc.localdomain (67-207-112-138.static.wiline.com. [67.207.112.138]) by smtp.gmail.com with ESMTPSA id m1sm29489077pab.46.2016.06.07.17.46.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 Jun 2016 17:46:34 -0700 (PDT) From: Ed Swierk To: tpmdd-devel@lists.sourceforge.net Cc: eswierk@skyportsystems.com, stefanb@us.ibm.com, jarkko.sakkinen@linux.intel.com, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org Subject: [PATCH v4 4/4] tpm_tis: Increase ST19NP18 TPM command duration to avoid chip lockup Date: Tue, 7 Jun 2016 17:45:40 -0700 Message-Id: <1465346740-60120-5-git-send-email-eswierk@skyportsystems.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1465346740-60120-1-git-send-email-eswierk@skyportsystems.com> References: <1465346740-60120-1-git-send-email-eswierk@skyportsystems.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP The STMicro ST19NP18-TPM sometimes takes much longer to execute commands than it reports in its capabilities. For example, command 186 (TPM_FlushSpecific) has been observed to take 14560 msec to complete, far longer than the 3000 msec limit for "short" commands reported by the chip. The behavior has also been seen with command 101 (TPM_GetCapability). Worse, when the tpm_tis driver attempts to cancel the current command (by writing commandReady = 1 to TPM_STS_x), the chip locks up completely, returning all-1s from all memory-mapped register reads. The lockup can be cleared only by resetting the system. The occurrence of this excessive command duration depends on the sequence of commands preceding it. One sequence is creating at least 2 new keys via TPM_CreateWrapKey, then letting the TPM idle for at least 30 seconds, then loading a key via TPM_LoadKey2. The next TPM_FlushSpecific occasionally takes tens of seconds to complete. Another sequence is creating many keys in a row without pause. The TPM_CreateWrapKey operation gets much slower after the first few iterations, as one would expect when the pool of precomputed keys is exhausted. Then after a 35-second pause, the same TPM_LoadKey2 followed by TPM_FlushSpecific sequence triggers the behavior. Our working theory is that this older TPM sometimes pauses to precompute keys, which modern chips implement as a background process. Without access to the chip's implementation details it's impossible to know whether any commands are immune to being blocked by this process. So it seems safest to ignore the chip's reported command durations, and use a value much higher than any observed duration, like 180 sec (which is the duration this chip reports for "long" commands). Signed-off-by: Ed Swierk --- drivers/char/tpm/tpm_tis.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c index 5c74980..0041622 100644 --- a/drivers/char/tpm/tpm_tis.c +++ b/drivers/char/tpm/tpm_tis.c @@ -485,6 +485,11 @@ static void tpm_tis_update_timeouts(struct tpm_chip *chip) chip->vendor.timeout_d = TIS_SHORT_TIMEOUT * HZ / 1000; chip->vendor.timeout_adjusted = true; break; + case 0x0000104a: /* STMicro ST19NP18-TPM */ + chip->vendor.duration[TPM_SHORT] = 180 * HZ; + chip->vendor.duration[TPM_MEDIUM] = 180 * HZ; + chip->vendor.duration[TPM_LONG] = 180 * HZ; + chip->vendor.duration_adjusted = true; } }