Skip to content

Commit 033f46b

Browse files
tstrukdavem330
authored andcommitted
crypto: algif - explicitly mark end of data
After the TX sgl is expanded we need to explicitly mark end of data at the last buffer that contains data. Changes in v2 - use type 'bool' and true/false for 'mark'. Signed-off-by: Tadeusz Struk <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 99949a7 commit 033f46b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

crypto/algif_skcipher.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -509,11 +509,11 @@ static int skcipher_recvmsg_async(struct socket *sock, struct msghdr *msg,
509509
struct skcipher_async_req *sreq;
510510
struct ablkcipher_request *req;
511511
struct skcipher_async_rsgl *last_rsgl = NULL;
512-
unsigned int len = 0, tx_nents = skcipher_all_sg_nents(ctx);
512+
unsigned int txbufs = 0, len = 0, tx_nents = skcipher_all_sg_nents(ctx);
513513
unsigned int reqlen = sizeof(struct skcipher_async_req) +
514514
GET_REQ_SIZE(ctx) + GET_IV_SIZE(ctx);
515-
int i = 0;
516515
int err = -ENOMEM;
516+
bool mark = false;
517517

518518
lock_sock(sk);
519519
req = kmalloc(reqlen, GFP_KERNEL);
@@ -555,7 +555,7 @@ static int skcipher_recvmsg_async(struct socket *sock, struct msghdr *msg,
555555
iov_iter_count(&msg->msg_iter));
556556
used = min_t(unsigned long, used, sg->length);
557557

558-
if (i == tx_nents) {
558+
if (txbufs == tx_nents) {
559559
struct scatterlist *tmp;
560560
int x;
561561
/* Ran out of tx slots in async request
@@ -573,10 +573,11 @@ static int skcipher_recvmsg_async(struct socket *sock, struct msghdr *msg,
573573
kfree(sreq->tsg);
574574
sreq->tsg = tmp;
575575
tx_nents *= 2;
576+
mark = true;
576577
}
577578
/* Need to take over the tx sgl from ctx
578579
* to the asynch req - these sgls will be freed later */
579-
sg_set_page(sreq->tsg + i++, sg_page(sg), sg->length,
580+
sg_set_page(sreq->tsg + txbufs++, sg_page(sg), sg->length,
580581
sg->offset);
581582

582583
if (list_empty(&sreq->list)) {
@@ -604,6 +605,9 @@ static int skcipher_recvmsg_async(struct socket *sock, struct msghdr *msg,
604605
iov_iter_advance(&msg->msg_iter, used);
605606
}
606607

608+
if (mark)
609+
sg_mark_end(sreq->tsg + txbufs - 1);
610+
607611
ablkcipher_request_set_crypt(req, sreq->tsg, sreq->first_sgl.sgl.sg,
608612
len, sreq->iv);
609613
err = ctx->enc ? crypto_ablkcipher_encrypt(req) :

0 commit comments

Comments
 (0)