tpm: tpm_vtpm_proxy: fix a race condition in /dev/vtpmx creation
commit f4032d615f90970d6c3ac1d9c0bce3351eb4445c upstream.
/dev/vtpmx is made visible before 'workqueue' is initialized, which can
lead to a memory corruption in the worst case scenario.
Address this by initializing 'workqueue' as the very first step of the
driver initialization.
Cc: stable@vger.kernel.org
Fixes: 6f99612e25
("tpm: Proxy driver for supporting multiple emulated TPMs")
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@tuni.fi>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
59490249c2
commit
9ff7fcb3a2
@@ -683,37 +683,21 @@ static struct miscdevice vtpmx_miscdev = {
|
|||||||
.fops = &vtpmx_fops,
|
.fops = &vtpmx_fops,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int vtpmx_init(void)
|
|
||||||
{
|
|
||||||
return misc_register(&vtpmx_miscdev);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void vtpmx_cleanup(void)
|
|
||||||
{
|
|
||||||
misc_deregister(&vtpmx_miscdev);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int __init vtpm_module_init(void)
|
static int __init vtpm_module_init(void)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
rc = vtpmx_init();
|
|
||||||
if (rc) {
|
|
||||||
pr_err("couldn't create vtpmx device\n");
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
workqueue = create_workqueue("tpm-vtpm");
|
workqueue = create_workqueue("tpm-vtpm");
|
||||||
if (!workqueue) {
|
if (!workqueue) {
|
||||||
pr_err("couldn't create workqueue\n");
|
pr_err("couldn't create workqueue\n");
|
||||||
rc = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto err_vtpmx_cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
rc = misc_register(&vtpmx_miscdev);
|
||||||
|
if (rc) {
|
||||||
err_vtpmx_cleanup:
|
pr_err("couldn't create vtpmx device\n");
|
||||||
vtpmx_cleanup();
|
destroy_workqueue(workqueue);
|
||||||
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@@ -721,7 +705,7 @@ err_vtpmx_cleanup:
|
|||||||
static void __exit vtpm_module_exit(void)
|
static void __exit vtpm_module_exit(void)
|
||||||
{
|
{
|
||||||
destroy_workqueue(workqueue);
|
destroy_workqueue(workqueue);
|
||||||
vtpmx_cleanup();
|
misc_deregister(&vtpmx_miscdev);
|
||||||
}
|
}
|
||||||
|
|
||||||
module_init(vtpm_module_init);
|
module_init(vtpm_module_init);
|
||||||
|
Reference in New Issue
Block a user