Re: [PATCH] tpm: fix a race between poll and write in tpm-dev-common

From: Tadeusz Struk
Date: Tue Mar 19 2019 - 15:09:38 EST


On 3/18/19 4:19 PM, James Bottomley wrote:
>> @@ -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);
> This doesn't do anything to address the theory that the queued work
> hasn't run before the poll wakes up, does it? If you have an
> alternative theory, could you explain it?

Right, it needs to be guarded by the mutex and also the condition
should only check priv->response_length, because we only care
about if there is data to read. The response_read flag only
prevents double writes, without reading in the middle (or a timeout)
which clean it. I will send a v2 soon.

Thanks,
--
Tadeusz