Skip to contentSkip to conversation

crypto: algif - explicitly mark end of data

PATCH Superseded Tadeusz Struk 2 participants 2 messages Mar 30, 2015 – Apr 1, 2015

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 crypto/algif_skcipher.c |   13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
crypto/algif_skcipher.c +8 -5
index 8276f21..9492dd5 100644
@@ -509,11 +509,10 @@ static int skcipher_recvmsg_async(struct socket *sock, struct msghdr *msg,
 	struct skcipher_async_req *sreq;
 	struct ablkcipher_request *req;
 	struct skcipher_async_rsgl *last_rsgl = NULL;
-	unsigned int len = 0, tx_nents = skcipher_all_sg_nents(ctx);
+	unsigned int txbufs = 0, len = 0, tx_nents = skcipher_all_sg_nents(ctx);
 	unsigned int reqlen = sizeof(struct skcipher_async_req) +
 				GET_REQ_SIZE(ctx) + GET_IV_SIZE(ctx);
-	int i = 0;
-	int err = -ENOMEM;
+	int mark = 0, err = -ENOMEM;
 
 	lock_sock(sk);
 	req = kmalloc(reqlen, GFP_KERNEL);
@@ -555,7 +554,7 @@ static int skcipher_recvmsg_async(struct socket *sock, struct msghdr *msg,
 			     iov_iter_count(&msg->msg_iter));
 		used = min_t(unsigned long, used, sg->length);
 
-		if (i == tx_nents) {
+		if (txbufs == tx_nents) {
 			struct scatterlist *tmp;
 			int x;
 			/* Ran out of tx slots in async request
@@ -573,10 +572,11 @@ static int skcipher_recvmsg_async(struct socket *sock, struct msghdr *msg,
 			kfree(sreq->tsg);
 			sreq->tsg = tmp;
 			tx_nents *= 2;
+			mark = 1;
 		}
 		/* Need to take over the tx sgl from ctx
 		 * to the asynch req - these sgls will be freed later */
-		sg_set_page(sreq->tsg + i++, sg_page(sg), sg->length,
+		sg_set_page(sreq->tsg + txbufs++, sg_page(sg), sg->length,
 			    sg->offset);
 
 		if (list_empty(&sreq->list)) {
@@ -604,6 +604,9 @@ static int skcipher_recvmsg_async(struct socket *sock, struct msghdr *msg,
 		iov_iter_advance(&msg->msg_iter, used);
 	}
 
+	if (mark)
+		sg_mark_end(sreq->tsg + txbufs - 1);
+
 	ablkcipher_request_set_crypt(req, sreq->tsg, sreq->first_sgl.sgl.sg,
 				     len, sreq->iv);
 	err = ctx->enc ? crypto_ablkcipher_encrypt(req) :
maintainer
#1 lore raw

From: Tadeusz Struk <[email protected]>
Date: Mon, 30 Mar 2015 14:25:43 -0700

Quoted 4 lines
crypto/algif_skcipher.c +1 -0
+	int mark = 0, err = -ENOMEM;
 
 	lock_sock(sk);
 	req = kmalloc(reqlen, GFP_KERNEL);

...

Quoted 5 lines
crypto/algif_skcipher.c +1 -0
@@ -573,10 +572,11 @@ static int skcipher_recvmsg_async(struct socket *sock, struct msghdr *msg,
 			kfree(sreq->tsg);
 			sreq->tsg = tmp;
 			tx_nents *= 2;
+			mark = 1;

...

crypto/algif_skcipher.c static int skcipher_recvmsg_async(struct socket *sock, struct msghdr *msg, · line 608

Quoted 6 lines
crypto/algif_skcipher.c +2 -0
@@ -604,6 +604,9 @@ static int skcipher_recvmsg_async(struct socket *sock, struct msghdr *msg,
 		iov_iter_advance(&msg->msg_iter, used);
 	}
 
+	if (mark)
+		sg_mark_end(sreq->tsg + txbufs - 1);

Please use type 'bool' and true/false for 'mark'.