From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933560AbbGGWkT (ORCPT ); Tue, 7 Jul 2015 18:40:19 -0400 Received: from mail-ig0-f176.google.com ([209.85.213.176]:32819 "EHLO mail-ig0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932851AbbGGWkP (ORCPT ); Tue, 7 Jul 2015 18:40:15 -0400 MIME-Version: 1.0 In-Reply-To: <1436300428-21163-9-git-send-email-yinghai@kernel.org> References: <1436300428-21163-1-git-send-email-yinghai@kernel.org> <1436300428-21163-9-git-send-email-yinghai@kernel.org> Date: Tue, 7 Jul 2015 15:40:14 -0700 X-Google-Sender-Auth: AWSKpfWP87r-IiSJzxXjAjDQ5E0 Message-ID: Subject: Re: [PATCH 08/42] x86, kaslr: Get correct max_addr for relocs pointer From: Kees Cook To: Yinghai Lu Cc: "H. Peter Anvin" , Baoquan He , LKML Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 7, 2015 at 1:19 PM, Yinghai Lu wrote: > There is boundary checking for pointer in kaslr relocation handling. > > Current code is using output_len, and that is VO (vmlinux after objcopy) > file size plus vmlinux.relocs file size. > > That is not right, as we should use loaded address for running. > > At that time parse_elf already move the sections according to ELF headers. > > The valid range should be VO [_text, __bss_start) loaded physical addresses. > > In the patch, add export for __bss_start to voffset.h and use it to get > max_addr. > > Signed-off-by: Yinghai Lu This seems correct, thanks! Acked-by: Kees Cook > --- > arch/x86/boot/compressed/Makefile | 2 +- > arch/x86/boot/compressed/misc.c | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile > index 50daea7..e12a93c 100644 > --- a/arch/x86/boot/compressed/Makefile > +++ b/arch/x86/boot/compressed/Makefile > @@ -40,7 +40,7 @@ LDFLAGS_vmlinux := -T > hostprogs-y := mkpiggy > HOST_EXTRACFLAGS += -I$(srctree)/tools/include > > -sed-voffset := -e 's/^\([0-9a-fA-F]*\) [ABCDGRSTVW] \(_text\|_end\)$$/\#define VO_\2 _AC(0x\1,UL)/p' > +sed-voffset := -e 's/^\([0-9a-fA-F]*\) [ABCDGRSTVW] \(_text\|__bss_start\|_end\)$$/\#define VO_\2 _AC(0x\1,UL)/p' > > quiet_cmd_voffset = VOFFSET $@ > cmd_voffset = $(NM) $< | sed -n $(sed-voffset) > $@ > diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c > index db97bdf..8fb74ba 100644 > --- a/arch/x86/boot/compressed/misc.c > +++ b/arch/x86/boot/compressed/misc.c > @@ -234,7 +234,7 @@ static void handle_relocations(void *output, unsigned long output_len) > int *reloc; > unsigned long delta, map, ptr; > unsigned long min_addr = (unsigned long)output; > - unsigned long max_addr = min_addr + output_len; > + unsigned long max_addr = min_addr + (VO___bss_start - VO__text); > > /* > * Calculate the delta between where vmlinux was linked to load > -- > 1.8.4.5 > -- Kees Cook Chrome OS Security