]> git.openfabrics.org - ~emulex/infiniband.git/commitdiff
UBIFS: fix an mmap and fsync race condition
authorhujianyang <hujianyang@huawei.com>
Wed, 30 Apr 2014 06:06:06 +0000 (14:06 +0800)
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Tue, 13 May 2014 10:45:15 +0000 (13:45 +0300)
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>
Cc: stable@vger.kernel.org
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
fs/ubifs/file.c

index 4f34dbae823dc9930077a4599933e14b7e457de9..f7d48a08f44393435e253a706d4d6bbf2d467e15 100644 (file)
@@ -1525,8 +1525,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);