From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jason Gunthorpe Date: Mon, 23 Oct 2017 16:31:39 +0000 Subject: Re: [tpmdd-devel] [PATCH] tpm: remove chip_num parameter from in-kernel API Message-Id: <20171023163139.GA17394@obsidianresearch.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit List-Id: References: <20171023123817.18559-1-jarkko.sakkinen@linux.intel.com> In-Reply-To: To: Stefan Berger Cc: Jarkko Sakkinen , linux-integrity@vger.kernel.org, David Howells , Herbert Xu , "open list:INTEGRITY MEASUREMENT ARCHITECTURE IMA" , Dmitry Kasatkin , open list , linux-security-module@vger.kernel.org, "moderated list:TPM DEVICE DRIVER" , "open list:KEYS-TRUSTED" , "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , James Morris , Matt Mackall , "open list:INTEGRITY MEASUREMENT ARCHITECTURE IMA" On Mon, Oct 23, 2017 at 10:07:31AM -0400, Stefan Berger wrote: > >-int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash) > >+int tpm_pcr_extend(int pcr_idx, const u8 *hash) > > { > > > I think every kernel internal TPM driver API should be called with the > tpm_chip as a parameter. This is in foresight of namespacing of IMA where we > want to provide the flexibility of passing a dedicated vTPM to each > namespace and IMA would use the chip as a parameter to all of these > functions to talk to the right tpm_vtpm_proxy instance. From that > perspective this patch goes into the wrong direction. Yes, we should ultimately try and get to there.. Someday the tpm_chip_find_get() will need to become namespace aware. But this patch is along the right path, eliminating the chip_num is the right thing to do.. > >- tpm2 = tpm_is_tpm2(TPM_ANY_NUM); > >+ tpm2 = tpm_is_tpm2(); > > if (tpm2 < 0) > > return tpm2; > > > >@@ -1008,7 +1007,7 @@ static int trusted_instantiate(struct key *key, > > switch (key_cmd) { > > case Opt_load: > > if (tpm2) > >- ret = tpm_unseal_trusted(TPM_ANY_NUM, payload, options); > >+ ret = tpm_unseal_trusted(payload, options); Sequences like this are sketchy. It should be struct tpm_chip *tpm; tpm = tpm_chip_find_get() tpm2 = tpm_is_tpm2(tpm); [..] if (tpm2) ret = tpm_unseal_trusted(tpm, payload, options); [..] tpm_put_chip(tpm); As hot plug could alter the 'tpm' between the two tpm calls. Jason From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jason Gunthorpe Subject: Re: [tpmdd-devel] [PATCH] tpm: remove chip_num parameter from in-kernel API Date: Mon, 23 Oct 2017 10:31:39 -0600 Message-ID: <20171023163139.GA17394@obsidianresearch.com> References: <20171023123817.18559-1-jarkko.sakkinen@linux.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Jarkko Sakkinen , linux-integrity@vger.kernel.org, David Howells , Herbert Xu , "open list:INTEGRITY MEASUREMENT ARCHITECTURE IMA" , Dmitry Kasatkin , open list , linux-security-module@vger.kernel.org, "moderated list:TPM DEVICE DRIVER" , "open list:KEYS-TRUSTED" , "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , James Morris , Matt Mackall , "open list:INTEGRITY MEASUREMENT ARCHITECTURE IMA" , To: Stefan Berger Return-path: Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org List-Id: linux-crypto.vger.kernel.org On Mon, Oct 23, 2017 at 10:07:31AM -0400, Stefan Berger wrote: > >-int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash) > >+int tpm_pcr_extend(int pcr_idx, const u8 *hash) > > { > > > I think every kernel internal TPM driver API should be called with the > tpm_chip as a parameter. This is in foresight of namespacing of IMA where we > want to provide the flexibility of passing a dedicated vTPM to each > namespace and IMA would use the chip as a parameter to all of these > functions to talk to the right tpm_vtpm_proxy instance. From that > perspective this patch goes into the wrong direction. Yes, we should ultimately try and get to there.. Someday the tpm_chip_find_get() will need to become namespace aware. But this patch is along the right path, eliminating the chip_num is the right thing to do.. > >- tpm2 = tpm_is_tpm2(TPM_ANY_NUM); > >+ tpm2 = tpm_is_tpm2(); > > if (tpm2 < 0) > > return tpm2; > > > >@@ -1008,7 +1007,7 @@ static int trusted_instantiate(struct key *key, > > switch (key_cmd) { > > case Opt_load: > > if (tpm2) > >- ret = tpm_unseal_trusted(TPM_ANY_NUM, payload, options); > >+ ret = tpm_unseal_trusted(payload, options); Sequences like this are sketchy. It should be struct tpm_chip *tpm; tpm = tpm_chip_find_get() tpm2 = tpm_is_tpm2(tpm); [..] if (tpm2) ret = tpm_unseal_trusted(tpm, payload, options); [..] tpm_put_chip(tpm); As hot plug could alter the 'tpm' between the two tpm calls. Jason From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from quartz.orcorp.ca ([184.70.90.242]:34039 "EHLO quartz.orcorp.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751280AbdJWQby (ORCPT ); Mon, 23 Oct 2017 12:31:54 -0400 Date: Mon, 23 Oct 2017 10:31:39 -0600 From: Jason Gunthorpe To: Stefan Berger Cc: Jarkko Sakkinen , linux-integrity@vger.kernel.org, David Howells , Herbert Xu , "open list:INTEGRITY MEASUREMENT ARCHITECTURE IMA" , Dmitry Kasatkin , open list , linux-security-module@vger.kernel.org, "moderated list:TPM DEVICE DRIVER" , "open list:KEYS-TRUSTED" , "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , James Morris , Matt Mackall , "open list:INTEGRITY MEASUREMENT ARCHITECTURE IMA" , David Safford , Mimi Zohar , "Serge E. Hallyn" Subject: Re: [tpmdd-devel] [PATCH] tpm: remove chip_num parameter from in-kernel API Message-ID: <20171023163139.GA17394@obsidianresearch.com> References: <20171023123817.18559-1-jarkko.sakkinen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii In-Reply-To: Sender: linux-integrity-owner@vger.kernel.org List-ID: On Mon, Oct 23, 2017 at 10:07:31AM -0400, Stefan Berger wrote: > >-int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash) > >+int tpm_pcr_extend(int pcr_idx, const u8 *hash) > > { > > > I think every kernel internal TPM driver API should be called with the > tpm_chip as a parameter. This is in foresight of namespacing of IMA where we > want to provide the flexibility of passing a dedicated vTPM to each > namespace and IMA would use the chip as a parameter to all of these > functions to talk to the right tpm_vtpm_proxy instance. From that > perspective this patch goes into the wrong direction. Yes, we should ultimately try and get to there.. Someday the tpm_chip_find_get() will need to become namespace aware. But this patch is along the right path, eliminating the chip_num is the right thing to do.. > >- tpm2 = tpm_is_tpm2(TPM_ANY_NUM); > >+ tpm2 = tpm_is_tpm2(); > > if (tpm2 < 0) > > return tpm2; > > > >@@ -1008,7 +1007,7 @@ static int trusted_instantiate(struct key *key, > > switch (key_cmd) { > > case Opt_load: > > if (tpm2) > >- ret = tpm_unseal_trusted(TPM_ANY_NUM, payload, options); > >+ ret = tpm_unseal_trusted(payload, options); Sequences like this are sketchy. It should be struct tpm_chip *tpm; tpm = tpm_chip_find_get() tpm2 = tpm_is_tpm2(tpm); [..] if (tpm2) ret = tpm_unseal_trusted(tpm, payload, options); [..] tpm_put_chip(tpm); As hot plug could alter the 'tpm' between the two tpm calls. Jason From mboxrd@z Thu Jan 1 00:00:00 1970 From: jgunthorpe@obsidianresearch.com (Jason Gunthorpe) Date: Mon, 23 Oct 2017 10:31:39 -0600 Subject: [tpmdd-devel] [PATCH] tpm: remove chip_num parameter from in-kernel API In-Reply-To: References: <20171023123817.18559-1-jarkko.sakkinen@linux.intel.com> Message-ID: <20171023163139.GA17394@obsidianresearch.com> To: linux-security-module@vger.kernel.org List-Id: linux-security-module.vger.kernel.org On Mon, Oct 23, 2017 at 10:07:31AM -0400, Stefan Berger wrote: > >-int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash) > >+int tpm_pcr_extend(int pcr_idx, const u8 *hash) > > { > > > I think every kernel internal TPM driver API should be called with the > tpm_chip as a parameter. This is in foresight of namespacing of IMA where we > want to provide the flexibility of passing a dedicated vTPM to each > namespace and IMA would use the chip as a parameter to all of these > functions to talk to the right tpm_vtpm_proxy instance. From that > perspective this patch goes into the wrong direction. Yes, we should ultimately try and get to there.. Someday the tpm_chip_find_get() will need to become namespace aware. But this patch is along the right path, eliminating the chip_num is the right thing to do.. > >- tpm2 = tpm_is_tpm2(TPM_ANY_NUM); > >+ tpm2 = tpm_is_tpm2(); > > if (tpm2 < 0) > > return tpm2; > > > >@@ -1008,7 +1007,7 @@ static int trusted_instantiate(struct key *key, > > switch (key_cmd) { > > case Opt_load: > > if (tpm2) > >- ret = tpm_unseal_trusted(TPM_ANY_NUM, payload, options); > >+ ret = tpm_unseal_trusted(payload, options); Sequences like this are sketchy. It should be struct tpm_chip *tpm; tpm = tpm_chip_find_get() tpm2 = tpm_is_tpm2(tpm); [..] if (tpm2) ret = tpm_unseal_trusted(tpm, payload, options); [..] tpm_put_chip(tpm); As hot plug could alter the 'tpm' between the two tpm calls. Jason -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jason Gunthorpe Subject: Re: [tpmdd-devel] [PATCH] tpm: remove chip_num parameter from in-kernel API Date: Mon, 23 Oct 2017 10:31:39 -0600 Message-ID: <20171023163139.GA17394@obsidianresearch.com> References: <20171023123817.18559-1-jarkko.sakkinen@linux.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org To: Stefan Berger Cc: Jarkko Sakkinen , linux-integrity@vger.kernel.org, David Howells , Herbert Xu , "open list:INTEGRITY MEASUREMENT ARCHITECTURE IMA" , Dmitry Kasatkin , open list , linux-security-module@vger.kernel.org, "moderated list:TPM DEVICE DRIVER" , "open list:KEYS-TRUSTED" , "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , James Morris , Matt Mackall , "open list:INTEGRITY MEASUREMENT ARCHITECTURE IMA" List-Id: tpmdd-devel@lists.sourceforge.net On Mon, Oct 23, 2017 at 10:07:31AM -0400, Stefan Berger wrote: > >-int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash) > >+int tpm_pcr_extend(int pcr_idx, const u8 *hash) > > { > > > I think every kernel internal TPM driver API should be called with the > tpm_chip as a parameter. This is in foresight of namespacing of IMA where we > want to provide the flexibility of passing a dedicated vTPM to each > namespace and IMA would use the chip as a parameter to all of these > functions to talk to the right tpm_vtpm_proxy instance. From that > perspective this patch goes into the wrong direction. Yes, we should ultimately try and get to there.. Someday the tpm_chip_find_get() will need to become namespace aware. But this patch is along the right path, eliminating the chip_num is the right thing to do.. > >- tpm2 = tpm_is_tpm2(TPM_ANY_NUM); > >+ tpm2 = tpm_is_tpm2(); > > if (tpm2 < 0) > > return tpm2; > > > >@@ -1008,7 +1007,7 @@ static int trusted_instantiate(struct key *key, > > switch (key_cmd) { > > case Opt_load: > > if (tpm2) > >- ret = tpm_unseal_trusted(TPM_ANY_NUM, payload, options); > >+ ret = tpm_unseal_trusted(payload, options); Sequences like this are sketchy. It should be struct tpm_chip *tpm; tpm = tpm_chip_find_get() tpm2 = tpm_is_tpm2(tpm); [..] if (tpm2) ret = tpm_unseal_trusted(tpm, payload, options); [..] tpm_put_chip(tpm); As hot plug could alter the 'tpm' between the two tpm calls. Jason