char: tpm: vtpm_proxy: Fix race in init
Subsystems (2)
PATCH 1/1 char: tpm: vtpm_proxy: Fix race in init
vtpm_module_init calls vtpmx_init which calls misc_register. The file operations callbacks are registered. So, vtpmx_fops_ioctl can execute in parallel with rest of vtpm_module_init. vtpmx_fops_ioctl calls vtpmx_ioc_new_dev, which calls vtpm_proxy_create_device, which calls vtpm_proxy_work_start, which could read uninitialized workqueue.
To avoid this, create workqueue before vtpmx init.
Found by Linux Driver Verification project (linuxtesting.org).
--- drivers/char/tpm/tpm_vtpm_proxy.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/char/tpm/tpm_vtpm_proxy.c +9 -10
@@ -697,23 +697,22 @@ static int __init vtpm_module_init(void) {int rc; - rc =vtpmx_init (); -if (rc) { -pr_err ("couldn't create vtpmx device\n" ); -return rc; - } - workqueue =create_workqueue ("tpm-vtpm" );if (!workqueue) {pr_err ("couldn't create workqueue\n" ); - rc = -ENOMEM ; - goto err_vtpmx_cleanup; +return -ENOMEM ; + } + + rc =vtpmx_init (); +if (rc) { +pr_err ("couldn't create vtpmx device\n" ); + goto err_destroy_workqueue; }return 0 ; -err_vtpmx_cleanup: -vtpmx_cleanup (); +err_destroy_workqueue: +destroy_workqueue (workqueue);return rc; }
Signature · 1 line
2.30.2
Quoted 56 lines · Saubhik Mukherjee
vtpm_module_initcallsvtpmx_initwhich callsmisc_register. The file operations callbacks are registered. So,vtpmx_fops_ioctlcan execute in parallel with rest ofvtpm_module_init.vtpmx_fops_ioctlcallsvtpmx_ioc_new_dev, which callsvtpm_proxy_create_device, which callsvtpm_proxy_work_start, which could read uninitialized workqueue.To avoid this, create workqueue before vtpmx init.
Found by Linux Driver Verification project (linuxtesting.org).
Signed-off-by Saubhik Mukherjee <[email protected]>--- drivers/char/tpm/tpm_vtpm_proxy.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)drivers/char/tpm/tpm_vtpm_proxy.c +9
-10@@ -697,23 +697,22 @@ static int __init vtpm_module_init(void) {int rc; - rc =vtpmx_init (); -if (rc) { -pr_err ("couldn't create vtpmx device\n" ); -return rc; - } - workqueue =create_workqueue ("tpm-vtpm" );if (!workqueue) {pr_err ("couldn't create workqueue\n" ); - rc = -ENOMEM ; - goto err_vtpmx_cleanup; +return -ENOMEM ; + } + + rc =vtpmx_init (); +if (rc) { +pr_err ("couldn't create vtpmx device\n" ); + goto err_destroy_workqueue; }return 0 ; -err_vtpmx_cleanup: -vtpmx_cleanup (); +err_destroy_workqueue: +destroy_workqueue (workqueue);return rc; }Signature · 1 line
2.30.2
/Jarkko
Jarkko Sakkinen
maintainerQuoted 51 lines · Jarkko Sakkinen
Quoted 50 lines · Saubhik Mukherjee
vtpm_module_initcallsvtpmx_initwhich callsmisc_register. The file operations callbacks are registered. So,vtpmx_fops_ioctlcan execute in parallel with rest ofvtpm_module_init.vtpmx_fops_ioctlcallsvtpmx_ioc_new_dev, which callsvtpm_proxy_create_device, which callsvtpm_proxy_work_start, which could read uninitialized workqueue.To avoid this, create workqueue before vtpmx init.
Found by Linux Driver Verification project (linuxtesting.org).
Signed-off-by Saubhik Mukherjee <[email protected]>--- drivers/char/tpm/tpm_vtpm_proxy.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)drivers/char/tpm/tpm_vtpm_proxy.c +9
-10@@ -697,23 +697,22 @@ static int __init vtpm_module_init(void) {int rc; - rc =vtpmx_init (); -if (rc) { -pr_err ("couldn't create vtpmx device\n" ); -return rc; - } - workqueue =create_workqueue ("tpm-vtpm" );if (!workqueue) {pr_err ("couldn't create workqueue\n" ); - rc = -ENOMEM ; - goto err_vtpmx_cleanup; +return -ENOMEM ; + } + + rc =vtpmx_init (); +if (rc) { +pr_err ("couldn't create vtpmx device\n" ); + goto err_destroy_workqueue; }return 0 ; -err_vtpmx_cleanup: -vtpmx_cleanup (); +err_destroy_workqueue: +destroy_workqueue (workqueue);
Quoted 8 lines
Quoted 6 lines
drivers/char/tpm/tpm_vtpm_proxy.c +0
-0return rc; }Signature · 1 line
2.30.2Reviewed-by Jarkko Sakkinen <[email protected]>
Taking reviewed-by back.
You're lacking fixes tag. Please re-send with one.
/Jarkko
PATCH 1/1 char: tpm: vtpm_proxy: Fix race in init
vtpm_module_init calls vtpmx_init which calls misc_register. The file operations callbacks are registered. So, vtpmx_fops_ioctl can execute in parallel with rest of vtpm_module_init. vtpmx_fops_ioctl calls vtpmx_ioc_new_dev, which calls vtpm_proxy_create_device, which calls vtpm_proxy_work_start, which could read uninitialized workqueue.
To avoid this, create workqueue before vtpmx init.
Found by Linux Driver Verification project (linuxtesting.org).
--- drivers/char/tpm/tpm_vtpm_proxy.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/char/tpm/tpm_vtpm_proxy.c +9 -10
@@ -697,23 +697,22 @@ static int __init vtpm_module_init(void) {int rc; - rc =vtpmx_init (); -if (rc) { -pr_err ("couldn't create vtpmx device\n" ); -return rc; - } - workqueue =create_workqueue ("tpm-vtpm" );if (!workqueue) {pr_err ("couldn't create workqueue\n" ); - rc = -ENOMEM ; - goto err_vtpmx_cleanup; +return -ENOMEM ; + } + + rc =vtpmx_init (); +if (rc) { +pr_err ("couldn't create vtpmx device\n" ); + goto err_destroy_workqueue; }return 0 ; -err_vtpmx_cleanup: -vtpmx_cleanup (); +err_destroy_workqueue: +destroy_workqueue (workqueue);return rc; }
Signature · 1 line
2.30.2
Jarkko Sakkinen
maintainerQuoted 6 lines · Saubhik Mukherjee
vtpm_module_initcallsvtpmx_initwhich callsmisc_register. The file operations callbacks are registered. So,vtpmx_fops_ioctlcan execute in parallel with rest ofvtpm_module_init.vtpmx_fops_ioctlcallsvtpmx_ioc_new_dev, which callsvtpm_proxy_create_device, which callsvtpm_proxy_work_start, which could read uninitialized workqueue.
Quoted 7 lines
To avoid this, create workqueue before vtpmx init.
Found by Linux Driver Verification project (linuxtesting.org).
Fixes 6f99612e2500 ("tpm: Proxy driver for supporting multiple emulated TPMs")Signed-off-by Saubhik Mukherjee <[email protected]>---
Is this v2? What was changed?
Quoted 44 lines
drivers/char/tpm/tpm_vtpm_proxy.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)drivers/char/tpm/tpm_vtpm_proxy.c +9
-10@@ -697,23 +697,22 @@ static int __init vtpm_module_init(void) {int rc; - rc =vtpmx_init (); -if (rc) { -pr_err ("couldn't create vtpmx device\n" ); -return rc; - } - workqueue =create_workqueue ("tpm-vtpm" );if (!workqueue) {pr_err ("couldn't create workqueue\n" ); - rc = -ENOMEM ; - goto err_vtpmx_cleanup; +return -ENOMEM ; + } + + rc =vtpmx_init (); +if (rc) { +pr_err ("couldn't create vtpmx device\n" ); + goto err_destroy_workqueue; }return 0 ; -err_vtpmx_cleanup: -vtpmx_cleanup (); +err_destroy_workqueue: +destroy_workqueue (workqueue);return rc; }Signature · 1 line
2.30.2
/Jarkko
Quoted 61 lines · Jarkko Sakkinen
Quoted 51 lines · Jarkko Sakkinen
Quoted 50 lines · Saubhik Mukherjee
vtpm_module_initcallsvtpmx_initwhich callsmisc_register. The file operations callbacks are registered. So,vtpmx_fops_ioctlcan execute in parallel with rest ofvtpm_module_init.vtpmx_fops_ioctlcallsvtpmx_ioc_new_dev, which callsvtpm_proxy_create_device, which callsvtpm_proxy_work_start, which could read uninitialized workqueue.To avoid this, create workqueue before vtpmx init.
Found by Linux Driver Verification project (linuxtesting.org).
Signed-off-by Saubhik Mukherjee <[email protected]>--- drivers/char/tpm/tpm_vtpm_proxy.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)drivers/char/tpm/tpm_vtpm_proxy.c +9
-10@@ -697,23 +697,22 @@ static int __init vtpm_module_init(void) {int rc; - rc =vtpmx_init (); -if (rc) { -pr_err ("couldn't create vtpmx device\n" ); -return rc; - } - workqueue =create_workqueue ("tpm-vtpm" );if (!workqueue) {pr_err ("couldn't create workqueue\n" ); - rc = -ENOMEM ; - goto err_vtpmx_cleanup; +return -ENOMEM ; + } + + rc =vtpmx_init (); +if (rc) { +pr_err ("couldn't create vtpmx device\n" ); + goto err_destroy_workqueue; }return 0 ; -err_vtpmx_cleanup: -vtpmx_cleanup (); +err_destroy_workqueue: +destroy_workqueue (workqueue);Quoted 8 lines
Quoted 6 lines
drivers/char/tpm/tpm_vtpm_proxy.c +0
-0return rc; }Signature · 1 line
2.30.2Reviewed-by Jarkko Sakkinen <[email protected]>
Quoted 6 lines
Taking reviewed-by back.
You're lacking fixes tag. Please re-send with one.
/Jarkko
Thank you for noticing. I sent the patch containing the Fixes tag in reply to your last message. (https://lkml.org/lkml/2021/6/30/104)
Jarkko Sakkinen
maintainerQuoted 60 lines · Saubhik Mukherjee
Quoted 59 lines · Jarkko Sakkinen
Quoted 47 lines · Jarkko Sakkinen
Quoted 46 lines · Saubhik Mukherjee
vtpm_module_initcallsvtpmx_initwhich callsmisc_register. The file operations callbacks are registered. So,vtpmx_fops_ioctlcan execute in parallel with rest ofvtpm_module_init.vtpmx_fops_ioctlcallsvtpmx_ioc_new_dev, which callsvtpm_proxy_create_device, which callsvtpm_proxy_work_start, which could read uninitialized workqueue.To avoid this, create workqueue before vtpmx init.
Found by Linux Driver Verification project (linuxtesting.org).
Signed-off-by Saubhik Mukherjee <[email protected]>--- drivers/char/tpm/tpm_vtpm_proxy.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)drivers/char/tpm/tpm_vtpm_proxy.c +9
-10@@ -697,23 +697,22 @@ static int __init vtpm_module_init(void) {int rc; - rc =vtpmx_init (); -if (rc) { -pr_err ("couldn't create vtpmx device\n" ); -return rc; - } - workqueue =create_workqueue ("tpm-vtpm" );if (!workqueue) {pr_err ("couldn't create workqueue\n" ); - rc = -ENOMEM ; - goto err_vtpmx_cleanup; +return -ENOMEM ; + } + + rc =vtpmx_init (); +if (rc) { +pr_err ("couldn't create vtpmx device\n" ); + goto err_destroy_workqueue; }return 0 ; -err_vtpmx_cleanup: -vtpmx_cleanup (); +err_destroy_workqueue: +destroy_workqueue (workqueue);Quoted 8 lines
Quoted 6 lines
drivers/char/tpm/tpm_vtpm_proxy.c +0
-0return rc; }Signature · 1 line
2.30.2Reviewed-by Jarkko Sakkinen <[email protected]>Taking reviewed-by back.
Quoted 7 lines
Quoted 4 lines
You're lacking fixes tag. Please re-send with one.
/Jarkko
Thank you for noticing. I sent the patch containing the Fixes tag in reply to your last message. (https://lkml.org/lkml/2021/6/30/104)
Please do not do that. Instead, version your patches (git format-patch -vX) and send them as separate threads.
It's all documented: https://www.kernel.org/doc/html/v5.13/process/submitting-patches.html
/Jarkko