diff mbox series

KEYS: trusted: fix crash when TPM/TEE are built as module

Message ID 20220204200342.48665-1-ztong0001@gmail.com (mailing list archive)
State New, archived
Headers show
Series KEYS: trusted: fix crash when TPM/TEE are built as module | expand

Commit Message

Tong Zhang Feb. 4, 2022, 8:03 p.m. UTC
when TCG_TPM and TEE are built as module, trusted_key_sources will be an
empty array, loading it won't do what it is supposed to do and unloading
it will cause kernel crash.

To reproduce:
$ modprobe trusted
$ modprobe -r trusted

[  173.749423] Unable to handle kernel NULL pointer dereference at virtual address 00000000
[  173.755268] Backtrace:
[  173.755378]  cleanup_trusted [trusted] from sys_delete_module+0x15c/0x22c
[  173.755589]  sys_delete_module from ret_fast_syscall+0x0/0x1c

To fix this issue, we also need to check CONFIG_TCG_TPM_MODULE and
CONFIG_TEE_MODULE.

Fixes: 5d0682be3189 ("KEYS: trusted: Add generic trusted keys framework")
Signed-off-by: Tong Zhang <ztong0001@gmail.com>
---
 security/keys/trusted-keys/trusted_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Ahmad Fatoum Feb. 6, 2022, 10:36 a.m. UTC | #1
Hello Tong,

On 04.02.22 21:03, Tong Zhang wrote:
> when TCG_TPM and TEE are built as module, trusted_key_sources will be an
> empty array, loading it won't do what it is supposed to do and unloading
> it will cause kernel crash.

Jarkko reported picking up an equivalent fix two months ago:
https://lkml.kernel.org/keyrings/YadRAWbl2aiapf8l@iki.fi/

But it seems to have never made it to Linus.

Cheers,
Ahmad

> 
> To reproduce:
> $ modprobe trusted
> $ modprobe -r trusted
> 
> [  173.749423] Unable to handle kernel NULL pointer dereference at virtual address 00000000
> [  173.755268] Backtrace:
> [  173.755378]  cleanup_trusted [trusted] from sys_delete_module+0x15c/0x22c
> [  173.755589]  sys_delete_module from ret_fast_syscall+0x0/0x1c
> 
> To fix this issue, we also need to check CONFIG_TCG_TPM_MODULE and
> CONFIG_TEE_MODULE.
> 
> Fixes: 5d0682be3189 ("KEYS: trusted: Add generic trusted keys framework")
> Signed-off-by: Tong Zhang <ztong0001@gmail.com>
> ---
>  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..b3a3b2f2d4a4 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 defined(CONFIG_TCG_TPM) || defined(CONFIG_TCG_TPM_MODULE)
>  	{ "tpm", &trusted_key_tpm_ops },
>  #endif
> -#if defined(CONFIG_TEE)
> +#if defined(CONFIG_TEE) || defined(CONFIG_TEE_MODULE)
>  	{ "tee", &trusted_key_tee_ops },
>  #endif
>  };
Tong Zhang Feb. 7, 2022, 11:12 p.m. UTC | #2
On Sun, Feb 6, 2022 at 2:36 AM Ahmad Fatoum <a.fatoum@pengutronix.de> wrote:
>
> Hello Tong,
>
> On 04.02.22 21:03, Tong Zhang wrote:
> > when TCG_TPM and TEE are built as module, trusted_key_sources will be an
> > empty array, loading it won't do what it is supposed to do and unloading
> > it will cause kernel crash.
>
> Jarkko reported picking up an equivalent fix two months ago:
> https://lkml.kernel.org/keyrings/YadRAWbl2aiapf8l@iki.fi/
>
> But it seems to have never made it to Linus.
>
> Cheers,
> Ahmad
>
> >
> > To reproduce:
> > $ modprobe trusted
> > $ modprobe -r trusted
> >
> > [  173.749423] Unable to handle kernel NULL pointer dereference at virtual address 00000000
> > [  173.755268] Backtrace:
> > [  173.755378]  cleanup_trusted [trusted] from sys_delete_module+0x15c/0x22c
> > [  173.755589]  sys_delete_module from ret_fast_syscall+0x0/0x1c
> >
> > To fix this issue, we also need to check CONFIG_TCG_TPM_MODULE and
> > CONFIG_TEE_MODULE.
> >
> > Fixes: 5d0682be3189 ("KEYS: trusted: Add generic trusted keys framework")
> > Signed-off-by: Tong Zhang <ztong0001@gmail.com>
> > ---
> >  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..b3a3b2f2d4a4 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 defined(CONFIG_TCG_TPM) || defined(CONFIG_TCG_TPM_MODULE)
> >       { "tpm", &trusted_key_tpm_ops },
> >  #endif
> > -#if defined(CONFIG_TEE)
> > +#if defined(CONFIG_TEE) || defined(CONFIG_TEE_MODULE)
> >       { "tee", &trusted_key_tee_ops },
> >  #endif
> >  };
>
>
> --
> Pengutronix e.K.                           |                             |
> Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

