Skip to content

Commit f4032d6

Browse files
Jarkko Sakkinenjarkkojs
authored andcommitted
tpm: tpm_vtpm_proxy: fix a race condition in /dev/vtpmx creation
/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: [email protected] Fixes: 6f99612 ("tpm: Proxy driver for supporting multiple emulated TPMs") Reviewed-by: Stefan Berger <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]>
1 parent fdf0eaf commit f4032d6

File tree

1 file changed

+7
-23
lines changed

1 file changed

+7
-23
lines changed

drivers/char/tpm/tpm_vtpm_proxy.c

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -683,45 +683,29 @@ static struct miscdevice vtpmx_miscdev = {
683683
.fops = &vtpmx_fops,
684684
};
685685

686-
static int vtpmx_init(void)
687-
{
688-
return misc_register(&vtpmx_miscdev);
689-
}
690-
691-
static void vtpmx_cleanup(void)
692-
{
693-
misc_deregister(&vtpmx_miscdev);
694-
}
695-
696686
static int __init vtpm_module_init(void)
697687
{
698688
int rc;
699689

700-
rc = vtpmx_init();
701-
if (rc) {
702-
pr_err("couldn't create vtpmx device\n");
703-
return rc;
704-
}
705-
706690
workqueue = create_workqueue("tpm-vtpm");
707691
if (!workqueue) {
708692
pr_err("couldn't create workqueue\n");
709-
rc = -ENOMEM;
710-
goto err_vtpmx_cleanup;
693+
return -ENOMEM;
711694
}
712695

713-
return 0;
714-
715-
err_vtpmx_cleanup:
716-
vtpmx_cleanup();
696+
rc = misc_register(&vtpmx_miscdev);
697+
if (rc) {
698+
pr_err("couldn't create vtpmx device\n");
699+
destroy_workqueue(workqueue);
700+
}
717701

718702
return rc;
719703
}
720704

721705
static void __exit vtpm_module_exit(void)
722706
{
723707
destroy_workqueue(workqueue);
724-
vtpmx_cleanup();
708+
misc_deregister(&vtpmx_miscdev);
725709
}
726710

727711
module_init(vtpm_module_init);

0 commit comments

Comments
 (0)