Skip to content

Commit 7110629

Browse files
tstrukJames Morris
authored and
James Morris
committed
tpm: fix an invalid condition in tpm_common_poll
The poll condition should only check response_length, because reads should only be issued if there is data to read. The response_read flag only prevents double writes. The problem was that the write set the response_read to false, enqued a tpm job, and returned. Then application called poll which checked the response_read flag and returned EPOLLIN. Then the application called read, but got nothing. After all that the async_work kicked in. Added also mutex_lock around the poll check to prevent other possible race conditions. Fixes: 9488585 ("tpm: add support for partial reads") Reported-by: Mantas Mikulėnas <[email protected]> Tested-by: Mantas Mikulėnas <[email protected]> Signed-off-by: Tadeusz Struk <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]> Signed-off-by: James Morris <[email protected]>
1 parent e891db1 commit 7110629

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

drivers/char/tpm/tpm-dev-common.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,19 @@ __poll_t tpm_common_poll(struct file *file, poll_table *wait)
233233
__poll_t mask = 0;
234234

235235
poll_wait(file, &priv->async_wait, wait);
236+
mutex_lock(&priv->buffer_mutex);
236237

237-
if (!priv->response_read || priv->response_length)
238+
/*
239+
* The response_length indicates if there is still response
240+
* (or part of it) to be consumed. Partial reads decrease it
241+
* by the number of bytes read, and write resets it the zero.
242+
*/
243+
if (priv->response_length)
238244
mask = EPOLLIN | EPOLLRDNORM;
239245
else
240246
mask = EPOLLOUT | EPOLLWRNORM;
241247

248+
mutex_unlock(&priv->buffer_mutex);
242249
return mask;
243250
}
244251

0 commit comments

Comments
 (0)