From patchwork Thu May 25 23:20:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Zimmerman X-Patchwork-Id: 767174 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 ozlabs.org (Postfix) with ESMTPS id 3wYlcv2PgYz9s8D for ; Fri, 26 May 2017 09:21:03 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sourceforge.net header.i=@sourceforge.net header.b="jpA36VxG"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sf.net header.i=@sf.net header.b="EmDAqPbp"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="hTBCNbad"; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=sfs-ml-4.v29.ch3.sourceforge.com) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1dE23t-0007j2-Su; Thu, 25 May 2017 23:20:57 +0000 Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194] helo=mx.sourceforge.net) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1dE23s-0007iZ-4H for tpmdd-devel@lists.sourceforge.net; Thu, 25 May 2017 23:20:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:To:Subject:Message-ID:Date:From:MIME-Version; bh=StbqCCL7xMTkS+TrR8xA6XIVe92FUSaDJagCIuxDX5M=; b=jpA36VxGjHWWgMHDGYRyKITbMR8WxZ3olx6lZ62+UvW5dIrrGep/kxmc8Z1t7EiAiFijK00UVrMN4giQ8NN6nDxRxvsGuwxJSvFFSD0YJN9UcbxMb8sFfyyfUnnaim8g6rsO8uJFEE/7GoUmAVuxQAkHMPsT4iRG3eadcQvsMMY=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x; h=Content-Type:To:Subject:Message-ID:Date:From:MIME-Version; bh=StbqCCL7xMTkS+TrR8xA6XIVe92FUSaDJagCIuxDX5M=; b=EmDAqPbpjrZ/ynbnSc7nbMY445vWju7SQfbq4NodBmCFB3c/QM0bYImzfcuvKucDWI/mgcQE6wuWzxfEnj7W+AYtjjrUE3cLRNRM9QdFwO4ZfEnDOGHVetYmPrBSb993dB+U2aktzvFYfu8EbXeG1ULI24VP0Bvl8CWUQSfF/w4=; Received-SPF: pass (sog-mx-4.v43.ch3.sourceforge.com: domain of google.com designates 209.85.220.174 as permitted sender) client-ip=209.85.220.174; envelope-from=joshz@google.com; helo=mail-qk0-f174.google.com; Received: from mail-qk0-f174.google.com ([209.85.220.174]) by sog-mx-4.v43.ch3.sourceforge.com with esmtps (TLSv1:AES128-SHA:128) (Exim 4.76) id 1dE23q-0006D1-4X for tpmdd-devel@lists.sourceforge.net; Thu, 25 May 2017 23:20:56 +0000 Received: by mail-qk0-f174.google.com with SMTP id u75so187928556qka.3 for ; Thu, 25 May 2017 16:20:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=StbqCCL7xMTkS+TrR8xA6XIVe92FUSaDJagCIuxDX5M=; b=hTBCNbadXG7YHjmxwvCUwPiD8T7mSWnjJ97/RHlx8t1cIkSkmSfQ3o8FnNQ4IHyAAA DcUQXRt4Ynf0EPpTdZzy9FjzyBepkbZFYyG5A6Ry8iV5dK8xicFHX1BoLK/EhdORGVQP AC3BuwO7n5cxwYKmz4McTgxlxTmYTHuUbgao5XvoPgVY4W4Uz7Q4H/6z5hlR4INakLHi BFxmAifmj6g3xSxD/MLXaWaS+TTmlKqod8A5+Qa2ESRiB9aXyyXoltIFqlII5jxKM649 WIzh0hnWta/dbubk22eueZynz9tGpBDYiObMBYo+rDt26Fjp5HbFyKySrJjfgJj5/4rG +nHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=StbqCCL7xMTkS+TrR8xA6XIVe92FUSaDJagCIuxDX5M=; b=sfKNRNf+j33wEIYjeGVgZJn+Td35TSlxV8KMKgzMp4ce2IJ/GsxzU0rRkNfsvOdRiw 0z2PyZeSgLD95nLoQfgfvkmqIhOIB7M/1z7yKXBM0KbS8mcdKyNJWhgJ5BoHjiSpRw2p fvzxEIs3GTy+zNQXg/9lQmOLfkg2XwJSlLEL/2/8JVszURC+cLRc/jgZkbeEgVajU0Es EYe6f2wng690/o+HT+mAOScxhXD8m0q9bL4ktbzLplymVN2eMwi789tujWXwYFn9/cBs AhsatjYpVZW8XlHG/9Jfnmx4IZFbBkKB0TrOwqQRSHQwpY1yxn7rlJFhLVWAywdzIudK 58sw== X-Gm-Message-State: AODbwcBFsoMtgu8y/WC//O3FbPIfiL2YccuwKOrkzqczHB0w6nkovRUd q+diCSo2lXE+hI+EpAZegs628Ebe2Ync X-Received: by 10.55.78.15 with SMTP id c15mr44417542qkb.62.1495754448502; Thu, 25 May 2017 16:20:48 -0700 (PDT) MIME-Version: 1.0 Received: by 10.140.82.180 with HTTP; Thu, 25 May 2017 16:20:28 -0700 (PDT) From: Josh Zimmerman Date: Thu, 25 May 2017 16:20:28 -0700 Message-ID: To: Peter Huewe , Marcel Selhorst , Jarkko Sakkinen , Jason Gunthorpe , tpmdd-devel@lists.sourceforge.net, jmorris@namei.org X-Spam-Score: -1.1 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [209.85.220.174 listed in list.dnswl.org] 0.5 RCVD_IN_SORBS_SPAM RBL: SORBS: sender is a spam source [209.85.220.174 listed in dnsbl.sorbs.net] -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1dE23q-0006D1-4X Subject: [tpmdd-devel] [PATCH v4 1/2] tpm: Issue a TPM2_Shutdown for TPM2 devices. X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 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 If a TPM2 loses power without a TPM2_Shutdown command being issued (a "disorderly reboot"), it may lose some state that has yet to be persisted to NVRam, and will increment the DA counter. After the DA counter gets sufficiently large, the TPM will lock the user out. NOTE: This only changes behavior on TPM2 devices. Since TPM1 uses sysfs, and sysfs relies on implicit locking on chip->ops, it is not safe to allow this code to run in TPM1, or to add sysfs support to TPM2, until that locking is made explicit. Signed-off-by: Josh Zimmerman Reviewed-by: Jarko Sakkinen Cc: stable@vger.kernel.org ---- v2: - Properly split changes between this and another commit - Use proper locking primitive. - Fix commenting style v3: - Re-fix commenting style v4: - Update description and tags (Reviewed-by, Cc). --- --- drivers/char/tpm/tpm-chip.c | 20 ++++++++++++++++++++ drivers/char/tpm/tpm-sysfs.c | 3 +++ 2 files changed, 23 insertions(+) -- 2.13.0.219.gdb65acc882-goog ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index 9dec9f551b83..272a42e77574 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -142,6 +142,25 @@ static void tpm_devs_release(struct device *dev) put_device(&chip->dev); } +static void tpm_shutdown(struct device *dev) +{ + struct tpm_chip *chip = container_of(dev, struct tpm_chip, dev); + /* TPM 2.0 requires that the TPM2_Shutdown() command be issued prior to + * loss of power. If it is not, the DA counter will be incremented and, + * eventually, the user will be locked out of their TPM. + * XXX: This codepath relies on the fact that sysfs is not enabled for + * TPM2: sysfs uses an implicit lock on chip->ops, so this use could + * race if TPM2 has sysfs support enabled before TPM sysfs's implicit + * locking is fixed. + */ + if (chip->flags & TPM_CHIP_FLAG_TPM2) { + down_write(&chip->ops_sem); + tpm2_shutdown(chip, TPM_SU_CLEAR); + chip->ops = NULL; + up_write(&chip->ops_sem); + } +} + /** * tpm_chip_alloc() - allocate a new struct tpm_chip instance * @pdev: device to which the chip is associated @@ -181,6 +200,7 @@ struct tpm_chip *tpm_chip_alloc(struct device *pdev, device_initialize(&chip->devs); chip->dev.class = tpm_class; + chip->dev.class.shutdown = tpm_shutdown; chip->dev.release = tpm_dev_release; chip->dev.parent = pdev; chip->dev.groups = chip->groups; diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c index 55405dbe43fa..5e5ff7eb6f7e 100644 --- a/drivers/char/tpm/tpm-sysfs.c +++ b/drivers/char/tpm/tpm-sysfs.c @@ -294,6 +294,9 @@ static const struct attribute_group tpm_dev_group = { void tpm_sysfs_add_device(struct tpm_chip *chip) { + /* XXX: Before this restriction is removed, tpm_sysfs must be updated + * to explicitly lock chip->ops. + */ if (chip->flags & TPM_CHIP_FLAG_TPM2) return;