Check length of unmapped area on MAP_FIXED
cover Check length of unmapped area on MAP_FIXED
RFC because the patches are not well tested. I've not triggered the issue these patches fix, but have compile tested arm, sh, and sparc64 using the default config. Please test the patches before accepting them on your arch.
arc, arm, nds32, sparc32 and sparc64 do not check the size of the requested MAP_FIXED before returning the address. It appears this issue was cloned across various architectures and, in some cases, affects both bottom up and top down searches. This set of patches aligns all platforms and search directions to check the size of a MAP_FIXED request before returning the fixed address.
Liam R. Howlett (6):
ARC: mm/mmap.c: Check length of unmapped area before allowing
MAP_FIXED
[ARM] mm/mmap.c: Check length of unmapped area before allowing
MAP_FIXED
nds32/mm/mmap.c: Check length of unmapped area before allowing
MAP_FIXED
sh/mm/mmap.c: Check length of unmapped area before allowing MAP_FIXED sys_sparc_32.c: Check length of unmapped area before allowing
MAP_FIXED
sys_sparc_64.c: Check length of unmapped area before allowing
MAP_FIXED
arch/arc/mm/mmap.c | 6 +++--- arch/arm/mm/mmap.c | 6 +++--- arch/nds32/mm/mmap.c | 6 +++--- arch/sh/mm/mmap.c | 12 ++++++------ arch/sparc/kernel/sys_sparc_32.c | 7 ++++--- arch/sparc/kernel/sys_sparc_64.c | 16 ++++++++-------- 6 files changed, 27 insertions(+), 26 deletions(-)
Signature · 6 lines
2.30.2 _______________________________________________ linux-snps-arc mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-snps-arc
RFC PATCH 1/6 ARC: mm/mmap.c: Check length of unmapped area before allowing MAP_FIXED
arch_get_unmapped_area() could potentially allow a larger than possible length when using the MAP_FIXED flag. The bound check should come before the check for MAP_FIXED.
--- arch/arc/mm/mmap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/arc/mm/mmap.c +3 -3
@@ -35,6 +35,9 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,int aliasing =cache_is_vipt_aliasing ();struct vm_unmapped_area_info info; +if (len >TASK_SIZE ) +return -ENOMEM ; +/* * We only need to do colour alignment if D cache aliases. */
@@ -51,9 +54,6 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,return addr; } -if (len >TASK_SIZE ) -return -ENOMEM ; -if (addr) {if (do_align) addr =COLOUR_ALIGN (addr, pgoff);
Signature · 6 lines
2.30.2 _______________________________________________ linux-snps-arc mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-snps-arc
RFC PATCH 2/6 mm/mmap.c: Check length of unmapped area before allowing MAP_FIXED
In reply to Liam Howlettarch_get_unmapped_area() could potentially allow a larger than possible length when using the MAP_FIXED flag. The bound check should come before the check for MAP_FIXED.
--- arch/arm/mm/mmap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/arm/mm/mmap.c +3 -3
@@ -36,6 +36,9 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,int aliasing =cache_is_vipt_aliasing ();struct vm_unmapped_area_info info; +if (len >TASK_SIZE ) +return -ENOMEM ; +/* * We only need to do colour alignment if either the I or D * caches alias.
@@ -53,9 +56,6 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,return addr; } -if (len >TASK_SIZE ) -return -ENOMEM ; -if (addr) {if (do_align) addr =COLOUR_ALIGN (addr, pgoff);
Signature · 6 lines
2.30.2 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
RFC PATCH 3/6 nds32/mm/mmap.c: Check length of unmapped area before allowing MAP_FIXED
In reply to Liam Howlettarch_get_unmapped_area() could potentially allow a larger than possible length when using the MAP_FIXED flag. The bound check should come before the check for MAP_FIXED.
management)
--- arch/nds32/mm/mmap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/nds32/mm/mmap.c +3 -3
@@ -31,6 +31,9 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,if (IS_ENABLED (CONFIG_CPU_CACHE_ALIASING )) aliasing =1 ; +if (len >TASK_SIZE ) +return -ENOMEM ; +/* * We only need to do colour alignment if either the I or D * caches alias.
@@ -48,9 +51,6 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,return addr; } -if (len >TASK_SIZE ) -return -ENOMEM ; -if (addr) {if (do_align) addr =COLOUR_ALIGN (addr, pgoff);
Signature · 1 line
2.30.2
RFC PATCH 4/6 sh/mm/mmap.c: Check length of unmapped area before allowing MAP_FIXED
In reply to Liam Howlettarch_get_unmapped_area() and arch_get_unmapped_area_topdown() could potentially allow a larger than possible length when using the MAP_FIXED flag. The bound check should come before the check for MAP_FIXED.
--- arch/sh/mm/mmap.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
arch/sh/mm/mmap.c +6 -6
@@ -39,6 +39,9 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,int do_colour_align;struct vm_unmapped_area_info info; +if (unlikely (len >TASK_SIZE )) +return -ENOMEM ; +if (flags &MAP_FIXED ) {/* We do not accept a shared mapping if it would violate * cache aliasing constraints.
@@ -49,9 +52,6 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,return addr; } -if (unlikely (len >TASK_SIZE )) -return -ENOMEM ; - do_colour_align =0 ;if (filp || (flags &MAP_SHARED )) do_colour_align =1 ;
@@ -88,6 +88,9 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,int do_colour_align;struct vm_unmapped_area_info info; +if (unlikely (len >TASK_SIZE )) +return -ENOMEM ; +if (flags &MAP_FIXED ) {/* We do not accept a shared mapping if it would violate * cache aliasing constraints.
@@ -98,9 +101,6 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,return addr; } -if (unlikely (len >TASK_SIZE )) -return -ENOMEM ; - do_colour_align =0 ;if (filp || (flags &MAP_SHARED )) do_colour_align =1 ;
Signature · 1 line
2.30.2
RFC PATCH 5/6 sys_sparc_32.c: Check length of unmapped area before allowing MAP_FIXED
In reply to Liam Howlettarch_get_unmapped_area() could potentially allow a larger than possible length when using the MAP_FIXED flag. The bound check should come before the check for MAP_FIXED.
--- arch/sparc/kernel/sys_sparc_32.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
arch/sparc/kernel/sys_sparc_32.c +4 -3
@@ -43,6 +43,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi {struct vm_unmapped_area_info info; +/* See asm-sparc/uaccess.h */ +if (len >TASK_SIZE -PAGE_SIZE ) +return -ENOMEM ; +if (flags &MAP_FIXED ) {/* We do not accept a shared mapping if it would violate * cache aliasing constraints.
@@ -53,9 +57,6 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsireturn addr; } -/* See asm-sparc/uaccess.h */ -if (len >TASK_SIZE -PAGE_SIZE ) -return -ENOMEM ;if (!addr) addr =TASK_UNMAPPED_BASE ;
Signature · 1 line
2.30.2
RFC PATCH 6/6 sys_sparc_64.c: Check length of unmapped area before allowing MAP_FIXED
In reply to Liam Howlettarch_get_unmapped_area() and arch_get_unmapped_area_topdown() could potentially allow a larger than possible length when using the MAP_FIXED flag. The bound check should come before the check for MAP_FIXED.
--- arch/sparc/kernel/sys_sparc_64.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
arch/sparc/kernel/sys_sparc_64.c +8 -8
@@ -95,6 +95,11 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsiint do_color_align;struct vm_unmapped_area_info info; +if (test_thread_flag (TIF_32BIT )) + task_size =STACK_TOP32 ; +if (unlikely (len > task_size || len >=VA_EXCLUDE_START )) +return -ENOMEM ; +if (flags &MAP_FIXED ) {/* We do not accept a shared mapping if it would violate * cache aliasing constraints.
@@ -105,11 +110,6 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsireturn addr; } -if (test_thread_flag (TIF_32BIT )) - task_size =STACK_TOP32 ; -if (unlikely (len > task_size || len >=VA_EXCLUDE_START )) -return -ENOMEM ; - do_color_align =0 ;if (filp || (flags &MAP_SHARED )) do_color_align =1 ;
@@ -159,6 +159,9 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,/* This should only ever run for 32-bit processes. */ BUG_ON (!test_thread_flag (TIF_32BIT )); +if (unlikely (len > task_size)) +return -ENOMEM ; +if (flags &MAP_FIXED ) {/* We do not accept a shared mapping if it would violate * cache aliasing constraints.
@@ -169,9 +172,6 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,return addr; } -if (unlikely (len > task_size)) -return -ENOMEM ; - do_color_align =0 ;if (filp || (flags &MAP_SHARED )) do_color_align =1 ;
Signature · 1 line
2.30.2