Skip to content

Commit

Permalink
tpm: Handle negative priv->response_len in tpm_common_read()
Browse files Browse the repository at this point in the history
commit a430e67 upstream.

The priv->response_length can hold the size of an response or an negative
error code, and the tpm_common_read() needs to handle both cases correctly.
Changed the type of response_length to signed and accounted for negative
value in tpm_common_read().

Cc: [email protected]
Fixes: d23d124 ("tpm: fix invalid locking in NONBLOCKING mode")
Reported-by: Laura Abbott <[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: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
tstruk authored and florpor committed Apr 30, 2020
1 parent 2f84e15 commit 0082102
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion drivers/char/tpm/tpm-dev-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ ssize_t tpm_common_read(struct file *file, char __user *buf,
priv->response_read = true;

ret_size = min_t(ssize_t, size, priv->response_length);
if (!ret_size) {
if (ret_size <= 0) {
priv->response_length = 0;
goto out;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/char/tpm/tpm-dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct file_priv {
struct work_struct timeout_work;
struct work_struct async_work;
wait_queue_head_t async_wait;
size_t response_length;
ssize_t response_length;
bool response_read;
bool command_enqueued;

Expand Down

0 comments on commit 0082102

Please sign in to comment.