Hi Ahmad,
Thanks for letting me know.
That fix looks good to me.
- Tong
Jarkko Sakkinen Feb. 20, 2022, 11:05 p.m. UTC | #3
On Fri, Feb 04, 2022 at 12:03:42PM -0800, Tong Zhang wrote:
> when TCG_TPM and TEE are built as module, trusted_key_sources will be an
> empty array, loading it won't do what it is supposed to do and unloading
> it will cause kernel crash.
> 
> To reproduce:
> $ modprobe trusted
> $ modprobe -r trusted
> 
> [  173.749423] Unable to handle kernel NULL pointer dereference at virtual address 00000000
> [  173.755268] Backtrace:
> [  173.755378]  cleanup_trusted [trusted] from sys_delete_module+0x15c/0x22c
> [  173.755589]  sys_delete_module from ret_fast_syscall+0x0/0x1c
> 
> To fix this issue, we also need to check CONFIG_TCG_TPM_MODULE and
> CONFIG_TEE_MODULE.
> 
> Fixes: 5d0682be3189 ("KEYS: trusted: Add generic trusted keys framework")
> Signed-off-by: Tong Zhang <ztong0001@gmail.com>
> ---
>  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..b3a3b2f2d4a4 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 defined(CONFIG_TCG_TPM) || defined(CONFIG_TCG_TPM_MODULE)
>  	{ "tpm", &trusted_key_tpm_ops },
>  #endif
> -#if defined(CONFIG_TEE)
> +#if defined(CONFIG_TEE) || defined(CONFIG_TEE_MODULE)
>  	{ "tee", &trusted_key_tee_ops },
>  #endif
>  };
> -- 
> 2.25.1
> 


Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>

BR, Jarkko
Jarkko Sakkinen Feb. 20, 2022, 11:10 p.m. UTC | #4
On Sun, Feb 06, 2022 at 11:36:48AM +0100, Ahmad Fatoum wrote:
> Hello Tong,
> 
> On 04.02.22 21:03, Tong Zhang wrote:
> > when TCG_TPM and TEE are built as module, trusted_key_sources will be an
> > empty array, loading it won't do what it is supposed to do and unloading
> > it will cause kernel crash.
> 
> Jarkko reported picking up an equivalent fix two months ago:
> https://lkml.kernel.org/keyrings/YadRAWbl2aiapf8l@iki.fi/
> 
> But it seems to have never made it to Linus.

Sorry, was not done purposely. I pushed the original fix.

BR, Jarkko
diff mbox series

Patch

diff --git a/security/keys/trusted-keys/trusted_core.c b/security/keys/trusted-keys/trusted_core.c
index d5c891d8d353..b3a3b2f2d4a4 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 defined(CONFIG_TCG_TPM) || defined(CONFIG_TCG_TPM_MODULE)
 	{ "tpm", &trusted_key_tpm_ops },
 #endif
-#if defined(CONFIG_TEE)
+#if defined(CONFIG_TEE) || defined(CONFIG_TEE_MODULE)
 	{ "tee", &trusted_key_tee_ops },
 #endif
 };