lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20160506085300.GE24044@pd.tnic>
Date:	Fri, 6 May 2016 10:53:01 +0200
From:	Borislav Petkov <bp@...en8.de>
To:	Ingo Molnar <mingo@...nel.org>, Kees Cook <keescook@...omium.org>
Cc:	torvalds@...ux-foundation.org, hpa@...or.com, dyoung@...hat.com,
	tglx@...utronix.de, keescook@...omium.org, luto@...nel.org,
	peterz@...radead.org, dvlasenk@...hat.com,
	linux-kernel@...r.kernel.org, brgerst@...il.com,
	luto@...capital.net, akpm@...ux-foundation.org, bhe@...hat.com,
	mingo@...nel.org, yinghai@...nel.org, vgoyal@...hat.com,
	linux-tip-commits@...r.kernel.org
Subject: Re: [tip:x86/boot] x86/boot: Clean up pointer casting

On Fri, May 06, 2016 at 12:45:41AM -0700, tip-bot for Kees Cook wrote:
> Commit-ID:  2bc1cd39fa9f659956b25e500422e700a6cd4ec3
> Gitweb:     http://git.kernel.org/tip/2bc1cd39fa9f659956b25e500422e700a6cd4ec3
> Author:     Kees Cook <keescook@...omium.org>
> AuthorDate: Thu, 5 May 2016 15:13:46 -0700
> Committer:  Ingo Molnar <mingo@...nel.org>
> CommitDate: Fri, 6 May 2016 09:00:59 +0200
> 
> x86/boot: Clean up pointer casting

...

> diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
> index f1818d9..2072d82 100644
> --- a/arch/x86/boot/compressed/kaslr.c
> +++ b/arch/x86/boot/compressed/kaslr.c
> @@ -305,12 +305,21 @@ static unsigned long find_random_addr(unsigned long minimum,
>  	return slots_fetch_random();
>  }
>  
> -unsigned char *choose_random_location(unsigned char *input,
> +unsigned char *choose_random_location(unsigned char *input_ptr,
>  				      unsigned long input_size,
> -				      unsigned char *output,
> +				      unsigned char *output_ptr,
>  				      unsigned long output_size)
>  {
> -	unsigned long choice = (unsigned long)output;
> +	/*
> +	 * 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;

This can be simplified even further:

---
From: Borislav Petkov <bp@...e.de>
Date: Fri, 6 May 2016 10:43:21 +0200
Subject: [PATCH] x86/boot: Simplify pointer casting in
 choose_random_location()

Pass them down as unsigned long directly and get rid of more casting and
assignments.

Signed-off-by: Borislav Petkov <bp@...e.de>
Cc: Kees Cook <keescook@...omium.org>
---
 arch/x86/boot/compressed/kaslr.c | 17 ++++++-----------
 arch/x86/boot/compressed/misc.c  |  3 ++-
 arch/x86/boot/compressed/misc.h  |  8 ++++----
 3 files changed, 12 insertions(+), 16 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..1c793463328b 100644
--- a/arch/x86/boot/compressed/misc.h
+++ b/arch/x86/boot/compressed/misc.h
@@ -67,17 +67,17 @@ 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;
-- 
2.7.3

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