From patchwork Fri Feb 24 21:16:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 9591169 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 D2E7D601AE for ; Fri, 24 Feb 2017 21:16:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C276E2895D for ; Fri, 24 Feb 2017 21:16:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B75B728965; Fri, 24 Feb 2017 21:16:10 +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 vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 401582895D for ; Fri, 24 Feb 2017 21:16:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751219AbdBXVQJ (ORCPT ); Fri, 24 Feb 2017 16:16:09 -0500 Received: from quartz.orcorp.ca ([184.70.90.242]:53184 "EHLO quartz.orcorp.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751163AbdBXVQJ (ORCPT ); Fri, 24 Feb 2017 16:16:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=obsidianresearch.com; s=rsa1; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=956HL3DlNF6bkTVgrktkfO8UZeLFCVmbU05nxRGgdIw=; b=cQeIa70d5vLhDewEUwxPpcFbr9JULo9qJmfvyQRG13iue0kmNIx9mkhUyHa5rGuk4KRSubpf3OuSBbTPti8izb1m9SHHYM9spz3jo6cvhWH2QYedqU4HLalE+W58XdOs9AcBfOyIGeGiedzl+lsfd9niu4OA899g80V0HZBN9xE=; Received: from [10.0.0.156] (helo=jggl.edm.orcorp.ca) by quartz.orcorp.ca with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1chNDj-0001Jx-5g; Fri, 24 Feb 2017 14:16:07 -0700 Received: from jgg by jggl.edm.orcorp.ca with local (Exim 4.86_2) (envelope-from ) id 1chNDj-0007bd-3a; Fri, 24 Feb 2017 14:16:07 -0700 Date: Fri, 24 Feb 2017 14:16:07 -0700 From: Jason Gunthorpe To: Jarkko Sakkinen Cc: tpmdd-devel@lists.sourceforge.net, linux-security-module@vger.kernel.org Subject: Re: [PATCH] tpm: Use the right clean up after cdev_add completes Message-ID: <20170224211607.GB28016@obsidianresearch.com> References: <20170223211914.GA12752@obsidianresearch.com> <20170224174354.w5e2v3nxntod72je@intel.com> <20170224205949.u63xb5qhqzd7lqtp@intel.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170224205949.u63xb5qhqzd7lqtp@intel.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Broken-Reverse-DNS: no host name found for IP address 10.0.0.156 Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP On Fri, Feb 24, 2017 at 10:59:50PM +0200, Jarkko Sakkinen wrote: > On Fri, Feb 24, 2017 at 07:43:54PM +0200, Jarkko Sakkinen wrote: > > On Thu, Feb 23, 2017 at 02:19:14PM -0700, Jason Gunthorpe wrote: > > > Once cdev_add is done the device node is visible to user space and > > > could have been opened. Thus we have to go through the locking > > > process in tpm_del_char_device if device_add fails. > > > > > > Fixes: 2c91ce8523a ("tpm: fix the rollback in tpm_chip_register()") > > > Signed-off-by: Jason Gunthorpe > > > > Pushed. > > It would make easier to merge this with resource manager commits if > there was instead > > void tpm_chip_shutdown(struct tpm_chip *chip) > { > /* Make the driver uncallable. */ > down_write(&chip->ops_sem); > if (chip->flags & TPM_CHIP_FLAG_TPM2) > tpm2_shutdown(chip, TPM2_SU_CLEAR); > chip->ops = NULL; > up_write(&chip->ops_sem); > } > > And you would call this instead of wiring into tpm_del_char_device. Hum.. I think this direction in the RM patch would be more maintainable.. Otherwise tpm_add_char_device has very complicated error handling. --- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index c82acf0a6e7353..444cf2495ef0e0 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -353,18 +353,26 @@ int tpm_chip_register(struct tpm_chip *chip) tpm_add_ppi(chip); rc = tpm_add_char_device(chip); - if (rc) { - tpm_bios_log_teardown(chip); - return rc; - } + if (rc) + goto err_add_char; + + rc = tpm_add_rm_char_device(chip); + if (rc) + goto err_add_rm_char; rc = tpm_add_legacy_sysfs(chip); - if (rc) { - tpm_chip_unregister(chip); - return rc; - } + if (rc) + goto err_add_legacy_sysfs; return 0; + +err_add_legacy_sysfs: + tpm_del_rm_char_device(chip); +err_add_rm_char: + tpm_del_char_device(chip, true); +err_add_char: + tpm_bios_log_teardown(chip); + return rc; } EXPORT_SYMBOL_GPL(tpm_chip_register); @@ -384,6 +392,7 @@ EXPORT_SYMBOL_GPL(tpm_chip_register); void tpm_chip_unregister(struct tpm_chip *chip) { tpm_del_legacy_sysfs(chip); + tpm_del_rm_char_device(chip); tpm_bios_log_teardown(chip); tpm_del_char_device(chip, true); }