* [PATCH] tpm_vtpm_proxy: fix race condition in /dev/vtpmx creation
@ 2023-05-13 17:28 Jarkko Sakkinen
2023-05-13 17:57 ` Jarkko Sakkinen
2023-05-13 20:49 ` Stefan Berger
0 siblings, 2 replies; 3+ messages in thread
From: Jarkko Sakkinen @ 2023-05-13 17:28 UTC (permalink / raw)
To: linux-integrity, Peter Huewe, Jarkko Sakkinen, Jason Gunthorpe,
Stefan Berger
Cc: Jarkko Sakkinen, stable, linux-kernel
/dev/vtpmx is made visible before the workqueue exist, which can lead
memory corruption in the worst case, if workqueue is used before it has
been fully initialized. Address this by changing the call order.
Cc: Stefan Berger <stefanb@linux.vnet.ibm.com>
Cc: stable@vger.kernel.org
Fixes: 6f99612e2500 ("tpm: Proxy driver for supporting multiple emulated TPMs")
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@tuni.fi>
---
drivers/char/tpm/tpm_vtpm_proxy.c | 26 ++++++++++----------------
1 file changed, 10 insertions(+), 16 deletions(-)
diff --git a/drivers/char/tpm/tpm_vtpm_proxy.c b/drivers/char/tpm/tpm_vtpm_proxy.c
index 5c865987ba5c..ef1367cf2f10 100644
--- a/drivers/char/tpm/tpm_vtpm_proxy.c
+++ b/drivers/char/tpm/tpm_vtpm_proxy.c
@@ -50,7 +50,7 @@ struct proxy_dev {
/* all supported flags */
#define VTPM_PROXY_FLAGS_ALL (VTPM_PROXY_FLAG_TPM2)
-static struct workqueue_struct *workqueue;
+static struct workqueue_struct *vtpm_workqueue;
static void vtpm_proxy_delete_device(struct proxy_dev *proxy_dev);
@@ -478,7 +478,7 @@ static void vtpm_proxy_work_stop(struct proxy_dev *proxy_dev)
*/
static inline void vtpm_proxy_work_start(struct proxy_dev *proxy_dev)
{
- queue_work(workqueue, &proxy_dev->work);
+ queue_work(vtpm_workqueue, &proxy_dev->work);
}
/*
@@ -697,30 +697,24 @@ static int __init vtpm_module_init(void)
{
int rc;
- rc = vtpmx_init();
- if (rc) {
- pr_err("couldn't create vtpmx device\n");
+ vtpm_workqueue = create_workqueue("tpm-vtpm");
+ if (!vtpm_workqueue) {
+ rc = -ENOMEM;
return rc;
}
- workqueue = create_workqueue("tpm-vtpm");
- if (!workqueue) {
- pr_err("couldn't create workqueue\n");
- rc = -ENOMEM;
- goto err_vtpmx_cleanup;
+ rc = vtpmx_init();
+ if (rc) {
+ vtpmx_cleanup();
+ return rc;
}
return 0;
-
-err_vtpmx_cleanup:
- vtpmx_cleanup();
-
- return rc;
}
static void __exit vtpm_module_exit(void)
{
- destroy_workqueue(workqueue);
+ destroy_workqueue(vtpm_workqueue);
vtpmx_cleanup();
}
--
2.39.2
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] tpm_vtpm_proxy: fix race condition in /dev/vtpmx creation
2023-05-13 17:28 [PATCH] tpm_vtpm_proxy: fix race condition in /dev/vtpmx creation Jarkko Sakkinen
@ 2023-05-13 17:57 ` Jarkko Sakkinen
2023-05-13 20:49 ` Stefan Berger
1 sibling, 0 replies; 3+ messages in thread
From: Jarkko Sakkinen @ 2023-05-13 17:57 UTC (permalink / raw)
To: Jarkko Sakkinen, linux-integrity, Peter Huewe, Jason Gunthorpe,
Stefan Berger
Cc: stable, linux-kernel
On Sat May 13, 2023 at 8:28 PM EEST, Jarkko Sakkinen wrote:
> /dev/vtpmx is made visible before the workqueue exist, which can lead
> memory corruption in the worst case, if workqueue is used before it has
> been fully initialized. Address this by changing the call order.
>
> Cc: Stefan Berger <stefanb@linux.vnet.ibm.com>
> Cc: stable@vger.kernel.org
> Fixes: 6f99612e2500 ("tpm: Proxy driver for supporting multiple emulated TPMs")
> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@tuni.fi>
> ---
> drivers/char/tpm/tpm_vtpm_proxy.c | 26 ++++++++++----------------
> 1 file changed, 10 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm_vtpm_proxy.c b/drivers/char/tpm/tpm_vtpm_proxy.c
> index 5c865987ba5c..ef1367cf2f10 100644
> --- a/drivers/char/tpm/tpm_vtpm_proxy.c
> +++ b/drivers/char/tpm/tpm_vtpm_proxy.c
> @@ -50,7 +50,7 @@ struct proxy_dev {
> /* all supported flags */
> #define VTPM_PROXY_FLAGS_ALL (VTPM_PROXY_FLAG_TPM2)
>
> -static struct workqueue_struct *workqueue;
> +static struct workqueue_struct *vtpm_workqueue;
>
> static void vtpm_proxy_delete_device(struct proxy_dev *proxy_dev);
>
> @@ -478,7 +478,7 @@ static void vtpm_proxy_work_stop(struct proxy_dev *proxy_dev)
> */
> static inline void vtpm_proxy_work_start(struct proxy_dev *proxy_dev)
> {
> - queue_work(workqueue, &proxy_dev->work);
> + queue_work(vtpm_workqueue, &proxy_dev->work);
> }
>
> /*
> @@ -697,30 +697,24 @@ static int __init vtpm_module_init(void)
> {
> int rc;
>
> - rc = vtpmx_init();
> - if (rc) {
> - pr_err("couldn't create vtpmx device\n");
> + vtpm_workqueue = create_workqueue("tpm-vtpm");
> + if (!vtpm_workqueue) {
> + rc = -ENOMEM;
> return rc;
> }
>
> - workqueue = create_workqueue("tpm-vtpm");
> - if (!workqueue) {
> - pr_err("couldn't create workqueue\n");
> - rc = -ENOMEM;
> - goto err_vtpmx_cleanup;
> + rc = vtpmx_init();
> + if (rc) {
> + vtpmx_cleanup();
This should be destroy_workqueue(). I'll send a new version.
BR, Jarkko
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] tpm_vtpm_proxy: fix race condition in /dev/vtpmx creation
2023-05-13 17:28 [PATCH] tpm_vtpm_proxy: fix race condition in /dev/vtpmx creation Jarkko Sakkinen
2023-05-13 17:57 ` Jarkko Sakkinen
@ 2023-05-13 20:49 ` Stefan Berger
1 sibling, 0 replies; 3+ messages in thread
From: Stefan Berger @ 2023-05-13 20:49 UTC (permalink / raw)
To: Jarkko Sakkinen, linux-integrity, Peter Huewe, Jarkko Sakkinen,
Jason Gunthorpe, Stefan Berger
Cc: stable, linux-kernel
On 5/13/23 13:28, Jarkko Sakkinen wrote:
> /dev/vtpmx is made visible before the workqueue exist, which can lead
which can lead to
> memory corruption in the worst case, if workqueue is used before it has
> been fully initialized. Address this by changing the call order.
>
Thanks,
Stefan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-05-13 20:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-13 17:28 [PATCH] tpm_vtpm_proxy: fix race condition in /dev/vtpmx creation Jarkko Sakkinen
2023-05-13 17:57 ` Jarkko Sakkinen
2023-05-13 20:49 ` Stefan Berger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox