Skip to content

Commit d23d124

Browse files
tstrukJarkko Sakkinen
authored andcommitted
tpm: fix invalid locking in NONBLOCKING mode
When an application sends TPM commands in NONBLOCKING mode the driver holds chip->tpm_mutex returning from write(), which triggers: "WARNING: lock held when returning to user space". To fix this issue the driver needs to release the mutex before returning and acquire it again in tpm_dev_async_work() before sending the command. Cc: [email protected] Fixes: 9e1b74a (tpm: add support for nonblocking operation) Reported-by: Jeffrin Jose T <[email protected]> Tested-by: Jeffrin Jose T <[email protected]> Signed-off-by: Tadeusz Struk <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]>
1 parent 45477b3 commit d23d124

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,20 @@ static void tpm_dev_async_work(struct work_struct *work)
6161

6262
mutex_lock(&priv->buffer_mutex);
6363
priv->command_enqueued = false;
64+
ret = tpm_try_get_ops(priv->chip);
65+
if (ret) {
66+
priv->response_length = ret;
67+
goto out;
68+
}
69+
6470
ret = tpm_dev_transmit(priv->chip, priv->space, priv->data_buffer,
6571
sizeof(priv->data_buffer));
6672
tpm_put_ops(priv->chip);
6773
if (ret > 0) {
6874
priv->response_length = ret;
6975
mod_timer(&priv->user_read_timer, jiffies + (120 * HZ));
7076
}
77+
out:
7178
mutex_unlock(&priv->buffer_mutex);
7279
wake_up_interruptible(&priv->async_wait);
7380
}
@@ -204,6 +211,7 @@ ssize_t tpm_common_write(struct file *file, const char __user *buf,
204211
if (file->f_flags & O_NONBLOCK) {
205212
priv->command_enqueued = true;
206213
queue_work(tpm_dev_wq, &priv->async_work);
214+
tpm_put_ops(priv->chip);
207215
mutex_unlock(&priv->buffer_mutex);
208216
return size;
209217
}

0 commit comments

Comments
 (0)