From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758607AbcEFLu0 (ORCPT ); Fri, 6 May 2016 07:50:26 -0400 Received: from mail.skyhub.de ([78.46.96.112]:59670 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758274AbcEFLuW (ORCPT ); Fri, 6 May 2016 07:50:22 -0400 Date: Fri, 6 May 2016 13:50:15 +0200 From: Borislav Petkov To: Ingo Molnar Cc: Kees Cook , torvalds@linux-foundation.org, hpa@zytor.com, dyoung@redhat.com, tglx@linutronix.de, luto@kernel.org, peterz@infradead.org, dvlasenk@redhat.com, linux-kernel@vger.kernel.org, brgerst@gmail.com, luto@amacapital.net, akpm@linux-foundation.org, bhe@redhat.com, yinghai@kernel.org, vgoyal@redhat.com, linux-tip-commits@vger.kernel.org Subject: [PATCH -v1.1] x86/boot: Simplify pointer casting in choose_random_location() Message-ID: <20160506115015.GI24044@pd.tnic> References: <1462486436-3707-2-git-send-email-keescook@chromium.org> <20160506085300.GE24044@pd.tnic> <20160506103619.GA8998@gmail.com> <20160506104438.GF24044@pd.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20160506104438.GF24044@pd.tnic> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Borislav Petkov Pass them down as unsigned long directly and get rid of more casting and assignments. Signed-off-by: Borislav Petkov Cc: Kees Cook --- arch/x86/boot/compressed/kaslr.c | 17 ++++++----------- arch/x86/boot/compressed/misc.c | 3 ++- arch/x86/boot/compressed/misc.h | 10 +++++----- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c index 6392f0041b8a..a49f48317dad 100644 --- a/arch/x86/boot/compressed/kaslr.c +++ b/arch/x86/boot/compressed/kaslr.c @@ -350,20 +350,15 @@ static unsigned long find_random_addr(unsigned long minimum, return slots_fetch_random(); } -unsigned char *choose_random_location(unsigned char *input_ptr, +/* + * Since this function examines addresses much more numerically, + * it takes the input and output pointers as unsigned long. + */ +unsigned char *choose_random_location(unsigned long input, unsigned long input_size, - unsigned char *output_ptr, + unsigned long output, unsigned long output_size) { - /* - * The caller of choose_random_location() uses unsigned char * for - * buffer pointers since it performs decompression, elf parsing, etc. - * Since this code examines addresses much more numerically, - * unsigned long is used internally here. Instead of sprinkling - * more casts into extract_kernel, do them here and at return. - */ - unsigned long input = (unsigned long)input_ptr; - unsigned long output = (unsigned long)output_ptr; unsigned long choice = output; unsigned long random_addr; diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c index 9536d778149e..f14db4e21654 100644 --- a/arch/x86/boot/compressed/misc.c +++ b/arch/x86/boot/compressed/misc.c @@ -366,7 +366,8 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap, * the entire decompressed kernel plus relocation table, or the * entire decompressed kernel plus .bss and .brk sections. */ - output = choose_random_location(input_data, input_len, output, + output = choose_random_location((unsigned long)input_data, input_len, + (unsigned long)output, max(output_len, kernel_total_size)); /* Validate memory location choices. */ diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h index 1f23d022d241..0112005a3f23 100644 --- a/arch/x86/boot/compressed/misc.h +++ b/arch/x86/boot/compressed/misc.h @@ -67,20 +67,20 @@ int cmdline_find_option_bool(const char *option); #if CONFIG_RANDOMIZE_BASE /* kaslr.c */ -unsigned char *choose_random_location(unsigned char *input_ptr, +unsigned char *choose_random_location(unsigned long input_ptr, unsigned long input_size, - unsigned char *output_ptr, + unsigned long output_ptr, unsigned long output_size); /* cpuflags.c */ bool has_cpuflag(int flag); #else static inline -unsigned char *choose_random_location(unsigned char *input_ptr, +unsigned char *choose_random_location(unsigned long input_ptr, unsigned long input_size, - unsigned char *output_ptr, + unsigned long output_ptr, unsigned long output_size) { - return output_ptr; + return (unsigned char *)output_ptr; } #endif -- 2.7.3 -- Regards/Gruss, Boris. ECO tip #101: Trim your mails when you reply.