]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
crypto: api - Add scaffolding to change completion function signature
authorHerbert Xu <herbert@gondor.apana.org.au>
Tue, 31 Jan 2023 08:01:45 +0000 (16:01 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 May 2023 09:53:40 +0000 (11:53 +0200)
[ Upstream commit c35e03eaece71101ff6cbf776b86403860ac8cc3 ]

The crypto completion function currently takes a pointer to a
struct crypto_async_request object.  However, in reality the API
does not allow the use of any part of the object apart from the
data field.  For example, ahash/shash will create a fake object
on the stack to pass along a different data field.

This leads to potential bugs where the user may try to dereference
or otherwise use the crypto_async_request object.

This patch adds some temporary scaffolding so that the completion
function can take a void * instead.  Once affected users have been
converted this can be removed.

The helper crypto_request_complete will remain even after the
conversion is complete.  It should be used instead of calling
the completion function directly.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Stable-dep-of: 4140aafcff16 ("crypto: engine - fix crypto_queue backlog handling")
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/crypto/algapi.h
include/linux/crypto.h

index f50c5d1725da5ad417989a1c7b9a8d38c35c8adc..224b8606470835a0180f6a37201998b23779a3b4 100644 (file)
@@ -265,4 +265,11 @@ enum {
        CRYPTO_MSG_ALG_LOADED,
 };
 
+static inline void crypto_request_complete(struct crypto_async_request *req,
+                                          int err)
+{
+       crypto_completion_t complete = req->complete;
+       complete(req, err);
+}
+
 #endif /* _CRYPTO_ALGAPI_H */
index 2324ab6f1846b0b309607c2ae8191afd16268397..e3c4be29aaccb672a58b8905669f919444820d90 100644 (file)
@@ -176,6 +176,7 @@ struct crypto_async_request;
 struct crypto_tfm;
 struct crypto_type;
 
+typedef struct crypto_async_request crypto_completion_data_t;
 typedef void (*crypto_completion_t)(struct crypto_async_request *req, int err);
 
 /**
@@ -595,6 +596,11 @@ struct crypto_wait {
 /*
  * Async ops completion helper functioons
  */
+static inline void *crypto_get_completion_data(crypto_completion_data_t *req)
+{
+       return req->data;
+}
+
 void crypto_req_done(struct crypto_async_request *req, int err);
 
 static inline int crypto_wait_req(int err, struct crypto_wait *wait)