* [PATCH] x86/KASLR: move aligning of minimal address to choose_random_location()
@ 2018-01-04 9:54 Alexander Kuleshov
2018-01-04 10:03 ` Baoquan He
0 siblings, 1 reply; 3+ messages in thread
From: Alexander Kuleshov @ 2018-01-04 9:54 UTC (permalink / raw)
To: Thomas Gleixner
Cc: Ingo Molnar, x86, Baoquan He, Kees Cook, Dave Jiang,
Naoya Horiguchi, Greg Kroah-Hartman, linux-kernel,
Alexander Kuleshov
we align minimal possible address during randomization to CONFIG_PHYSICAL_ALIGN
two times: during getting of random physical address and virtual
address (only for x86_64).
Let's move this to choose_random_location() to not duplicate code in
find_random_virt_addr() and find_random_phys_addr().
Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
---
arch/x86/boot/compressed/kaslr.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
index 8199a6187251..8c93e399fdfd 100644
--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -673,9 +673,6 @@ static unsigned long find_random_phys_addr(unsigned long minimum,
return 0;
}
- /* Make sure minimum is aligned. */
- minimum = ALIGN(minimum, CONFIG_PHYSICAL_ALIGN);
-
if (process_efi_entries(minimum, image_size))
return slots_fetch_random();
@@ -688,8 +685,6 @@ static unsigned long find_random_virt_addr(unsigned long minimum,
{
unsigned long slots, random_addr;
- /* Make sure minimum is aligned. */
- minimum = ALIGN(minimum, CONFIG_PHYSICAL_ALIGN);
/* Align image_size for easy slot calculations. */
image_size = ALIGN(image_size, CONFIG_PHYSICAL_ALIGN);
@@ -738,6 +733,9 @@ void choose_random_location(unsigned long input,
*/
min_addr = min(*output, 512UL << 20);
+ /* Make sure minimum is aligned. */
+ min_addr = ALIGN(min_addr, CONFIG_PHYSICAL_ALIGN);
+
/* Walk available memory entries to find a random address. */
random_addr = find_random_phys_addr(min_addr, output_size);
if (!random_addr) {
--
2.14.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] x86/KASLR: move aligning of minimal address to choose_random_location()
2018-01-04 9:54 [PATCH] x86/KASLR: move aligning of minimal address to choose_random_location() Alexander Kuleshov
@ 2018-01-04 10:03 ` Baoquan He
2018-01-04 10:04 ` Alexander Kuleshov
0 siblings, 1 reply; 3+ messages in thread
From: Baoquan He @ 2018-01-04 10:03 UTC (permalink / raw)
To: Alexander Kuleshov
Cc: Thomas Gleixner, Ingo Molnar, x86, Kees Cook, Dave Jiang,
Naoya Horiguchi, Greg Kroah-Hartman, linux-kernel
On 01/04/18 at 03:54pm, Alexander Kuleshov wrote:
> we align minimal possible address during randomization to CONFIG_PHYSICAL_ALIGN
> two times: during getting of random physical address and virtual
> address (only for x86_64).
>
> Let's move this to choose_random_location() to not duplicate code in
> find_random_virt_addr() and find_random_phys_addr().
>
> Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
> ---
> arch/x86/boot/compressed/kaslr.c | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
> index 8199a6187251..8c93e399fdfd 100644
> --- a/arch/x86/boot/compressed/kaslr.c
> +++ b/arch/x86/boot/compressed/kaslr.c
> @@ -673,9 +673,6 @@ static unsigned long find_random_phys_addr(unsigned long minimum,
> return 0;
> }
>
> - /* Make sure minimum is aligned. */
> - minimum = ALIGN(minimum, CONFIG_PHYSICAL_ALIGN);
> -
> if (process_efi_entries(minimum, image_size))
> return slots_fetch_random();
>
> @@ -688,8 +685,6 @@ static unsigned long find_random_virt_addr(unsigned long minimum,
> {
> unsigned long slots, random_addr;
>
> - /* Make sure minimum is aligned. */
> - minimum = ALIGN(minimum, CONFIG_PHYSICAL_ALIGN);
> /* Align image_size for easy slot calculations. */
> image_size = ALIGN(image_size, CONFIG_PHYSICAL_ALIGN);
>
> @@ -738,6 +733,9 @@ void choose_random_location(unsigned long input,
> */
> min_addr = min(*output, 512UL << 20);
>
> + /* Make sure minimum is aligned. */
> + min_addr = ALIGN(min_addr, CONFIG_PHYSICAL_ALIGN);
Hmm, the min_addr is passed to find_random_phys_addr(), but not to
find_random_virt_addr().
> +
> /* Walk available memory entries to find a random address. */
> random_addr = find_random_phys_addr(min_addr, output_size);
> if (!random_addr) {
> --
> 2.14.3
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] x86/KASLR: move aligning of minimal address to choose_random_location()
2018-01-04 10:03 ` Baoquan He
@ 2018-01-04 10:04 ` Alexander Kuleshov
0 siblings, 0 replies; 3+ messages in thread
From: Alexander Kuleshov @ 2018-01-04 10:04 UTC (permalink / raw)
To: Baoquan He
Cc: Alexander Kuleshov, Thomas Gleixner, Ingo Molnar, x86, Kees Cook,
Dave Jiang, Naoya Horiguchi, Greg Kroah-Hartman, linux-kernel
On 01-04-18, Baoquan He wrote:
> On 01/04/18 at 03:54pm, Alexander Kuleshov wrote:
> > we align minimal possible address during randomization to CONFIG_PHYSICAL_ALIGN
> > two times: during getting of random physical address and virtual
> > address (only for x86_64).
> >
> > Let's move this to choose_random_location() to not duplicate code in
> > find_random_virt_addr() and find_random_phys_addr().
> >
> > Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
> > ---
> > arch/x86/boot/compressed/kaslr.c | 8 +++-----
> > 1 file changed, 3 insertions(+), 5 deletions(-)
> >
> > diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
> > index 8199a6187251..8c93e399fdfd 100644
> > --- a/arch/x86/boot/compressed/kaslr.c
> > +++ b/arch/x86/boot/compressed/kaslr.c
> > @@ -673,9 +673,6 @@ static unsigned long find_random_phys_addr(unsigned long minimum,
> > return 0;
> > }
> >
> > - /* Make sure minimum is aligned. */
> > - minimum = ALIGN(minimum, CONFIG_PHYSICAL_ALIGN);
> > -
> > if (process_efi_entries(minimum, image_size))
> > return slots_fetch_random();
> >
> > @@ -688,8 +685,6 @@ static unsigned long find_random_virt_addr(unsigned long minimum,
> > {
> > unsigned long slots, random_addr;
> >
> > - /* Make sure minimum is aligned. */
> > - minimum = ALIGN(minimum, CONFIG_PHYSICAL_ALIGN);
> > /* Align image_size for easy slot calculations. */
> > image_size = ALIGN(image_size, CONFIG_PHYSICAL_ALIGN);
> >
> > @@ -738,6 +733,9 @@ void choose_random_location(unsigned long input,
> > */
> > min_addr = min(*output, 512UL << 20);
> >
> > + /* Make sure minimum is aligned. */
> > + min_addr = ALIGN(min_addr, CONFIG_PHYSICAL_ALIGN);
>
> Hmm, the min_addr is passed to find_random_phys_addr(), but not to
> find_random_virt_addr().
ah, yes, sorry for noise then
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-01-04 10:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-04 9:54 [PATCH] x86/KASLR: move aligning of minimal address to choose_random_location() Alexander Kuleshov
2018-01-04 10:03 ` Baoquan He
2018-01-04 10:04 ` Alexander Kuleshov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox