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@suse.de> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Kees Cook <keescook@chromium.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: akpm@linux-foundation.org Cc: bhe@redhat.com Cc: dyoung@redhat.com Cc: linux-tip-commits@vger.kernel.org Cc: luto@kernel.org Cc: vgoyal@redhat.com Cc: yinghai@kernel.org Link: http://lkml.kernel.org/r/20160506115015.GI24044@pd.tnic Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:
parent
9dc1969c24
commit
549f90db68
@ -350,20 +350,15 @@ static unsigned long find_random_addr(unsigned long minimum,
|
|||||||
return slots_fetch_random();
|
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 long input_size,
|
||||||
unsigned char *output_ptr,
|
unsigned long output,
|
||||||
unsigned long output_size)
|
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 choice = output;
|
||||||
unsigned long random_addr;
|
unsigned long random_addr;
|
||||||
|
|
||||||
|
@ -366,7 +366,8 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap,
|
|||||||
* the entire decompressed kernel plus relocation table, or the
|
* the entire decompressed kernel plus relocation table, or the
|
||||||
* entire decompressed kernel plus .bss and .brk sections.
|
* 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));
|
max(output_len, kernel_total_size));
|
||||||
|
|
||||||
/* Validate memory location choices. */
|
/* Validate memory location choices. */
|
||||||
|
@ -67,20 +67,20 @@ int cmdline_find_option_bool(const char *option);
|
|||||||
|
|
||||||
#if CONFIG_RANDOMIZE_BASE
|
#if CONFIG_RANDOMIZE_BASE
|
||||||
/* kaslr.c */
|
/* 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 long input_size,
|
||||||
unsigned char *output_ptr,
|
unsigned long output_ptr,
|
||||||
unsigned long output_size);
|
unsigned long output_size);
|
||||||
/* cpuflags.c */
|
/* cpuflags.c */
|
||||||
bool has_cpuflag(int flag);
|
bool has_cpuflag(int flag);
|
||||||
#else
|
#else
|
||||||
static inline
|
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 long input_size,
|
||||||
unsigned char *output_ptr,
|
unsigned long output_ptr,
|
||||||
unsigned long output_size)
|
unsigned long output_size)
|
||||||
{
|
{
|
||||||
return output_ptr;
|
return (unsigned char *)output_ptr;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user