Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752147AbcDUNcF (ORCPT ); Thu, 21 Apr 2016 09:32:05 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:17372 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751988AbcDUNcC (ORCPT ); Thu, 21 Apr 2016 09:32:02 -0400 Subject: Re: [RFC v1 3/4] x86, boot: Implement ASLR for kernel memory sections (x86_64) To: Thomas Garnier , "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Andy Lutomirski , Dmitry Vyukov , Paolo Bonzini , Dan Williams , Kees Cook , Stephen Smalley , Seth Jennings , Kefeng Wang , Jonathan Corbet , Matt Fleming , Toshi Kani , Alexander Kuleshov , Alexander Popov , Joerg Roedel , Dave Young , Baoquan He , Dave Hansen , Mark Salter References: <1460757793-59020-1-git-send-email-thgarnie@google.com> <1460757793-59020-4-git-send-email-thgarnie@google.com> Cc: x86@kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, gthelen@google.com, kernel-hardening@lists.openwall.com From: Boris Ostrovsky Message-ID: <5718D5F0.8010501@oracle.com> Date: Thu, 21 Apr 2016 09:30:24 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <1460757793-59020-4-git-send-email-thgarnie@google.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Source-IP: userv0021.oracle.com [156.151.31.71] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 964 Lines: 30 On 04/15/2016 06:03 PM, Thomas Garnier wrote: > +void __init kernel_randomize_memory(void) > +{ > + size_t i; > + unsigned long addr = memory_rand_start; > + unsigned long padding, rand, mem_tb; > + struct rnd_state rnd_st; > + unsigned long remain_padding = memory_rand_end - memory_rand_start; > + > + if (!kaslr_enabled()) > + return; > + > + /* Take the additional space when Xen is not active. */ > + if (!xen_domain()) > + page_offset_base -= __XEN_SPACE; This should be !xen_pv_domain(). Xen HVM guests are no different from bare metal as far as address ranges are concerned. (Technically it's probably !xen_pv_domain() && !xen_pvh_domain() but we can ignore PVH for now since it is being replaced by an HVM-type guest) Having said that, I am not sure I understand why page_offset_base is shifted. I thought 0xffff800000000000 - 0xffff87ffffffffff is not supposed to be used by anyone, whether we are running under a hypervisor or not. -boris