Skip to contentSkip to conversation

remap_file_pages protection support: wrong "historical" code for review - 2

PATCH In review [email protected] 1 participant 1 message Aug 12, 2005

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 39/39 remap_file_pages protection support: wrong "historical" code for review - 2

From: Ingo Molnar <[email protected]>, Paolo 'Blaisorblade' Giarrusso <[email protected]>

This "fast-path" was contained in the original remap-file-pages-prot-2.6.4-rc1-mm1-A1.patch from Ingo Molnar; I think this code is wrong, but I'm sending it for review anyway, because I'm unsure (and in fact, in the end I found the reason for this).

I guess this code is intended for when we're called by sys_remap_file_page, without altering pgoffset or protections (otherwise we'd refuse operation on a private mapping). This cannot happen with mmap(MAP_POPULATE) because we clear old mappings. And the code makes sense only if we COW'ed a page, because otherwise the old mapping is already correct. I'm not sure whether we should fail here - maybe skipping the PTE would be more appropriate. Or we could anyway turn the nonblock param into a bitmask and pass O_TRUNC there.

However, this is wrong because both routines can be called from within do_file_page, which is called when !pte_present(pte) && !pte_none(pte) && pte_file(pte). I.e. the pte is not zeroed, so it has been used, but the page has been swapped out, or the page hasn't been loaded in first place (for instance for MAP_NONBLOCK).

More accurately, in that situation ->populate is called with nonblock == 0, so only install_page can be called there. If ->populate fails, the faulting process will get an inappropriate SIGBUS.

---

 linux-2.6.git-paolo/mm/fremap.c |   15 +++++++++++++++
 1 files changed, 15 insertions(+)
mm/fremap.c renamed from mm/fremap.c~rfp-wrong +15 -0
diff -puN mm/fremap.c~rfp-wrong mm/fremap.c
@@ -90,6 +90,14 @@ int install_page(struct mm_struct *mm, s
 	if (!page->mapping || page->index >= size)
 		goto err_unlock;
 
+	/*
+	 * Only install a new page for a non-shared mapping if it's
+	 * not existent yet:
+	 */
+	err = -EEXIST;
+	if (!pte_none(*pte) && !(vma->vm_flags & VM_SHARED))
+		goto err_unlock;
+
 	zap_pte(mm, vma, addr, pte);
 
 	inc_mm_counter(mm,rss);
@@ -145,6 +153,13 @@ int install_file_pte(struct mm_struct *m
 	pte = pte_alloc_map(mm, pmd, addr);
 	if (!pte)
 		goto err_unlock;
+	/*
+	 * Only install a new page for a non-shared mapping if it's
+	 * not existent yet:
+	 */
+	err = -EEXIST;
+	if (!pte_none(*pte) && !(vma->vm_flags & VM_SHARED))
+		goto err_unlock;
 
 	zap_pte(mm, vma, addr, pte);
 

_

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel