From mboxrd@z Thu Jan 1 00:00:00 1970 From: lauraa@codeaurora.org (Laura Abbott) Date: Thu, 30 Oct 2014 10:17:37 -0700 Subject: [PATCHv4 7/7] arm64: add better page protections to arm64 In-Reply-To: <20141028142040.GH9796@leverpostej> References: <1414440752-9411-1-git-send-email-lauraa@codeaurora.org> <1414440752-9411-8-git-send-email-lauraa@codeaurora.org> <20141028142040.GH9796@leverpostej> Message-ID: <545272B1.7080702@codeaurora.org> To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org On 10/28/2014 7:20 AM, Mark Rutland wrote: > [resending due to previous header destruction] > > Hi Laura, > > On Mon, Oct 27, 2014 at 08:12:32PM +0000, Laura Abbott wrote: >> Add page protections for arm64 similar to those in arm. >> This is for security reasons to prevent certain classes >> of exploits. The current method: >> >> - Map all memory as either RWX or RW. We round to the nearest >> section to avoid creating page tables before everything is mapped >> - Once everything is mapped, if either end of the RWX section should >> not be X, we split the PMD and remap as necessary >> - When initmem is to be freed, we change the permissions back to >> RW (using stop machine if necessary to flush the TLB) >> - If CONFIG_DEBUG_RODATA is set, the read only sections are set >> read only. >> >> Signed-off-by: Laura Abbott >> --- >> v4: Combined the Kconfig options >> --- >> arch/arm64/Kconfig.debug | 23 +++ >> arch/arm64/include/asm/cacheflush.h | 4 + >> arch/arm64/kernel/vmlinux.lds.S | 17 ++ >> arch/arm64/mm/init.c | 1 + >> arch/arm64/mm/mm.h | 2 + >> arch/arm64/mm/mmu.c | 303 +++++++++++++++++++++++++++++++----- >> 6 files changed, 314 insertions(+), 36 deletions(-) > > With this patch applied to v3.18-rc2, my board to blows up at boot when > using UEFI (without DEBUG_RODATA selected): > > ---->8---- > EFI stub: Booting Linux Kernel... > Initializing cgroup subsys cpu > Linux version 3.18.0-rc2+ (mark at leverpostej) (gcc version 4.9.2 20140904 (prerelease) (crosstool-NG linaro-1.13.1-4.9-2014.09 - Linaro GCC 4.9-2014.09) ) #112 SMP PREEMPT Tue Oct 28 13:58:41 GMT 2014 > CPU: AArch64 Processor [410fd030] revision 0 > Detected VIPT I-cache on CPU0 > bootconsole [uart0] enabled > efi: Getting EFI parameters from FDT: > EFI v2.40 by ARM Juno EFI Oct 7 2014 15:05:42 > efi: ACPI=0xfebdc000 ACPI 2.0=0xfebdc014 > cma: Reserved 16 MiB at fd800000 > BUG: failure at arch/arm64/mm/mmu.c:234/alloc_init_pmd()! > Kernel panic - not syncing: BUG! > CPU: 0 PID: 0 Comm: swapper Not tainted 3.18.0-rc2+ #112 > Call trace: > [] dump_backtrace+0x0/0x124 > [] show_stack+0x10/0x1c > [] dump_stack+0x74/0xb8 > [] panic+0xe0/0x220 > [] alloc_init_pmd+0x1cc/0x1dc > [] alloc_init_pud+0x24/0x6c > [] __create_mapping+0xd0/0xf0 > [] create_id_mapping+0x5c/0x68 > [] efi_idmap_init+0x54/0xd8 > [] setup_arch+0x408/0x5c0 > [] start_kernel+0x94/0x3a0 > ---[ end Kernel panic - not syncing: BUG! > ---->8---- > > I've not yet figured out precisely why. I haven't tried a !EFI boot > because of the way my board is set up at the moment. > I think it's because the idmap is now being created earlier than expected so it's trying to get memory from the normal allocator and dying. I'll have to see if I can get my hands on an EFI board and test it out. Thanks, Laura -- Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project