aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/algif_skcipher.c
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2015-02-10 14:35:36 -0500
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2015-02-10 14:35:36 -0500
commit4ba24fef3eb3b142197135223b90ced2f319cd53 (patch)
treea20c125b27740ec7b4c761b11d801108e1b316b2 /crypto/algif_skcipher.c
parent47c1ffb2b6b630894e9a16442611c056ab21c057 (diff)
parent98a4a59ee31a12105a2b84f5b8b515ac2cb208ef (diff)
Merge branch 'next' into for-linus
Prepare first round of input updates for 3.20.
Diffstat (limited to 'crypto/algif_skcipher.c')
-rw-r--r--crypto/algif_skcipher.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c
index a19c027b29bd..c12207c8dde9 100644
--- a/crypto/algif_skcipher.c
+++ b/crypto/algif_skcipher.c
@@ -49,7 +49,7 @@ struct skcipher_ctx {
49 struct ablkcipher_request req; 49 struct ablkcipher_request req;
50}; 50};
51 51
52#define MAX_SGL_ENTS ((PAGE_SIZE - sizeof(struct skcipher_sg_list)) / \ 52#define MAX_SGL_ENTS ((4096 - sizeof(struct skcipher_sg_list)) / \
53 sizeof(struct scatterlist) - 1) 53 sizeof(struct scatterlist) - 1)
54 54
55static inline int skcipher_sndbuf(struct sock *sk) 55static inline int skcipher_sndbuf(struct sock *sk)
@@ -251,6 +251,7 @@ static int skcipher_sendmsg(struct kiocb *unused, struct socket *sock,
251 struct af_alg_control con = {}; 251 struct af_alg_control con = {};
252 long copied = 0; 252 long copied = 0;
253 bool enc = 0; 253 bool enc = 0;
254 bool init = 0;
254 int err; 255 int err;
255 int i; 256 int i;
256 257
@@ -259,6 +260,7 @@ static int skcipher_sendmsg(struct kiocb *unused, struct socket *sock,
259 if (err) 260 if (err)
260 return err; 261 return err;
261 262
263 init = 1;
262 switch (con.op) { 264 switch (con.op) {
263 case ALG_OP_ENCRYPT: 265 case ALG_OP_ENCRYPT:
264 enc = 1; 266 enc = 1;
@@ -280,7 +282,7 @@ static int skcipher_sendmsg(struct kiocb *unused, struct socket *sock,
280 if (!ctx->more && ctx->used) 282 if (!ctx->more && ctx->used)
281 goto unlock; 283 goto unlock;
282 284
283 if (!ctx->used) { 285 if (init) {
284 ctx->enc = enc; 286 ctx->enc = enc;
285 if (con.iv) 287 if (con.iv)
286 memcpy(ctx->iv, con.iv->iv, ivsize); 288 memcpy(ctx->iv, con.iv->iv, ivsize);
@@ -298,9 +300,9 @@ static int skcipher_sendmsg(struct kiocb *unused, struct socket *sock,
298 len = min_t(unsigned long, len, 300 len = min_t(unsigned long, len,
299 PAGE_SIZE - sg->offset - sg->length); 301 PAGE_SIZE - sg->offset - sg->length);
300 302
301 err = memcpy_fromiovec(page_address(sg_page(sg)) + 303 err = memcpy_from_msg(page_address(sg_page(sg)) +
302 sg->offset + sg->length, 304 sg->offset + sg->length,
303 msg->msg_iov, len); 305 msg, len);
304 if (err) 306 if (err)
305 goto unlock; 307 goto unlock;
306 308
@@ -337,8 +339,8 @@ static int skcipher_sendmsg(struct kiocb *unused, struct socket *sock,
337 if (!sg_page(sg + i)) 339 if (!sg_page(sg + i))
338 goto unlock; 340 goto unlock;
339 341
340 err = memcpy_fromiovec(page_address(sg_page(sg + i)), 342 err = memcpy_from_msg(page_address(sg_page(sg + i)),
341 msg->msg_iov, plen); 343 msg, plen);
342 if (err) { 344 if (err) {
343 __free_page(sg_page(sg + i)); 345 __free_page(sg_page(sg + i));
344 sg_assign_page(sg + i, NULL); 346 sg_assign_page(sg + i, NULL);
@@ -359,8 +361,6 @@ static int skcipher_sendmsg(struct kiocb *unused, struct socket *sock,
359 err = 0; 361 err = 0;
360 362
361 ctx->more = msg->msg_flags & MSG_MORE; 363 ctx->more = msg->msg_flags & MSG_MORE;
362 if (!ctx->more && !list_empty(&ctx->tsgl))
363 sgl = list_entry(ctx->tsgl.prev, struct skcipher_sg_list, list);
364 364
365unlock: 365unlock:
366 skcipher_data_wakeup(sk); 366 skcipher_data_wakeup(sk);
@@ -408,8 +408,6 @@ static ssize_t skcipher_sendpage(struct socket *sock, struct page *page,
408 408
409done: 409done:
410 ctx->more = flags & MSG_MORE; 410 ctx->more = flags & MSG_MORE;
411 if (!ctx->more && !list_empty(&ctx->tsgl))
412 sgl = list_entry(ctx->tsgl.prev, struct skcipher_sg_list, list);
413 411
414unlock: 412unlock:
415 skcipher_data_wakeup(sk); 413 skcipher_data_wakeup(sk);
@@ -429,13 +427,13 @@ static int skcipher_recvmsg(struct kiocb *unused, struct socket *sock,
429 struct skcipher_sg_list *sgl; 427 struct skcipher_sg_list *sgl;
430 struct scatterlist *sg; 428 struct scatterlist *sg;
431 unsigned long iovlen; 429 unsigned long iovlen;
432 struct iovec *iov; 430 const struct iovec *iov;
433 int err = -EAGAIN; 431 int err = -EAGAIN;
434 int used; 432 int used;
435 long copied = 0; 433 long copied = 0;
436 434
437 lock_sock(sk); 435 lock_sock(sk);
438 for (iov = msg->msg_iov, iovlen = msg->msg_iovlen; iovlen > 0; 436 for (iov = msg->msg_iter.iov, iovlen = msg->msg_iter.nr_segs; iovlen > 0;
439 iovlen--, iov++) { 437 iovlen--, iov++) {
440 unsigned long seglen = iov->iov_len; 438 unsigned long seglen = iov->iov_len;
441 char __user *from = iov->iov_base; 439 char __user *from = iov->iov_base;
@@ -448,14 +446,13 @@ static int skcipher_recvmsg(struct kiocb *unused, struct socket *sock,
448 while (!sg->length) 446 while (!sg->length)
449 sg++; 447 sg++;
450 448
451 used = ctx->used; 449 if (!ctx->used) {
452 if (!used) {
453 err = skcipher_wait_for_data(sk, flags); 450 err = skcipher_wait_for_data(sk, flags);
454 if (err) 451 if (err)
455 goto unlock; 452 goto unlock;
456 } 453 }
457 454
458 used = min_t(unsigned long, used, seglen); 455 used = min_t(unsigned long, ctx->used, seglen);
459 456
460 used = af_alg_make_sg(&ctx->rsgl, from, used, 1); 457 used = af_alg_make_sg(&ctx->rsgl, from, used, 1);
461 err = used; 458 err = used;
@@ -566,7 +563,7 @@ static void skcipher_sock_destruct(struct sock *sk)
566 struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(&ctx->req); 563 struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(&ctx->req);
567 564
568 skcipher_free_sgl(sk); 565 skcipher_free_sgl(sk);
569 sock_kfree_s(sk, ctx->iv, crypto_ablkcipher_ivsize(tfm)); 566 sock_kzfree_s(sk, ctx->iv, crypto_ablkcipher_ivsize(tfm));
570 sock_kfree_s(sk, ctx, ctx->len); 567 sock_kfree_s(sk, ctx, ctx->len);
571 af_alg_release_parent(sk); 568 af_alg_release_parent(sk);
572} 569}