diff options
| author | David S. Miller <davem@davemloft.net> | 2015-02-04 23:46:55 -0500 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2015-02-04 23:46:55 -0500 |
| commit | f2683b743f2334ef49a5361bf596dd1fbd2c9be4 (patch) | |
| tree | 7f53b2614742238e966ba8a815ef6c5079422ee2 | |
| parent | 9878196578286c5ed494778ada01da094377a686 (diff) | |
| parent | 57dd8a0735aabff4862025cf64ad94da3d80e620 (diff) | |
Merge branch 'for-davem' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
More iov_iter work from Al Viro.
Signed-off-by: David S. Miller <davem@davemloft.net>
33 files changed, 320 insertions, 686 deletions
diff --git a/crypto/af_alg.c b/crypto/af_alg.c index 4665b79c729a..eb78fe8a60c8 100644 --- a/crypto/af_alg.c +++ b/crypto/af_alg.c | |||
| @@ -338,49 +338,31 @@ static const struct net_proto_family alg_family = { | |||
| 338 | .owner = THIS_MODULE, | 338 | .owner = THIS_MODULE, |
| 339 | }; | 339 | }; |
| 340 | 340 | ||
| 341 | int af_alg_make_sg(struct af_alg_sgl *sgl, void __user *addr, int len, | 341 | int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len) |
| 342 | int write) | ||
| 343 | { | 342 | { |
| 344 | unsigned long from = (unsigned long)addr; | 343 | size_t off; |
| 345 | unsigned long npages; | 344 | ssize_t n; |
| 346 | unsigned off; | 345 | int npages, i; |
| 347 | int err; | ||
| 348 | int i; | ||
| 349 | |||
| 350 | err = -EFAULT; | ||
| 351 | if (!access_ok(write ? VERIFY_READ : VERIFY_WRITE, addr, len)) | ||
| 352 | goto out; | ||
| 353 | |||
| 354 | off = from & ~PAGE_MASK; | ||
| 355 | npages = (off + len + PAGE_SIZE - 1) >> PAGE_SHIFT; | ||
| 356 | if (npages > ALG_MAX_PAGES) | ||
| 357 | npages = ALG_MAX_PAGES; | ||
| 358 | 346 | ||
| 359 | err = get_user_pages_fast(from, npages, write, sgl->pages); | 347 | n = iov_iter_get_pages(iter, sgl->pages, len, ALG_MAX_PAGES, &off); |
| 360 | if (err < 0) | 348 | if (n < 0) |
| 361 | goto out; | 349 | return n; |
| 362 | 350 | ||
| 363 | npages = err; | 351 | npages = PAGE_ALIGN(off + n); |
| 364 | err = -EINVAL; | ||
| 365 | if (WARN_ON(npages == 0)) | 352 | if (WARN_ON(npages == 0)) |
| 366 | goto out; | 353 | return -EINVAL; |
| 367 | |||
| 368 | err = 0; | ||
| 369 | 354 | ||
| 370 | sg_init_table(sgl->sg, npages); | 355 | sg_init_table(sgl->sg, npages); |
| 371 | 356 | ||
| 372 | for (i = 0; i < npages; i++) { | 357 | for (i = 0, len = n; i < npages; i++) { |
| 373 | int plen = min_t(int, len, PAGE_SIZE - off); | 358 | int plen = min_t(int, len, PAGE_SIZE - off); |
| 374 | 359 | ||
| 375 | sg_set_page(sgl->sg + i, sgl->pages[i], plen, off); | 360 | sg_set_page(sgl->sg + i, sgl->pages[i], plen, off); |
| 376 | 361 | ||
| 377 | off = 0; | 362 | off = 0; |
| 378 | len -= plen; | 363 | len -= plen; |
| 379 | err += plen; | ||
| 380 | } | 364 | } |
| 381 | 365 | return n; | |
| 382 | out: | ||
| 383 | return err; | ||
| 384 | } | 366 | } |
| 385 | EXPORT_SYMBOL_GPL(af_alg_make_sg); | 367 | EXPORT_SYMBOL_GPL(af_alg_make_sg); |
| 386 | 368 | ||
diff --git a/crypto/algif_hash.c b/crypto/algif_hash.c index 01f56eb7816e..01da360bdb55 100644 --- a/crypto/algif_hash.c +++ b/crypto/algif_hash.c | |||
| @@ -41,8 +41,6 @@ static int hash_sendmsg(struct kiocb *unused, struct socket *sock, | |||
| 41 | struct sock *sk = sock->sk; | 41 | struct sock *sk = sock->sk; |
| 42 | struct alg_sock *ask = alg_sk(sk); | 42 | struct alg_sock *ask = alg_sk(sk); |
| 43 | struct hash_ctx *ctx = ask->private; | 43 | struct hash_ctx *ctx = ask->private; |
| 44 | unsigned long iovlen; | ||
| 45 | const struct iovec *iov; | ||
| 46 | long copied = 0; | 44 | long copied = 0; |
| 47 | int err; | 45 | int err; |
| 48 | 46 | ||
| @@ -58,37 +56,28 @@ static int hash_sendmsg(struct kiocb *unused, struct socket *sock, | |||
| 58 | 56 | ||
| 59 | ctx->more = 0; | 57 | ctx->more = 0; |
| 60 | 58 | ||
| 61 | for (iov = msg->msg_iter.iov, iovlen = msg->msg_iter.nr_segs; iovlen > 0; | 59 | while (iov_iter_count(&msg->msg_iter)) { |
| 62 | iovlen--, iov++) { | 60 | int len = iov_iter_count(&msg->msg_iter); |
| 63 | unsigned long seglen = iov->iov_len; | ||
| 64 | char __user *from = iov->iov_base; | ||
| 65 | 61 | ||
| 66 | while (seglen) { | 62 | if (len > limit) |
| 67 | int len = min_t(unsigned long, seglen, limit); | 63 | len = limit; |
| 68 | int newlen; | ||
| 69 | 64 | ||
| 70 | newlen = af_alg_make_sg(&ctx->sgl, from, len, 0); | 65 | len = af_alg_make_sg(&ctx->sgl, &msg->msg_iter, len); |
| 71 | if (newlen < 0) { | 66 | if (len < 0) { |
| 72 | err = copied ? 0 : newlen; | 67 | err = copied ? 0 : len; |
| 73 | goto unlock; | 68 | goto unlock; |
| 74 | } | 69 | } |
| 75 | |||
| 76 | ahash_request_set_crypt(&ctx->req, ctx->sgl.sg, NULL, | ||
| 77 | newlen); | ||
| 78 | |||
| 79 | err = af_alg_wait_for_completion( | ||
| 80 | crypto_ahash_update(&ctx->req), | ||
| 81 | &ctx->completion); | ||
| 82 | 70 | ||
| 83 | af_alg_free_sg(&ctx->sgl); | 71 | ahash_request_set_crypt(&ctx->req, ctx->sgl.sg, NULL, len); |
| 84 | 72 | ||
| 85 | if (err) | 73 | err = af_alg_wait_for_completion(crypto_ahash_update(&ctx->req), |
| 86 | goto unlock; | 74 | &ctx->completion); |
| 75 | af_alg_free_sg(&ctx->sgl); | ||
| 76 | if (err) | ||
| 77 | goto unlock; | ||
| 87 | 78 | ||
| 88 | seglen -= newlen; | 79 | copied += len; |
| 89 | from += newlen; | 80 | iov_iter_advance(&msg->msg_iter, len); |
| 90 | copied += newlen; | ||
| 91 | } | ||
| 92 | } | 81 | } |
| 93 | 82 | ||
| 94 | err = 0; | 83 | err = 0; |
diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c index c12207c8dde9..37110fd68adf 100644 --- a/crypto/algif_skcipher.c +++ b/crypto/algif_skcipher.c | |||
| @@ -426,67 +426,59 @@ static int skcipher_recvmsg(struct kiocb *unused, struct socket *sock, | |||
| 426 | &ctx->req)); | 426 | &ctx->req)); |
| 427 | struct skcipher_sg_list *sgl; | 427 | struct skcipher_sg_list *sgl; |
| 428 | struct scatterlist *sg; | 428 | struct scatterlist *sg; |
| 429 | unsigned long iovlen; | ||
| 430 | const struct iovec *iov; | ||
| 431 | int err = -EAGAIN; | 429 | int err = -EAGAIN; |
| 432 | int used; | 430 | int used; |
| 433 | long copied = 0; | 431 | long copied = 0; |
