From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934523AbdCXIqc (ORCPT ); Fri, 24 Mar 2017 04:46:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41308 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751935AbdCXIqU (ORCPT ); Fri, 24 Mar 2017 04:46:20 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A272061D2D Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dyoung@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A272061D2D Date: Fri, 24 Mar 2017 16:46:09 +0800 From: Dave Young To: Baoquan He Cc: Ingo Molnar , linux-kernel@vger.kernel.org, stable@vger.kernel.org, Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, linux-efi@vger.kernel.org, Thomas Garnier , Kees Cook , Borislav Petkov , Andrew Morton , Masahiro Yamada , Bhupesh Sharma Subject: Re: [PATCH v2] x86/mm/KASLR: EFI region is mistakenly included into KASLR VA space for randomization Message-ID: <20170324084609.GA6807@dhcp-128-65.nay.redhat.com> References: <1490331592-31860-1-git-send-email-bhe@redhat.com> <20170324080833.GA15200@gmail.com> <20170324083451.GC30442@x1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170324083451.GC30442@x1> User-Agent: Mutt/1.7.1 (2016-10-04) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 24 Mar 2017 08:46:19 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/24/17 at 04:34pm, Baoquan He wrote: > On 03/24/17 at 09:08am, Ingo Molnar wrote: > > > Cc: #4.8+ > > > Signed-off-by: Baoquan He > > > Acked-by: Dave Young > > > Reviewed-by: Bhupesh Sharma > > > Acked-by: Thomas Garnier > > > Cc: Thomas Gleixner > > > Cc: Ingo Molnar > > > Cc: "H. Peter Anvin" > > > Cc: x86@kernel.org > > > Cc: linux-efi@vger.kernel.org > > > Cc: Thomas Garnier > > > Cc: Kees Cook > > > Cc: Borislav Petkov > > > Cc: Andrew Morton > > > Cc: Masahiro Yamada > > > Cc: Dave Young > > > Cc: Bhupesh Sharma > > > > So I applied this kexec fix and extended the changelog to clearly show why this > > fix matters in practice. > > I thought it only impacts kexec, but Dave thought it will impact 1st > kenrel either. Yes, I think no need to mention kexec, it is a general issue. First, the space is reserved for EFI, so kernel should not use it for kaslr. Second, EFI page tables sync the low kernel page tables into its own page tables, if others use this space for non-EFI then those part will be missing. arch/x86/platform/efi/efi_64.c efi_sync_low_kernel_mappings() is syncing kernel page tables to efi's. >>From the function comment below: Add low kernel mappings for passing arguments to EFI functions. Suppose some arguments use kaslr randomized address which is within efi ranges then we will hit bugs. But we do not see actual bug reports in real world yet. This is found during patch review. Anyway, since this area is EFI reserved, no reason to add it to kaslr pool. > > > > Also, to make sure I understood it correctly: these addresses are all dynamic on > > 64-bit kernels, i.e. we are establishing and then tearing down these page tables > > around EFI calls, and they are 'normally' not present at all, right? > > The EFI region is reserved for EFI runtime services virtual mapping, the > original purpose is to preserve this region so that they can be reused > by kexec-ed kernel. This was introduced by Boris in commit d2f7cbe7b26a7 > ("x86/efi: Runtime services virtual mapping"). > > So it will be establishing and stay there. According to Dave's telling, > efi will still fetch efi variables or time/date by runtime service by > switching the efi pgd and entering into efi mode. And then switch back > to normal OS. Not sure if I am right for efi part in 1st kernel. For 2nd > kernel, if want to reuse the them, the efi region has to be kept. > > Thanks > Baoquan Thanks Dave From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dave Young Subject: Re: [PATCH v2] x86/mm/KASLR: EFI region is mistakenly included into KASLR VA space for randomization Date: Fri, 24 Mar 2017 16:46:09 +0800 Message-ID: <20170324084609.GA6807@dhcp-128-65.nay.redhat.com> References: <1490331592-31860-1-git-send-email-bhe@redhat.com> <20170324080833.GA15200@gmail.com> <20170324083451.GC30442@x1> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: <20170324083451.GC30442@x1> Sender: linux-efi-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Baoquan He Cc: Ingo Molnar , linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org, linux-efi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Thomas Garnier , Kees Cook , Borislav Petkov , Andrew Morton , Masahiro Yamada , Bhupesh Sharma List-Id: linux-efi@vger.kernel.org On 03/24/17 at 04:34pm, Baoquan He wrote: > On 03/24/17 at 09:08am, Ingo Molnar wrote: > > > Cc: #4.8+ > > > Signed-off-by: Baoquan He > > > Acked-by: Dave Young > > > Reviewed-by: Bhupesh Sharma > > > Acked-by: Thomas Garnier > > > Cc: Thomas Gleixner > > > Cc: Ingo Molnar > > > Cc: "H. Peter Anvin" > > > Cc: x86-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org > > > Cc: linux-efi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org > > > Cc: Thomas Garnier > > > Cc: Kees Cook > > > Cc: Borislav Petkov > > > Cc: Andrew Morton > > > Cc: Masahiro Yamada > > > Cc: Dave Young > > > Cc: Bhupesh Sharma > > > > So I applied this kexec fix and extended the changelog to clearly show why this > > fix matters in practice. > > I thought it only impacts kexec, but Dave thought it will impact 1st > kenrel either. Yes, I think no need to mention kexec, it is a general issue. First, the space is reserved for EFI, so kernel should not use it for kaslr. Second, EFI page tables sync the low kernel page tables into its own page tables, if others use this space for non-EFI then those part will be missing. arch/x86/platform/efi/efi_64.c efi_sync_low_kernel_mappings() is syncing kernel page tables to efi's. >>From the function comment below: Add low kernel mappings for passing arguments to EFI functions. Suppose some arguments use kaslr randomized address which is within efi ranges then we will hit bugs. But we do not see actual bug reports in real world yet. This is found during patch review. Anyway, since this area is EFI reserved, no reason to add it to kaslr pool. > > > > Also, to make sure I understood it correctly: these addresses are all dynamic on > > 64-bit kernels, i.e. we are establishing and then tearing down these page tables > > around EFI calls, and they are 'normally' not present at all, right? > > The EFI region is reserved for EFI runtime services virtual mapping, the > original purpose is to preserve this region so that they can be reused > by kexec-ed kernel. This was introduced by Boris in commit d2f7cbe7b26a7 > ("x86/efi: Runtime services virtual mapping"). > > So it will be establishing and stay there. According to Dave's telling, > efi will still fetch efi variables or time/date by runtime service by > switching the efi pgd and entering into efi mode. And then switch back > to normal OS. Not sure if I am right for efi part in 1st kernel. For 2nd > kernel, if want to reuse the them, the efi region has to be kept. > > Thanks > Baoquan Thanks Dave