Skip to contentSkip to conversation

Check for brk() entering a hugepage region

hugepage 'David Gibson' 3 participants 3 messages Nov 14, 2006

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

Andrew, please apply. I could have sworn I checked ages ago, and thought that sys_brk() eventually called do_mmap_pgoff() which would do the necessary checks. Can't find any evidence of such a change though, so either I was just blind at the time, or it happened before the changeover to git.

Unlike mmap(), the codepath for brk() creates a vma without first checking that it doesn't touch a region exclusively reserved for hugepages. On powerpc, this can allow it to create a normal page vma in a hugepage region, causing oopses and other badness.

This patch adds a test to prevent this. With this patch, brk() will simply fail if it attempts to move the break into a hugepage reserved region.

mm/mmap.c +4 -0
Index: working-2.6/mm/mmap.c
===================================================================
@@ -1880,6 +1880,10 @@ unsigned long do_brk(unsigned long addr,
 	if ((addr + len) > TASK_SIZE || (addr + len) < addr)
 		return -EINVAL;
 
+	error = is_hugepage_only_range(current->mm, addr, len);
+	if (error)
+		return error;
+
 	flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
 
 	error = arch_mmap_check(addr, len, flags);
Signature · 10 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Acked-by
#1 lore raw
Quoted 11 lines · David Gibson

Andrew, please apply. I could have sworn I checked ages ago, and thought that sys_brk() eventually called do_mmap_pgoff() which would do the necessary checks. Can't find any evidence of such a change though, so either I was just blind at the time, or it happened before the changeover to git.

Unlike mmap(), the codepath for brk() creates a vma without first checking that it doesn't touch a region exclusively reserved for hugepages. On powerpc, this can allow it to create a normal page vma in a hugepage region, causing oopses and other badness.

Quoted 5 lines

This patch adds a test to prevent this. With this patch, brk() will simply fail if it attempts to move the break into a hugepage reserved region.

Signature · 8 lines
Adam Litke - (agl at us.ibm.com)
IBM Linux Technology Center

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Acked-by William Irwin
#2 lore raw
In reply to 'David Gibson'
Quoted 12 lines · David Gibson

Andrew, please apply. I could have sworn I checked ages ago, and thought that sys_brk() eventually called do_mmap_pgoff() which would do the necessary checks. Can't find any evidence of such a change though, so either I was just blind at the time, or it happened before the changeover to git.
Unlike mmap(), the codepath for brk() creates a vma without first checking that it doesn't touch a region exclusively reserved for hugepages. On powerpc, this can allow it to create a normal page vma in a hugepage region, causing oopses and other badness. This patch adds a test to prevent this. With this patch, brk() will simply fail if it attempts to move the break into a hugepage reserved region.

Quoted 1 line

-- wli

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>