Commit f9e7a5fa authored by David Howells's avatar David Howells Committed by Paolo Abeni

crypto: af_alg: Pin pages rather than ref'ing if appropriate

Convert AF_ALG to use iov_iter_extract_pages() instead of
iov_iter_get_pages().  This will pin pages or leave them unaltered rather
than getting a ref on them as appropriate to the iterator.

The pages need to be pinned for DIO-read rather than having refs taken on
them to prevent VM copy-on-write from malfunctioning during a concurrent
fork() (the result of the I/O would otherwise end up only visible to the
child process and not the parent).
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
cc: Herbert Xu <herbert@gondor.apana.org.au>
cc: "David S. Miller" <davem@davemloft.net>
cc: Eric Dumazet <edumazet@google.com>
cc: Jakub Kicinski <kuba@kernel.org>
cc: Paolo Abeni <pabeni@redhat.com>
cc: Jens Axboe <axboe@kernel.dk>
cc: Matthew Wilcox <willy@infradead.org>
cc: linux-crypto@vger.kernel.org
cc: netdev@vger.kernel.org
Acked-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent f5f82cd1
...@@ -533,14 +533,17 @@ static const struct net_proto_family alg_family = { ...@@ -533,14 +533,17 @@ static const struct net_proto_family alg_family = {
int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len) int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len)
{ {
struct page **pages = sgl->pages;
size_t off; size_t off;
ssize_t n; ssize_t n;
int npages, i; int npages, i;
n = iov_iter_get_pages2(iter, sgl->pages, len, ALG_MAX_PAGES, &off); n = iov_iter_extract_pages(iter, &pages, len, ALG_MAX_PAGES, 0, &off);
if (n < 0) if (n < 0)
return n; return n;
sgl->need_unpin = iov_iter_extract_will_pin(iter);
npages = DIV_ROUND_UP(off + n, PAGE_SIZE); npages = DIV_ROUND_UP(off + n, PAGE_SIZE);
if (WARN_ON(npages == 0)) if (WARN_ON(npages == 0))
return -EINVAL; return -EINVAL;
...@@ -573,8 +576,9 @@ void af_alg_free_sg(struct af_alg_sgl *sgl) ...@@ -573,8 +576,9 @@ void af_alg_free_sg(struct af_alg_sgl *sgl)
{ {
int i; int i;
for (i = 0; i < sgl->npages; i++) if (sgl->need_unpin)
put_page(sgl->pages[i]); for (i = 0; i < sgl->npages; i++)
unpin_user_page(sgl->pages[i]);
} }
EXPORT_SYMBOL_GPL(af_alg_free_sg); EXPORT_SYMBOL_GPL(af_alg_free_sg);
......
...@@ -59,6 +59,7 @@ struct af_alg_sgl { ...@@ -59,6 +59,7 @@ struct af_alg_sgl {
struct scatterlist sg[ALG_MAX_PAGES + 1]; struct scatterlist sg[ALG_MAX_PAGES + 1];
struct page *pages[ALG_MAX_PAGES]; struct page *pages[ALG_MAX_PAGES];
unsigned int npages; unsigned int npages;
bool need_unpin;
}; };
/* TX SGL entry */ /* TX SGL entry */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment