Skip to content

Commit dd7da13

Browse files
author
Kent Yoder
committed
tpm: fix double write race and tpm_release free issue
Moved the atomic_set of the data_pending variable until after the tpm_read has completed processing. The existing code had a window of time where a second write to the driver could clobber the tpm command buffer. Also fixed an issue where if close was called on the tpm device before a read completed, the tpm command buffer would be returned to the OS, which could contain sensitive information. Signed-off-by: Kent Yoder <[email protected]>
1 parent 578b016 commit dd7da13

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/char/tpm/tpm.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ int tpm_release(struct inode *inode, struct file *file)
11711171
flush_work_sync(&chip->work);
11721172
file->private_data = NULL;
11731173
atomic_set(&chip->data_pending, 0);
1174-
kfree(chip->data_buffer);
1174+
kzfree(chip->data_buffer);
11751175
clear_bit(0, &chip->is_open);
11761176
put_device(chip->dev);
11771177
return 0;
@@ -1223,7 +1223,6 @@ ssize_t tpm_read(struct file *file, char __user *buf,
12231223
del_singleshot_timer_sync(&chip->user_read_timer);
12241224
flush_work_sync(&chip->work);
12251225
ret_size = atomic_read(&chip->data_pending);
1226-
atomic_set(&chip->data_pending, 0);
12271226
if (ret_size > 0) { /* relay data */
12281227
ssize_t orig_ret_size = ret_size;
12291228
if (size < ret_size)
@@ -1238,6 +1237,8 @@ ssize_t tpm_read(struct file *file, char __user *buf,
12381237
mutex_unlock(&chip->buffer_mutex);
12391238
}
12401239

1240+
atomic_set(&chip->data_pending, 0);
1241+
12411242
return ret_size;
12421243
}
12431244
EXPORT_SYMBOL_GPL(tpm_read);

0 commit comments

Comments
 (0)