From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755347AbcHYSdf (ORCPT ); Thu, 25 Aug 2016 14:33:35 -0400 Received: from quartz.orcorp.ca ([184.70.90.242]:54331 "EHLO quartz.orcorp.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751671AbcHYSdc (ORCPT ); Thu, 25 Aug 2016 14:33:32 -0400 Date: Thu, 25 Aug 2016 12:30:59 -0600 From: Jason Gunthorpe To: Jarkko Sakkinen Cc: Peter Huewe , linux-security-module@vger.kernel.org, stable@vger.kernel.org, Marcel Selhorst , "moderated list:TPM DEVICE DRIVER" , open list Subject: Re: [PATCH] tpm: fix a race condition tpm2_unseal_trusted() Message-ID: <20160825183059.GB1142@obsidianresearch.com> References: <1472000243-7088-1-git-send-email-jarkko.sakkinen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1472000243-7088-1-git-send-email-jarkko.sakkinen@linux.intel.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Broken-Reverse-DNS: no host name found for IP address 10.0.0.151 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 23, 2016 at 08:57:22PM -0400, Jarkko Sakkinen wrote: > + if (flags & TPM_TRANSMIT_LOCK) > + mutex_lock(&chip->tpm_mutex); I think I would invert this. UNLOCKED is the exceptional case, so I'd make the 0 flags lock. If we see UNLOCKED in the caller then we know to audit for locking, 0 is much less obvious. > @@ -576,7 +576,7 @@ static int tpm2_load(struct tpm_chip *chip, > goto out; > } > > - rc = tpm_transmit_cmd(chip, buf.data, PAGE_SIZE, "loading blob"); > + rc = __tpm_transmit_cmd(chip, buf.data, PAGE_SIZE, "loading blob", 0); All these points should accept a flags too and the caller should pass in the TPM_TRASNMIT_UNLOCKED if it needs it.. > + mutex_lock(&chip->tpm_mutex); > rc = tpm2_load(chip, payload, options, &blob_handle); > if (rc) So when we read here we see the pattern: > + mutex_lock(&chip->tpm_mutex); > rc = tpm2_load(chip, payload, options, &blob_handle, TPM_TRASNMIT_UNLOCKED); Which is much easier to audit.. Jason