diff options
Diffstat (limited to 'crypto/algif_skcipher.c')
| -rw-r--r-- | crypto/algif_skcipher.c | 29 | 
1 files changed, 13 insertions, 16 deletions
diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c index 83187f497c7c..c12207c8dde9 100644 --- a/crypto/algif_skcipher.c +++ b/crypto/algif_skcipher.c @@ -251,6 +251,7 @@ static int skcipher_sendmsg(struct kiocb *unused, struct socket *sock,  	struct af_alg_control con = {};  	long copied = 0;  	bool enc = 0; +	bool init = 0;  	int err;  	int i; @@ -259,6 +260,7 @@ static int skcipher_sendmsg(struct kiocb *unused, struct socket *sock,  		if (err)  			return err; +		init = 1;  		switch (con.op) {  		case ALG_OP_ENCRYPT:  			enc = 1; @@ -280,7 +282,7 @@ static int skcipher_sendmsg(struct kiocb *unused, struct socket *sock,  	if (!ctx->more && ctx->used)  		goto unlock; -	if (!ctx->used) { +	if (init) {  		ctx->enc = enc;  		if (con.iv)  			memcpy(ctx->iv, con.iv->iv, ivsize); @@ -298,9 +300,9 @@ static int skcipher_sendmsg(struct kiocb *unused, struct socket *sock,  			len = min_t(unsigned long, len,  				    PAGE_SIZE - sg->offset - sg->length); -			err = memcpy_fromiovec(page_address(sg_page(sg)) + -					       sg->offset + sg->length, -					       msg->msg_iov, len); +			err = memcpy_from_msg(page_address(sg_page(sg)) + +					      sg->offset + sg->length, +					      msg, len);  			if (err)  				goto unlock; @@ -337,8 +339,8 @@ static int skcipher_sendmsg(struct kiocb *unused, struct socket *sock,  			if (!sg_page(sg + i))  				goto unlock; -			err = memcpy_fromiovec(page_address(sg_page(sg + i)), -					       msg->msg_iov, plen); +			err = memcpy_from_msg(page_address(sg_page(sg + i)), +					      msg, plen);  			if (err) {  				__free_page(sg_page(sg + i));  				sg_assign_page(sg + i, NULL); @@ -359,8 +361,6 @@ static int skcipher_sendmsg(struct kiocb *unused, struct socket *sock,  	err = 0;  	ctx->more = msg->msg_flags & MSG_MORE; -	if (!ctx->more && !list_empty(&ctx->tsgl)) -		sgl = list_entry(ctx->tsgl.prev, struct skcipher_sg_list, list);  unlock:  	skcipher_data_wakeup(sk); @@ -408,8 +408,6 @@ static ssize_t skcipher_sendpage(struct socket *sock, struct page *page,  done:  	ctx->more = flags & MSG_MORE; -	if (!ctx->more && !list_empty(&ctx->tsgl)) -		sgl = list_entry(ctx->tsgl.prev, struct skcipher_sg_list, list);  unlock:  	skcipher_data_wakeup(sk); @@ -429,13 +427,13 @@ static int skcipher_recvmsg(struct kiocb *unused, struct socket *sock,  	struct skcipher_sg_list *sgl;  	struct scatterlist *sg;  	unsigned long iovlen; -	struct iovec *iov; +	const struct iovec *iov;  	int err = -EAGAIN;  	int used;  	long copied = 0;  	lock_sock(sk); -	for (iov = msg->msg_iov, iovlen = msg->msg_iovlen; iovlen > 0; +	for (iov = msg->msg_iter.iov, iovlen = msg->msg_iter.nr_segs; iovlen > 0;  	     iovlen--, iov++) {  		unsigned long seglen = iov->iov_len;  		char __user *from = iov->iov_base; @@ -448,14 +446,13 @@ static int skcipher_recvmsg(struct kiocb *unused, struct socket *sock,  			while (!sg->length)  				sg++; -			used = ctx->used; -			if (!used) { +			if (!ctx->used) {  				err = skcipher_wait_for_data(sk, flags);  				if (err)  					goto unlock;  			} -			used = min_t(unsigned long, used, seglen); +			used = min_t(unsigned long, ctx->used, seglen);  			used = af_alg_make_sg(&ctx->rsgl, from, used, 1);  			err = used; @@ -566,7 +563,7 @@ static void skcipher_sock_destruct(struct sock *sk)  	struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(&ctx->req);  	skcipher_free_sgl(sk); -	sock_kfree_s(sk, ctx->iv, crypto_ablkcipher_ivsize(tfm)); +	sock_kzfree_s(sk, ctx->iv, crypto_ablkcipher_ivsize(tfm));  	sock_kfree_s(sk, ctx, ctx->len);  	af_alg_release_parent(sk);  }  |