KEYS: trusted: fix crash when TPM/TEE are built as module
Subsystems (3)
PATCH 1/1 KEYS: trusted: fix crash when TPM/TEE are built as module
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.
--- security/keys/trusted-keys/trusted_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
security/keys/trusted-keys/trusted_core.c +2 -2
@@ -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 };
Signature · 1 line
2.25.1
Hello Tong,
Quoted 3 lines · Tong Zhang
when
TCG_TPMand TEE are built as module,trusted_key_sourceswill 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/[email protected]/
But it seems to have never made it to Linus.
Cheers,
Ahmad
Quoted 36 lines
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/0x1cTo fix this issue, we also need to check
CONFIG_TCG_TPM_MODULEandCONFIG_TEE_MODULE.Fixes 5d0682be3189 ("KEYS: trusted: Add generic trusted keys framework")Signed-off-by Tong Zhang <[email protected]>--- security/keys/trusted-keys/trusted_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)security/keys/trusted-keys/trusted_core.c +2
-2@@ -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 };
Signature · 4 lines
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 |
Quoted 55 lines · Ahmad Fatoum
Hello Tong,
Quoted 3 lines · Tong Zhang
when
TCG_TPMand TEE are built as module,trusted_key_sourceswill 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/[email protected]/But it seems to have never made it to Linus.
Cheers,
AhmadQuoted 26 lines
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/0x1cTo fix this issue, we also need to check
CONFIG_TCG_TPM_MODULEandCONFIG_TEE_MODULE.Fixes 5d0682be3189 ("KEYS: trusted: Add generic trusted keys framework")Signed-off-by Tong Zhang <[email protected]>--- security/keys/trusted-keys/trusted_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)security/keys/trusted-keys/trusted_core.c +0
-0@@ -27,10 +27,10 @@ module_param_named(source, trusted_key_source, charp, 0);MODULE_PARM_DESC (source,"Select trusted keys source (tpm or tee)" );security/keys/trusted-keys/trusted_core.c module_param_named(source, trusted_key_source, charp, 0); · line 36
Quoted 10 lines
security/keys/trusted-keys/trusted_core.c +2
-2static 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 };--
Quoted 4 lines
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
maintainerQuoted 11 lines · Ahmad Fatoum
Hello Tong,
Quoted 3 lines · Tong Zhang
when
TCG_TPMand TEE are built as module,trusted_key_sourceswill 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/[email protected]/But it seems to have never made it to Linus.
Sorry, was not done purposely. I pushed the original fix.
BR, Jarkko
kernel test robot
build botThank you for the patch! Yet something to improve:
Hi Tong,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on v5.17-rc2]
[also build test ERROR on next-20220208]
[cannot apply to jmorris-security/next-testing]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Tong-Zhang/KEYS-trusted-fix-crash-when-TPM-TEE-are-built-as-module/20220205-040706 base: 26291c54e111ff6ba87a164d85d4a4e134b7315c config: i386-randconfig-a011 (https://download.01.org/0day-ci/archive/20220209/202202090354.jnH19acv-lkp(a)intel.com/config) compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project e8bff9ae54a55b4dbfeb6ba55f723abbd81bf494)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/1f9dab49ae11af2bde1b057f7104ded0714ae7dd
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Tong-Zhang/KEYS-trusted-fix-crash-when-TPM-TEE-are-built-as-module/20220205-040706 git checkout 1f9dab49ae11af2bde1b057f7104ded0714ae7dd
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
>> ld.lld: error: undefined symbol: trusted_key_tee_ops >>> referenced by trusted_core.c >>> keys/trusted-keys/trusted_core.o:(trusted_key_sources) in archive security/built-in.a
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Quoted 42 lines · Tong Zhang
when
TCG_TPMand TEE are built as module,trusted_key_sourceswill 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/0x1cTo fix this issue, we also need to check
CONFIG_TCG_TPM_MODULEandCONFIG_TEE_MODULE.Fixes 5d0682be3189 ("KEYS: trusted: Add generic trusted keys framework")Signed-off-by Tong Zhang <[email protected]>--- security/keys/trusted-keys/trusted_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)security/keys/trusted-keys/trusted_core.c +2
-2@@ -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 };Signature · 1 line
2.25.1
BR, Jarkko