Author: mcayland Date: Fri Apr 19 09:04:32 2013 New Revision: 1123 URL: http://tracker.coreboot.org/trac/openbios/changeset/1123
Log: SPARC32: Remove zero page mapping from MMU to enable detection of NULL pointer dereferences
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk Acked-by: Artyom Tarasenko atar4qemu@gmail.com
Modified: trunk/openbios-devel/arch/sparc32/lib.c trunk/openbios-devel/arch/sparc32/ofmem_sparc32.c
Modified: trunk/openbios-devel/arch/sparc32/lib.c ============================================================================== --- trunk/openbios-devel/arch/sparc32/lib.c Fri Apr 19 09:04:25 2013 (r1122) +++ trunk/openbios-devel/arch/sparc32/lib.c Fri Apr 19 09:04:32 2013 (r1123) @@ -393,9 +393,9 @@ ofmem_arch_map_pages(pa, va, size, ofmem_arch_default_translation_mode(pa)); ofmem_map_page_range(pa, va, size, ofmem_arch_default_translation_mode(pa));
- // 1:1 mapping for RAM - ofmem_arch_map_pages(0, 0, LOWMEMSZ, ofmem_arch_default_translation_mode(0)); - ofmem_map_page_range(0, 0, LOWMEMSZ, ofmem_arch_default_translation_mode(0)); + // 1:1 mapping for RAM (don't map page 0 to allow catching of NULL dereferences) + ofmem_arch_map_pages(PAGE_SIZE, PAGE_SIZE, LOWMEMSZ - PAGE_SIZE, ofmem_arch_default_translation_mode(0)); + ofmem_map_page_range(PAGE_SIZE, PAGE_SIZE, LOWMEMSZ - PAGE_SIZE, ofmem_arch_default_translation_mode(0));
/* * Flush cache
Modified: trunk/openbios-devel/arch/sparc32/ofmem_sparc32.c ============================================================================== --- trunk/openbios-devel/arch/sparc32/ofmem_sparc32.c Fri Apr 19 09:04:25 2013 (r1122) +++ trunk/openbios-devel/arch/sparc32/ofmem_sparc32.c Fri Apr 19 09:04:32 2013 (r1123) @@ -238,6 +238,9 @@ memset(&s_ofmem_data, 0, sizeof(s_ofmem_data)); s_ofmem_data.ofmem.ramsize = qemu_mem_size; + /* Mark the first page as non-free */ + ofmem_claim_virt(0, PAGE_SIZE, 0); + /* Claim reserved physical addresses at top of RAM */ ofmem_claim_phys(ofmem_arch_get_phys_top(), s_ofmem_data.ofmem.ramsize - ofmem_arch_get_phys_top(), 0);