diff mbox series

[09/10] crypto: add timeout to crypto_wait_req

Message ID 20191017122549.4634-10-t-kristo@ti.com
State New
Headers show
Series crypto: omap fixes towards 5.5 | expand

Commit Message

Tero Kristo Oct. 17, 2019, 12:25 p.m. UTC
Currently crypto_wait_req waits indefinitely for an async crypto request
to complete. This is bad as it can cause for example the crypto test
manager to hang without any notification as to why it has happened.
Instead of waiting indefinitely, add a 1 second timeout to the call,
and provide a warning print if a timeout happens.

Signed-off-by: Tero Kristo <t-kristo@ti.com>

---
 include/linux/crypto.h | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

-- 
2.17.1

--
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

Comments

Eric Biggers Nov. 5, 2019, 5:42 p.m. UTC | #1
On Thu, Oct 17, 2019 at 03:25:48PM +0300, Tero Kristo wrote:
> Currently crypto_wait_req waits indefinitely for an async crypto request

> to complete. This is bad as it can cause for example the crypto test

> manager to hang without any notification as to why it has happened.

> Instead of waiting indefinitely, add a 1 second timeout to the call,

> and provide a warning print if a timeout happens.

> 

> Signed-off-by: Tero Kristo <t-kristo@ti.com>

> ---

>  include/linux/crypto.h | 9 ++++++++-

>  1 file changed, 8 insertions(+), 1 deletion(-)

> 

> diff --git a/include/linux/crypto.h b/include/linux/crypto.h

> index 19ea3a371d7b..b8f0e5c3cc0c 100644

> --- a/include/linux/crypto.h

> +++ b/include/linux/crypto.h

> @@ -682,8 +682,15 @@ static inline int crypto_wait_req(int err, struct crypto_wait *wait)

>  	switch (err) {

>  	case -EINPROGRESS:

>  	case -EBUSY:

> -		wait_for_completion(&wait->completion);

> +		err = wait_for_completion_timeout(&wait->completion,

> +						  msecs_to_jiffies(1000));

>  		reinit_completion(&wait->completion);

> +		if (!err) {

> +			pr_err("%s: timeout for %p\n", __func__, wait);

> +			err = -ETIMEDOUT;

> +			break;

> +		}

> +

>  		err = wait->err;

>  		break;

>  	};


I'm not sure this is a good idea, because operations could legitimately take a
long time, e.g. if someone passes in a huge data buffer.  How do you know that X
amount of time is always going to be enough?

- Eric
diff mbox series

Patch

diff --git a/include/linux/crypto.h b/include/linux/crypto.h
index 19ea3a371d7b..b8f0e5c3cc0c 100644
--- a/include/linux/crypto.h
+++ b/include/linux/crypto.h
@@ -682,8 +682,15 @@  static inline int crypto_wait_req(int err, struct crypto_wait *wait)
 	switch (err) {
 	case -EINPROGRESS:
 	case -EBUSY:
-		wait_for_completion(&wait->completion);
+		err = wait_for_completion_timeout(&wait->completion,
+						  msecs_to_jiffies(1000));
 		reinit_completion(&wait->completion);
+		if (!err) {
+			pr_err("%s: timeout for %p\n", __func__, wait);
+			err = -ETIMEDOUT;
+			break;
+		}
+
 		err = wait->err;
 		break;
 	};