Skip to content

Commit

Permalink
crypto: api - Add scaffolding to change completion function signature
Browse files Browse the repository at this point in the history
[ Upstream commit c35e03e ]

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: 4140aaf ("crypto: engine - fix crypto_queue backlog handling")
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
herbertx authored and gregkh committed May 17, 2023
1 parent 1055edd commit 6ba620f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/crypto/algapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
6 changes: 6 additions & 0 deletions include/linux/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/**
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6ba620f

Please sign in to comment.