[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <155294749695.20367.14472779462229450620.stgit@tstruk-mobl1.jf.intel.com>
Date: Mon, 18 Mar 2019 15:18:16 -0700
From: Tadeusz Struk <tadeusz.struk@...el.com>
To: jarkko.sakkinen@...ux.intel.com
Cc: grawity@...il.com, James.Bottomley@...senPartnership.com,
linux-integrity@...r.kernel.org, linux-kernel@...r.kernel.org,
tadeusz.struk@...el.com
Subject: [PATCH] tpm: fix a race between poll and write in tpm-dev-common
Since the poll returns EPOLLIN base on the state of two
variables, the response_read being false and the
response_length > 0 the poll needs to take the buffer_mutex
after it is woken up.
Fixes: 9488585b21bef0df12 ("tpm: add support for partial reads")
Reported-by: Mantas Mikulėnas <grawity@...il.com>
Signed-off-by: Tadeusz Struk <tadeusz.struk@...el.com>
---
drivers/char/tpm/tpm-dev-common.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/char/tpm/tpm-dev-common.c b/drivers/char/tpm/tpm-dev-common.c
index 5eecad233ea1..61e458d6f652 100644
--- a/drivers/char/tpm/tpm-dev-common.c
+++ b/drivers/char/tpm/tpm-dev-common.c
@@ -203,12 +203,14 @@ __poll_t tpm_common_poll(struct file *file, poll_table *wait)
__poll_t mask = 0;
poll_wait(file, &priv->async_wait, wait);
+ mutex_lock(&priv->buffer_mutex);
if (!priv->response_read || priv->response_length)
mask = EPOLLIN | EPOLLRDNORM;
else
mask = EPOLLOUT | EPOLLWRNORM;
+ mutex_unlock(&priv->buffer_mutex);
return mask;
}
Powered by blists - more mailing lists