Skip to content

Commit

Permalink
crypto: af_alg - fix race accessing cipher request
Browse files Browse the repository at this point in the history
When invoking an asynchronous cipher operation, the invocation of the
callback may be performed before the subsequent operations in the
initial code path are invoked. The callback deletes the cipher request
data structure which implies that after the invocation of the
asynchronous cipher operation, this data structure must not be accessed
any more.

The setting of the return code size with the request data structure must
therefore be moved before the invocation of the asynchronous cipher
operation.

Fixes: e870456 ("crypto: algif_skcipher - overhaul memory management")
Fixes: d887c52 ("crypto: algif_aead - overhaul memory management")
Reported-by: syzbot <[email protected]>
Cc: <[email protected]> # v4.14+
Signed-off-by: Stephan Mueller <[email protected]>
Acked-by: Jonathan Cameron <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
smuellerDD authored and herbertx committed Dec 11, 2017
1 parent 9abffc6 commit d53c513
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions crypto/algif_aead.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,19 +291,19 @@ static int _aead_recvmsg(struct socket *sock, struct msghdr *msg,
/* AIO operation */
sock_hold(sk);
areq->iocb = msg->msg_iocb;

/* Remember output size that will be generated. */
areq->outlen = outlen;

aead_request_set_callback(&areq->cra_u.aead_req,
CRYPTO_TFM_REQ_MAY_BACKLOG,
af_alg_async_cb, areq);
err = ctx->enc ? crypto_aead_encrypt(&areq->cra_u.aead_req) :
crypto_aead_decrypt(&areq->cra_u.aead_req);

/* AIO operation in progress */
if (err == -EINPROGRESS || err == -EBUSY) {
/* Remember output size that will be generated. */
areq->outlen = outlen;

if (err == -EINPROGRESS || err == -EBUSY)
return -EIOCBQUEUED;
}

sock_put(sk);
} else {
Expand Down
10 changes: 5 additions & 5 deletions crypto/algif_skcipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ static int _skcipher_recvmsg(struct socket *sock, struct msghdr *msg,
/* AIO operation */
sock_hold(sk);
areq->iocb = msg->msg_iocb;

/* Remember output size that will be generated. */
areq->outlen = len;

skcipher_request_set_callback(&areq->cra_u.skcipher_req,
CRYPTO_TFM_REQ_MAY_SLEEP,
af_alg_async_cb, areq);
Expand All @@ -133,12 +137,8 @@ static int _skcipher_recvmsg(struct socket *sock, struct msghdr *msg,
crypto_skcipher_decrypt(&areq->cra_u.skcipher_req);

/* AIO operation in progress */
if (err == -EINPROGRESS || err == -EBUSY) {
/* Remember output size that will be generated. */
areq->outlen = len;

if (err == -EINPROGRESS || err == -EBUSY)
return -EIOCBQUEUED;
}

sock_put(sk);
} else {
Expand Down

0 comments on commit d53c513

Please sign in to comment.