Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753205AbcD2Jy1 (ORCPT ); Fri, 29 Apr 2016 05:54:27 -0400 Received: from terminus.zytor.com ([198.137.202.10]:53258 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752699AbcD2JyY (ORCPT ); Fri, 29 Apr 2016 05:54:24 -0400 Date: Fri, 29 Apr 2016 02:53:13 -0700 From: tip-bot for Yinghai Lu Message-ID: Cc: dvlasenk@redhat.com, tglx@linutronix.de, vgoyal@redhat.com, dyoung@redhat.com, linux-kernel@vger.kernel.org, keescook@chromium.org, peterz@infradead.org, hpa@zytor.com, luto@amacapital.net, brgerst@gmail.com, yinghai@kernel.org, bhe@redhat.com, luto@kernel.org, mingo@kernel.org, torvalds@linux-foundation.org, bp@alien8.de, akpm@linux-foundation.org Reply-To: torvalds@linux-foundation.org, akpm@linux-foundation.org, bp@alien8.de, luto@kernel.org, mingo@kernel.org, bhe@redhat.com, luto@amacapital.net, yinghai@kernel.org, brgerst@gmail.com, peterz@infradead.org, keescook@chromium.org, hpa@zytor.com, vgoyal@redhat.com, tglx@linutronix.de, dvlasenk@redhat.com, linux-kernel@vger.kernel.org, dyoung@redhat.com In-Reply-To: <1461888548-32439-7-git-send-email-keescook@chromium.org> References: <1461888548-32439-7-git-send-email-keescook@chromium.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/boot] x86/boot: Correctly bounds-check relocations Git-Commit-ID: 4abf061bf87bbd856c8d60199b2fba8b8f9b9fd6 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2944 Lines: 68 Commit-ID: 4abf061bf87bbd856c8d60199b2fba8b8f9b9fd6 Gitweb: http://git.kernel.org/tip/4abf061bf87bbd856c8d60199b2fba8b8f9b9fd6 Author: Yinghai Lu AuthorDate: Thu, 28 Apr 2016 17:09:08 -0700 Committer: Ingo Molnar CommitDate: Fri, 29 Apr 2016 11:03:30 +0200 x86/boot: Correctly bounds-check relocations Relocation handling performs bounds checking on the resulting calculated addresses. The existing code uses output_len (VO size plus relocs size) as the max address. This is not right since the max_addr check should stop at the end of VO and exclude bss, brk, etc, which follows. The valid range should be VO [_text, __bss_start] in the loaded physical address space. This patch adds an export for __bss_start in voffset.h and uses it to set the correct limit for max_addr. Signed-off-by: Yinghai Lu [ Rewrote the changelog. ] Signed-off-by: Kees Cook Cc: Andrew Morton Cc: Andy Lutomirski Cc: Andy Lutomirski Cc: Baoquan He Cc: Borislav Petkov Cc: Brian Gerst Cc: Dave Young Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Vivek Goyal Cc: lasse.collin@tukaani.org Link: http://lkml.kernel.org/r/1461888548-32439-7-git-send-email-keescook@chromium.org Signed-off-by: Ingo Molnar --- 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 adef26d..75f2233 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -57,7 +57,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 bee6238..8f0253d 100644 --- a/arch/x86/boot/compressed/misc.c +++ b/arch/x86/boot/compressed/misc.c @@ -191,7 +191,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