Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752593AbeADKEz (ORCPT + 1 other); Thu, 4 Jan 2018 05:04:55 -0500 Received: from mail-lf0-f65.google.com ([209.85.215.65]:41554 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751872AbeADKEx (ORCPT ); Thu, 4 Jan 2018 05:04:53 -0500 X-Google-Smtp-Source: ACJfBotxKNuhYjQaonD337UqRXoop1A91lgN5VSCKKknkhCy5rFSMKkgMRpoJoBxcO9DH5teCGzebQ== Date: Thu, 4 Jan 2018 16:04:48 +0600 From: Alexander Kuleshov To: Baoquan He Cc: Alexander Kuleshov , Thomas Gleixner , Ingo Molnar , x86@kernel.org, Kees Cook , Dave Jiang , Naoya Horiguchi , Greg Kroah-Hartman , linux-kernel@vger.kernel.org Subject: Re: [PATCH] x86/KASLR: move aligning of minimal address to choose_random_location() Message-ID: <20180104100448.GA2586@localhost.localdomain> References: <20180104095421.10606-1-kuleshovmail@gmail.com> <20180104100308.GB7235@x1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180104100308.GB7235@x1> X-Operating-System: Linux X-Date: Thu Jan 4 14:15:14 +06 2018 User-Agent: Mutt/1.6.0-rc0 ((null)) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: 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 > > --- > > 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