2021-07-29 18:35:49

by Andreas Rammhold

[permalink] [raw]
Subject: [PATCH v2] KEYS: trusted: Fix trusted key backends when building as module

Before this commit the kernel could end up with no trusted key sources
even though both of the currently supported backends (TPM and TEE) were
compiled as modules. This manifested in the trusted key type not being
registered at all.

When checking if a CONFIG_… preprocessor variable is defined we only
test for the builtin (=y) case and not the module (=m) case. By using
the IS_REACHABLE() macro we do test for both cases.


v2:
* Fixed commit message
* Switched from IS_DEFINED() to IS_REACHABLE()


Fixes: 5d0682be3189 ("KEYS: trusted: Add generic trusted keys framework")
Signed-off-by: Andreas Rammhold <[email protected]>
---

Here is the version that was proposed by Ahmad [1] in response to the
feedback received in the "[PATCH v2] KEYS: trusted: fix use as module
when CONFIG_TCG_TPM=m" discussion [2].

I have tested both of the patches on v5.13 and they both fix the problem
I originally encountered.

[1] https://lore.kernel.org/keyrings/[email protected]/
[2] https://lore.kernel.org/keyrings/[email protected]/


security/keys/trusted-keys/trusted_core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/security/keys/trusted-keys/trusted_core.c b/security/keys/trusted-keys/trusted_core.c
index d5c891d8d353..5b35f1b87644 100644
--- a/security/keys/trusted-keys/trusted_core.c
+++ b/security/keys/trusted-keys/trusted_core.c
@@ -27,10 +27,10 @@ module_param_named(source, trusted_key_source, charp, 0);
MODULE_PARM_DESC(source, "Select trusted keys source (tpm or tee)");

static const struct trusted_key_source trusted_key_sources[] = {
-#if defined(CONFIG_TCG_TPM)
+#if IS_REACHABLE(CONFIG_TCG_TPM)
{ "tpm", &trusted_key_tpm_ops },
#endif
-#if defined(CONFIG_TEE)
+#if IS_REACHABLE(CONFIG_TEE)
{ "tee", &trusted_key_tee_ops },
#endif
};
--
2.32.0



2021-07-30 01:04:29

by Jarkko Sakkinen

[permalink] [raw]
Subject: Re: [PATCH v2] KEYS: trusted: Fix trusted key backends when building as module

On Thu, Jul 29, 2021 at 08:33:32PM +0200, Andreas Rammhold wrote:
> Before this commit the kernel could end up with no trusted key sources
> even though both of the currently supported backends (TPM and TEE) were
> compiled as modules. This manifested in the trusted key type not being
> registered at all.
>
> When checking if a CONFIG_… preprocessor variable is defined we only
> test for the builtin (=y) case and not the module (=m) case. By using
> the IS_REACHABLE() macro we do test for both cases.
>
>
> v2:
> * Fixed commit message
> * Switched from IS_DEFINED() to IS_REACHABLE()

Please put these below '---' because otherwise they included to the commit
log.

> Fixes: 5d0682be3189 ("KEYS: trusted: Add generic trusted keys framework")
> Signed-off-by: Andreas Rammhold <[email protected]>
> ---
>
> Here is the version that was proposed by Ahmad [1] in response to the
> feedback received in the "[PATCH v2] KEYS: trusted: fix use as module
> when CONFIG_TCG_TPM=m" discussion [2].
>
> I have tested both of the patches on v5.13 and they both fix the problem
> I originally encountered.
>
> [1] https://lore.kernel.org/keyrings/[email protected]/
> [2] https://lore.kernel.org/keyrings/[email protected]/
>
>
> security/keys/trusted-keys/trusted_core.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/security/keys/trusted-keys/trusted_core.c b/security/keys/trusted-keys/trusted_core.c
> index d5c891d8d353..5b35f1b87644 100644
> --- a/security/keys/trusted-keys/trusted_core.c
> +++ b/security/keys/trusted-keys/trusted_core.c
> @@ -27,10 +27,10 @@ module_param_named(source, trusted_key_source, charp, 0);
> MODULE_PARM_DESC(source, "Select trusted keys source (tpm or tee)");
>
> static const struct trusted_key_source trusted_key_sources[] = {
> -#if defined(CONFIG_TCG_TPM)
> +#if IS_REACHABLE(CONFIG_TCG_TPM)
> { "tpm", &trusted_key_tpm_ops },
> #endif
> -#if defined(CONFIG_TEE)
> +#if IS_REACHABLE(CONFIG_TEE)
> { "tee", &trusted_key_tee_ops },
> #endif
> };
> --
> 2.32.0
>
>

Can you send a one more v3 without the changelog in the commit message
and also add

Reviewed-by: Jarkko Sakkinen <[email protected]>

/Jarkko