From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753305AbcEIW1X (ORCPT ); Mon, 9 May 2016 18:27:23 -0400 Received: from mail-vk0-f68.google.com ([209.85.213.68]:35920 "EHLO mail-vk0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751658AbcEIW1W (ORCPT ); Mon, 9 May 2016 18:27:22 -0400 MIME-Version: 1.0 In-Reply-To: References: <1462825332-10505-1-git-send-email-keescook@chromium.org> <1462825332-10505-2-git-send-email-keescook@chromium.org> Date: Mon, 9 May 2016 15:27:21 -0700 X-Google-Sender-Auth: kv0QUiuM1h3ZnSzsZyMezeVQFso Message-ID: Subject: Re: [PATCH v7 1/9] x86/KASLR: Initialize mapping_info every time From: Yinghai Lu To: Kees Cook Cc: Ingo Molnar , Borislav Petkov , Baoquan He , Ingo Molnar , "H. Peter Anvin" , Borislav Petkov , Vivek Goyal , Andy Lutomirski , lasse.collin@tukaani.org, Andrew Morton , Dave Young , "kernel-hardening@lists.openwall.com" , LKML Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 9, 2016 at 3:23 PM, Yinghai Lu wrote: > On Mon, May 9, 2016 at 3:01 PM, Yinghai Lu wrote: >> Still should be assigned once, and should be done in >> prepare_level4(). --- by may need different name for that ? >> >> The exact reason to have assigning in functions. >> >> pgt_data address could be changed during kernel relocation. >> so can not assigned during compiling time. > > Something like: > > -/* > - * Mapping information structure passed to kernel_ident_mapping_init(). > - * Since this never changes, there's no reason to repeatedly fill it > - * in on the stack when calling add_identity_map(). > - */ > -static struct x86_mapping_info mapping_info = { > - .alloc_pgt_page = alloc_pgt_page, > - .context = &pgt_data, > - .pmd_flag = __PAGE_KERNEL_LARGE_EXEC, > -}; > +static struct x86_mapping_info mapping_info; > > /* > * Adds the specified range to what will become the new identity mappings. > @@ -110,8 +101,14 @@ void add_identity_map(unsigned long start, > unsigned long size) > unsigned long end = start + size; > > /* Make sure we have a top level page table ready to use. */ > - if (!level4p) > + if (!level4p) { > + /* need to set once during run time */ > + mapping_info.alloc_pgt_page = alloc_pgt_page; > + mapping_info.context = &pgt_data; > + mapping_info.pmd_flag = __PAGE_KERNEL_LARGE_EXEC; > + > prepare_level4(); > + } > > /* Align boundary to 2M. */ > start = round_down(start, PMD_SIZE); It would be better if Ingo could fold the change to https://git.kernel.org/cgit/linux/kernel/git/tip/tip.git/patch/?id=3a94707d7a7bb1eb82acae5fbc035247dd1ba8a5 x86/KASLR: Build identity mappings on demand As it happens to the last commit in tip/x86/boot. Thanks Yinghai