From patchwork Fri Jun 2 21:55:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Zimmerman X-Patchwork-Id: 770616 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 3wfdMZ2812z9s7B for ; Sat, 3 Jun 2017 07:56:26 +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="DDzIBo8L"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sf.net header.i=@sf.net header.b="L//qHmLW"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="Jecoaben"; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1dGuYO-0005Oq-KZ; Fri, 02 Jun 2017 21:56:20 +0000 Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1dGuYN-0005Oi-F7 for tpmdd-devel@lists.sourceforge.net; Fri, 02 Jun 2017 21:56:19 +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=yAeCaLUwVOfvgaVnjE3kBI7EPTlDWPYdjyEMdYND+5Y=; b=DDzIBo8L3ILL7bCi92Vr4TnbRNE731um9/oMLtMnyab9NNGRvEEVZQdMY50p9Qzns5xPpyB5SVnqY2igeYyKC5w+kohLy9RDgDD5r57u9MoK4Mw/38E9WFmYDf3by78gRM7z6tl1CeBaRWI+bQu6RImvUs3bRlF1eQ9CR4CGoPE=; 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=yAeCaLUwVOfvgaVnjE3kBI7EPTlDWPYdjyEMdYND+5Y=; b=L//qHmLW/FvCxk/IKYgNguJEUXD9uEe+ncI7YQF4WMfks9KqT4+O4hPIIEqwLP2dhSl43BjZaxAcr5XMeaV7X/OPiYN4D9qtVHQp9pKozPgXqllW0ve6uJo5InZbyUHeyIaOWqihEuxCSTJAufnCJVEcuHagYJyHg/ZsFrS9Wlc=; Received-SPF: pass (sog-mx-4.v43.ch3.sourceforge.com: domain of google.com designates 209.85.216.172 as permitted sender) client-ip=209.85.216.172; envelope-from=joshz@google.com; helo=mail-qt0-f172.google.com; Received: from mail-qt0-f172.google.com ([209.85.216.172]) by sog-mx-4.v43.ch3.sourceforge.com with esmtps (TLSv1:AES128-SHA:128) (Exim 4.76) id 1dGuYM-0000Df-FT for tpmdd-devel@lists.sourceforge.net; Fri, 02 Jun 2017 21:56:19 +0000 Received: by mail-qt0-f172.google.com with SMTP id f55so69049344qta.3 for ; Fri, 02 Jun 2017 14:56:18 -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=yAeCaLUwVOfvgaVnjE3kBI7EPTlDWPYdjyEMdYND+5Y=; b=JecoabenLsrzJ2uqS68IUTseiBz89k60O9f/vODkrHKaJUSF7m5x8zNQMqhPmXXwuJ vZN2VbXMVMGA1fL9GtvyiEiBGJGtSdKFOIN9z5EYwkHEyepyX8wsRcM5J46BYV+nmtqY E0v6HbUxXkOp0lFSJDQV2Ekagy8obr8PGu5YZT3yv+d58p5PbQYwCC9T88ILZWLiA070 6dcNX+BHLwEAi5nqZ/tpuIqBc2tx1eOZxp3MukRpDpj9QnKECNX9XK8O+IoPAyPgT1dv PjEUc2LUW3VlJuQTvxqQxNFR7IH9L3mZc4ZyLLu0zSjNAgZozN45FNdqbcuNamobOpD6 cDng== 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=yAeCaLUwVOfvgaVnjE3kBI7EPTlDWPYdjyEMdYND+5Y=; b=jj79mGsUDqgcbJbSKzFtkJKnjOM85asfrURf/UPTCy4IP1j9bb9bvWHljPPgcjGMpn xQDwnKDo5RxvjXM05PDqm198I9vKgmpAsRQ+lI7a5Qi5LBpN1vrpP71lWBKit7rQwyBt zE6iMCMn0yK/wkxQaaBJ6EtYfXGTfpUJFajP4i7zIkI7bawZQA1+Px5Cus+dn2oVq97Z 8rYfjnzIo/gw5O68VxE5SVYiCqi7BAwhYfcBTVjY7oLnher/AbCH0YOmeR0OMsWg2Eg8 L9GvVMhnN4ZQewTDrfWq3fGRWDhRb+9YdQc+N23R5rHs5GZHP9dSpPUmJyMVBVUUaQjC 9VNQ== X-Gm-Message-State: AODbwcB4kZtRaXlTAqbcJWH1hSMuWyXX7fsLUGyz2duhIe0zzBCsZT8a CmRgD3cbSqxyQNOCCoT/AG3Yw/B34fx1 X-Received: by 10.237.34.41 with SMTP id n38mr11117001qtc.29.1496440572738; Fri, 02 Jun 2017 14:56:12 -0700 (PDT) MIME-Version: 1.0 Received: by 10.140.82.180 with HTTP; Fri, 2 Jun 2017 14:55:52 -0700 (PDT) From: Josh Zimmerman Date: Fri, 2 Jun 2017 14:55:52 -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. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [209.85.216.172 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain 0.5 RCVD_IN_SORBS_SPAM RBL: SORBS: sender is a spam source [209.85.216.172 listed in dnsbl.sorbs.net] -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: 1dGuYM-0000Df-FT Subject: [tpmdd-devel] [PATCH v6 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 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). v5: - Update documentation. v6: - Call device or bus shutdown from tpm_shutdown. --- drivers/char/tpm/tpm-chip.c | 31 +++++++++++++++++++++++++++++++ drivers/char/tpm/tpm-sysfs.c | 3 +++ 2 files changed, 34 insertions(+) diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index 9dec9f551b83..62691d266f22 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -142,6 +142,36 @@ static void tpm_devs_release(struct device *dev) put_device(&chip->dev); } +/** + * tpm_shutdown() - prepare the TPM device for loss of power. + * @dev: device to which the chip is associated. + * + * Issues a TPM2_Shutdown command prior to loss of power, as required by the + * TPM 2.0 spec. + * + * XXX: This codepath relies on the fact that sysfs is not enabled for + * TPM2: sysfs uses an implicit lock on chip->ops, so this could race if TPM2 + * has sysfs support enabled before TPM sysfs's implicit locking is fixed. + */ +static void tpm_shutdown(struct device *dev) +{ + struct tpm_chip *chip = container_of(dev, struct tpm_chip, dev); + + 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); + } + // Allow bus- and device-specific code to run. Note: since chip->ops + // is NULL, more-specific shutdown code will not be able to issue TPM + // commands. + if (dev->bus->shutdown) + dev->bus->shutdown(dev); + else if (dev->driver && dev->driver->shutdown) + dev->driver->shutdown(dev); +} + /** * tpm_chip_alloc() - allocate a new struct tpm_chip instance * @pdev: device to which the chip is associated @@ -181,6 +211,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..59bd0b7b5959 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: If you wish to remove this restriction, you must first update + * tpm_sysfs to explicitly lock chip->ops. + */ if (chip->flags & TPM_CHIP_FLAG_TPM2) return;