[tip:x86/boot] x86/boot: Simplify pointer casting in choose_random_location()

2016-05-07 Thread tip-bot for Borislav Petkov
Commit-ID:  549f90db68c9f8e21a40ec21c8047441984e7164
Gitweb: http://git.kernel.org/tip/549f90db68c9f8e21a40ec21c8047441984e7164
Author: Borislav Petkov 
AuthorDate: Fri, 6 May 2016 13:50:15 +0200
Committer:  Ingo Molnar 
CommitDate: Sat, 7 May 2016 07:38:38 +0200

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 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: a...@linux-foundation.org
Cc: b...@redhat.com
Cc: dyo...@redhat.com
Cc: linux-tip-comm...@vger.kernel.org
Cc: l...@kernel.org
Cc: vgo...@redhat.com
Cc: ying...@kernel.org
Link: http://lkml.kernel.org/r/20160506115015.gi24...@pd.tnic
Signed-off-by: Ingo Molnar 
---
 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 6392f00..ff12277 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 9536d77..f14db4e 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 1f23d02..0112005a 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
 


[tip:x86/boot] x86/boot: Simplify pointer casting in choose_random_location()

2016-05-07 Thread tip-bot for Borislav Petkov
Commit-ID:  549f90db68c9f8e21a40ec21c8047441984e7164
Gitweb: http://git.kernel.org/tip/549f90db68c9f8e21a40ec21c8047441984e7164
Author: Borislav Petkov 
AuthorDate: Fri, 6 May 2016 13:50:15 +0200
Committer:  Ingo Molnar 
CommitDate: Sat, 7 May 2016 07:38:38 +0200

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 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: a...@linux-foundation.org
Cc: b...@redhat.com
Cc: dyo...@redhat.com
Cc: linux-tip-comm...@vger.kernel.org
Cc: l...@kernel.org
Cc: vgo...@redhat.com
Cc: ying...@kernel.org
Link: http://lkml.kernel.org/r/20160506115015.gi24...@pd.tnic
Signed-off-by: Ingo Molnar 
---
 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 6392f00..ff12277 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 9536d77..f14db4e 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 1f23d02..0112005a 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