tpm: Begin the process to deprecate user_read_timer
PATCH 1/1 tpm: Begin the process to deprecate user_read_timer
For a long time the cdev read/write interface had this strange idea that userspace had to read the result within 60 seconds otherwise it is discarded. Perhaps this made sense under some older locking regime, but in the modern kernel it is not required and is just dangerous.
Since something may be relying on this, double the timeout and print a warning. We can remove the code in a few years, but this should be enough to prevent new users.
--- drivers/char/tpm/tpm-dev.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm-dev.c +4 -1
@@ -38,6 +38,9 @@ static void user_reader_timeout(unsigned long ptr) {struct file_priv *priv = (struct file_priv *)ptr; +pr_warn ("TPM user space timeout is deprecated (pid=%d)\n" , +task_tgid_nr (current)); +schedule_work (&priv->work); }
@@ -159,7 +162,7 @@ static ssize_t tpm_write(struct file *file, const char __user *buf,mutex_unlock (&priv->buffer_mutex);/* Set a timeout by which the reader must come claim the result */ -mod_timer (&priv->user_read_timer, jiffies + (60 *HZ )); +mod_timer (&priv->user_read_timer, jiffies + (120 *HZ ));return in_size; }
Signature · 1 line
2.7.4
Quoted 11 lines · Jason Gunthorpe
For a long time the cdev read/write interface had this strange idea that userspace had to read the result within 60 seconds otherwise it is discarded. Perhaps this made sense under some older locking regime, but in the modern kernel it is not required and is just dangerous.
Since something may be relying on this, double the timeout and print a warning. We can remove the code in a few years, but this should be enough to prevent new users.
Suggested-by James Bottomley <[email protected]>Signed-off-by Jason Gunthorpe <[email protected]>
Thanks. I'll include this to my next PR for 4.11 as it does not add any new features.
/Jarkko
Quoted 29 lines
--- drivers/char/tpm/tpm-dev.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/char/tpm/tpm-dev.c +4
-1@@ -38,6 +38,9 @@ static void user_reader_timeout(unsigned long ptr) {struct file_priv *priv = (struct file_priv *)ptr; +pr_warn ("TPM user space timeout is deprecated (pid=%d)\n" , +task_tgid_nr (current)); +schedule_work (&priv->work); }@@ -159,7 +162,7 @@ static ssize_t tpm_write(struct file *file, const char __user *buf,mutex_unlock (&priv->buffer_mutex);/* Set a timeout by which the reader must come claim the result */ -mod_timer (&priv->user_read_timer, jiffies + (60 *HZ )); +mod_timer (&priv->user_read_timer, jiffies + (120 *HZ ));return in_size; }Signature · 1 line
2.7.4