Skip to content

Commit

Permalink
mm/filemap_xip.c: fix race condition in xip_file_fault()
Browse files Browse the repository at this point in the history
commit 99f02ef upstream.

Fix a race condition that shows in conjunction with xip_file_fault() when
two threads of the same user process fault on the same memory page.

In this case, the race winner will install the page table entry and the
unlucky loser will cause an oops: xip_file_fault calls vm_insert_pfn (via
vm_insert_mixed) which drops out at this check:

	retval = -EBUSY;
	if (!pte_none(*pte))
		goto out_unlock;

The resulting -EBUSY return value will trigger a BUG_ON() in
xip_file_fault.

This fix simply considers the fault as fixed in this case, because the
race winner has successfully installed the pte.

[[email protected]: use conventional (and consistent) comment layout]
Reported-by: David Sadler <[email protected]>
Signed-off-by: Carsten Otte <[email protected]>
Reported-by: Louis Alex Eisner <[email protected]>
Cc: Hugh Dickins <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
Carsten Otte authored and koenkooi committed May 4, 2012
1 parent 33c2a5e commit c8ed4d2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion mm/filemap_xip.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,12 @@ static int xip_file_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
xip_pfn);
if (err == -ENOMEM)
return VM_FAULT_OOM;
BUG_ON(err);
/*
* err == -EBUSY is fine, we've raced against another thread
* that faulted-in the same page
*/
if (err != -EBUSY)
BUG_ON(err);
return VM_FAULT_NOPAGE;
} else {
int err, ret = VM_FAULT_OOM;
Expand Down

0 comments on commit c8ed4d2

Please sign in to comment.