From patchwork Tue Jul 4 13:56:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Steffen X-Patchwork-Id: 9825073 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 23878603B5 for ; Tue, 4 Jul 2017 14:08:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 142DB200F5 for ; Tue, 4 Jul 2017 14:08:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 08FB1280B0; Tue, 4 Jul 2017 14:08:24 +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=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 89DBB200F5 for ; Tue, 4 Jul 2017 14:08:23 +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 1dSOV4-0001bN-K3; Tue, 04 Jul 2017 14:08:22 +0000 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1dSOV3-0001b8-CQ for tpmdd-devel@lists.sourceforge.net; Tue, 04 Jul 2017 14:08:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=3BXPG4exE/lyacj0q6zlDV3q1NRAk1O0HRDciIQoiWk=; b=m32jmueruWo4VChUFUdmxWlvUuJGdWJWqLYLOiOmAdoWWI6f9Kh2TGTFnPRV2IJxMl+iix1wym0NSq9qd6REX29i0JuL/ILkhlc9zAyGe60ODqYigG6MSD2ePwNIuZ4CH8sTxWH+ECsDlzDTBkzzyDQX3hbnM0wb5xBBzwoxTP8=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=3BXPG4exE/lyacj0q6zlDV3q1NRAk1O0HRDciIQoiWk=; b=iDEc8r41tN5MTBOm4W8ZupqimSsl7B6t2RWVfAMrq4aPthxcn3uuFQ2L4iipzexXa78DiWTrlpFQslLWWBKBf1SWm8kQg36MI+jU+rP5JwuJsjWoTTyQJY5G5qbAy7+uYVwYIPjmZ0uQ7z8CrirB7BbFjHnING6Fe6JFZUNyJkE=; Received-SPF: pass (sog-mx-2.v43.ch3.sourceforge.com: domain of infineon.com designates 217.10.52.105 as permitted sender) client-ip=217.10.52.105; envelope-from=alexander.steffen@infineon.com; helo=smtp11.infineon.com; Received: from smtp11.infineon.com ([217.10.52.105]) by sog-mx-2.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1dSOV2-0000x2-63 for tpmdd-devel@lists.sourceforge.net; Tue, 04 Jul 2017 14:08:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=infineon.com; i=@infineon.com; q=dns/txt; s=IFXMAIL; t=1499177300; x=1530713300; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=VxQx0yeg7D6mLv7CmRF6wZ2l8CqaWhV2wgKTeFmHgPM=; b=M19nJy5+jAhoG14V1DaVn7MytI2NsIlKCEhNOLZN/k2XCoiQLDxeUapG Th6QBiWikeWh5sCXuU/XUT9pr4TEIf+WwYSN4+31VEvzqwNh00iM5FTVH tox6Gdf1lCx1CWarmF8QTMLIk2yi3jakCnQxJRCqYJwIyrFD/8GcT1wDX 4=; X-SBRS: None Received: from unknown (HELO mucxv001.muc.infineon.com) ([172.23.11.16]) by smtp11.infineon.com with ESMTP/TLS/AES256-GCM-SHA384; 04 Jul 2017 15:57:01 +0200 Received: from MUCSE606.infineon.com (unknown [172.23.7.107]) by mucxv001.muc.infineon.com (Postfix) with ESMTPS for ; Tue, 4 Jul 2017 15:56:59 +0200 (CEST) Received: from MUCSE603.infineon.com (172.23.7.104) by MUCSE606.infineon.com (172.23.7.107) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Tue, 4 Jul 2017 15:56:59 +0200 Received: from ABGN5CG4522MQD.eu.infineon.com (172.29.170.97) by MUCSE603.infineon.com (172.23.7.104) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Tue, 4 Jul 2017 15:56:59 +0200 From: Alexander Steffen To: Date: Tue, 4 Jul 2017 15:56:48 +0200 Message-ID: <20170704135648.7360-3-Alexander.Steffen@infineon.com> X-Mailer: git-send-email 2.11.1.windows.1 In-Reply-To: <20170704135648.7360-1-Alexander.Steffen@infineon.com> References: <20170704135648.7360-1-Alexander.Steffen@infineon.com> MIME-Version: 1.0 X-Originating-IP: [172.29.170.97] X-ClientProxiedBy: MUCSE601.infineon.com (172.23.7.102) To MUCSE603.infineon.com (172.23.7.104) X-Headers-End: 1dSOV2-0000x2-63 Subject: [tpmdd-devel] [PATCH 3/3] tpm-chip: Export TPM device to user space even when startup failed 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 X-Virus-Scanned: ClamAV using ClamSMTP When one of the commands during the auto_startup sequences does not return TPM_RC_SUCCESS, tpm_chip_register misleadingly returns ENODEV, even though a TPM device is definitely present. An error response during those sequences is indeed unexpected, so to prevent subsequent errors, the kernel should not make use of the TPM device. But user space applications still might be able to communicate with the TPM, so they can be used to further diagnose and/or fix the problem. To allow this, with this patch the device is still exported to user space, even if a TPM error code has been received, but the kernel itself will not be allowed to use the device for anything. This is not a hypothetical scenario, but there are devices in the wild that show this behavior. With this fix, those devices can be recovered from their failed state. Signed-off-by: Alexander Steffen --- drivers/char/tpm/tpm-chip.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index f20fcb7..a4baa56 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -390,7 +390,7 @@ static int tpm_add_legacy_sysfs(struct tpm_chip *chip) * * Creates a character device for the TPM chip and adds sysfs attributes for * the device. As the last step this function adds the chip to the list of TPM - * chips available for in-kernel use. + * chips available for in-kernel use, if the TPM startup was successful. * * This function should be only called after the chip initialization is * complete. @@ -398,6 +398,7 @@ static int tpm_add_legacy_sysfs(struct tpm_chip *chip) int tpm_chip_register(struct tpm_chip *chip) { int rc; + bool startup_successful = true; if (chip->ops->flags & TPM_OPS_AUTO_STARTUP) { if (chip->flags & TPM_CHIP_FLAG_TPM2) @@ -407,7 +408,7 @@ int tpm_chip_register(struct tpm_chip *chip) if (rc < 0) return rc; else if (rc > 0) - return -ENODEV; + startup_successful = false; } tpm_sysfs_add_device(chip); @@ -430,10 +431,12 @@ int tpm_chip_register(struct tpm_chip *chip) return rc; } - /* Make the chip available. */ - mutex_lock(&idr_lock); - idr_replace(&dev_nums_idr, chip, chip->dev_num); - mutex_unlock(&idr_lock); + if (startup_successful) { + /* Make the chip available. */ + mutex_lock(&idr_lock); + idr_replace(&dev_nums_idr, chip, chip->dev_num); + mutex_unlock(&idr_lock); + } return 0; }