Skip to contentSkip to conversation

resend, /dev/zero vs hugetlb mappings.

PATCH New Oleg Nesterov 1 participant 1 message Jul 9, 2004 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 resend, /dev/zero vs hugetlb mappings.

Hello.

Hugetlbfs mmap with MAP_PRIVATE becomes MAP_SHARED silently, but vma->vm_flags have no VM_SHARED bit. Reading from /dev/zero into hugetlb area will do:

read_zero()

    read_zero_pagealigned()
        if (vma->vm_flags & VM_SHARED)
            break;                      // fallback to clear_user()
        zap_page_range();
        zeromap_page_range();

It will hit BUG_ON() in unmap_hugepage_range() if region is not huge page aligned, or silently convert it into the private anonymous mapping.

Patch against mm7.

Oleg.

drivers/char/mem.c renamed from drivers/char/mem.c.orig +1 -1
@@ -415,7 +415,7 @@ static inline size_t read_zero_pagealign
 
 		if (vma->vm_start > addr || (vma->vm_flags & VM_WRITE) == 0)
 			goto out_up;
-		if (vma->vm_flags & VM_SHARED)
+		if (vma->vm_flags & (VM_SHARED | VM_HUGETLB))
 			break;
 		count = vma->vm_end - addr;
 		if (count > size)