diff options
author | Benjamin LaHaise <bcrl@kvack.org> | 2013-09-09 11:57:59 -0400 |
---|---|---|
committer | Benjamin LaHaise <bcrl@kvack.org> | 2013-09-09 11:57:59 -0400 |
commit | d6c355c7dabcd753a75bc77d150d36328a355267 (patch) | |
tree | 97b30abf03e5758fca4eef8572de38b77af54ae8 /fs/aio.c | |
parent | 77d30b14d24e557f89c41980011d72428514d729 (diff) |
aio: fix race in ring buffer page lookup introduced by page migration support
Prior to the introduction of page migration support in "fs/aio: Add support
to aio ring pages migration" / 36bc08cc01709b4a9bb563b35aa530241ddc63e3,
mapping of the ring buffer pages was done via get_user_pages() while
retaining mmap_sem held for write. This avoided possible races with userland
racing an munmap() or mremap(). The page migration patch, however, switched
to using mm_populate() to prime the page mapping. mm_populate() cannot be
called with mmap_sem held.
Instead of dropping the mmap_sem, revert to the old behaviour and simply
drop the use of mm_populate() since get_user_pages() will cause the pages to
get mapped anyways. Thanks to Al Viro for spotting this issue.
Signed-off-by: Benjamin LaHaise <bcrl@kvack.org>
Diffstat (limited to 'fs/aio.c')
-rw-r--r-- | fs/aio.c | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -307,16 +307,25 @@ static int aio_setup_ring(struct kioctx *ctx) | |||
307 | aio_free_ring(ctx); | 307 | aio_free_ring(ctx); |
308 | return -EAGAIN; | 308 | return -EAGAIN; |
309 | } | 309 | } |
310 | up_write(&mm->mmap_sem); | ||
311 | |||
312 | mm_populate(ctx->mmap_base, populate); | ||
313 | 310 | ||
314 | pr_debug("mmap address: 0x%08lx\n", ctx->mmap_base); | 311 | pr_debug("mmap address: 0x%08lx\n", ctx->mmap_base); |
312 | |||
313 | /* We must do this while still holding mmap_sem for write, as we | ||
314 | * need to be protected against userspace attempting to mremap() | ||
315 | * or munmap() the ring buffer. | ||
316 | */ | ||
315 | ctx->nr_pages = get_user_pages(current, mm, ctx->mmap_base, nr_pages, | 317 | ctx->nr_pages = get_user_pages(current, mm, ctx->mmap_base, nr_pages, |
316 | 1, 0, ctx->ring_pages, NULL); | 318 | 1, 0, ctx->ring_pages, NULL); |
319 | |||
320 | /* Dropping the reference here is safe as the page cache will hold | ||
321 | * onto the pages for us. It is also required so that page migration | ||
322 | * can unmap the pages and get the right reference count. | ||
323 | */ | ||
317 | for (i = 0; i < ctx->nr_pages; i++) | 324 | for (i = 0; i < ctx->nr_pages; i++) |
318 | put_page(ctx->ring_pages[i]); | 325 | put_page(ctx->ring_pages[i]); |
319 | 326 | ||
327 | up_write(&mm->mmap_sem); | ||
328 | |||
320 | if (unlikely(ctx->nr_pages != nr_pages)) { | 329 | if (unlikely(ctx->nr_pages != nr_pages)) { |
321 | aio_free_ring(ctx); | 330 | aio_free_ring(ctx); |
322 | return -EAGAIN; | 331 | return -EAGAIN; |