summaryrefslogtreecommitdiff
path: root/fs/ubifs
diff options
context:
space:
mode:
authorhujianyang <hujianyang@huawei.com>2014-04-30 14:06:06 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-07-06 18:54:13 -0700
commitac8df9ec7b4e25b87d5a71dfd9af4d8076d66bff (patch)
tree3db074c5c49fb8e9d584a5f3a07eb86a4a73fcc1 /fs/ubifs
parent9a87f81f9393a91c01c1e3f8dc99458bf68d1d51 (diff)
downloadlinux-3.10-ac8df9ec7b4e25b87d5a71dfd9af4d8076d66bff.tar.gz
linux-3.10-ac8df9ec7b4e25b87d5a71dfd9af4d8076d66bff.tar.bz2
linux-3.10-ac8df9ec7b4e25b87d5a71dfd9af4d8076d66bff.zip
UBIFS: fix an mmap and fsync race condition
commit 691a7c6f28ac90cccd0dbcf81348ea90b211bdd0 upstream. There is a race condition in UBIFS: Thread A (mmap) Thread B (fsync) ->__do_fault ->write_cache_pages -> ubifs_vm_page_mkwrite -> budget_space -> lock_page -> release/convert_page_budget -> SetPagePrivate -> TestSetPageDirty -> unlock_page -> lock_page -> TestClearPageDirty -> ubifs_writepage -> do_writepage -> release_budget -> ClearPagePrivate -> unlock_page -> !(ret & VM_FAULT_LOCKED) -> lock_page -> set_page_dirty -> ubifs_set_page_dirty -> TestSetPageDirty (set page dirty without budgeting) -> unlock_page This leads to situation where we have a diry page but no budget allocated for this page, so further write-back may fail with -ENOSPC. In this fix we return from page_mkwrite without performing unlock_page. We return VM_FAULT_LOCKED instead. After doing this, the race above will not happen. Signed-off-by: hujianyang <hujianyang@huawei.com> Tested-by: Laurence Withers <lwithers@guralp.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/ubifs')
-rw-r--r--fs/ubifs/file.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c
index 14374530784..881324c0843 100644
--- a/fs/ubifs/file.c
+++ b/fs/ubifs/file.c
@@ -1524,8 +1524,7 @@ static int ubifs_vm_page_mkwrite(struct vm_area_struct *vma,
}
wait_for_stable_page(page);
- unlock_page(page);
- return 0;
+ return VM_FAULT_LOCKED;
out_unlock:
unlock_page(page);