Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7AA37C61DA4 for ; Sat, 11 Mar 2023 14:31:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229875AbjCKObv (ORCPT ); Sat, 11 Mar 2023 09:31:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229685AbjCKObs (ORCPT ); Sat, 11 Mar 2023 09:31:48 -0500 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 613739BA7C; Sat, 11 Mar 2023 06:31:47 -0800 (PST) Received: from mail.ispras.ru (unknown [83.149.199.84]) by mail.ispras.ru (Postfix) with ESMTPSA id D497E40737A9; Sat, 11 Mar 2023 14:31:45 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru D497E40737A9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1678545105; bh=46KXPcpWJeBRUYX0NYuLLZ+/sY00b3jrDW80RjYVVhc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=RQsYjIN4R5qJ290VufJajvqheM7crhZ6HrWbqSIV0anVBDZ/CnRhIbd+tKYQiyTWz 2iJYqUiFXeWs2TWPlRVGzbIFQ9ihaCXysHvaagdtDd7wH+vgaSVRDQ7S7afFBmVlWG LbEyAzW4LqgDXW+bT7pPVVyL7t+h586TuML4VMc8= MIME-Version: 1.0 Date: Sat, 11 Mar 2023 17:31:45 +0300 From: Evgeniy Baskov To: Ard Biesheuvel Cc: Borislav Petkov , Andy Lutomirski , Dave Hansen , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , Alexey Khoroshilov , Peter Jones , "Limonciello, Mario" , joeyli , lvc-project@linuxtesting.org, x86@kernel.org, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v4 02/26] x86/build: Remove RWX sections and align on 4KB In-Reply-To: References: <721b5c42e0e79d307d5bcb08f9c8402f5067ded0.1671098103.git.baskov@ispras.ru> User-Agent: Roundcube Webmail/1.4.4 Message-ID: <94de9f7c8a26d98be778619d4104d232@ispras.ru> X-Sender: baskov@ispras.ru Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023-03-10 17:45, Ard Biesheuvel wrote: > On Thu, 15 Dec 2022 at 13:38, Evgeniy Baskov wrote: >> >> Avoid creating sections simultaneously writable and readable >> to prepare for W^X implementation. Align sections on page size (4KB) >> to >> allow protecting them in the page tables. >> >> Split init code form ".init" segment into separate R_X ".inittext" >> segment and make ".init" segment non-executable. >> >> Also add these segments to x86_32 architecture for consistency. >> Currently paging is disabled in x86_32 in compressed kernel, so >> protection is not applied anyways, but .init code was incorrectly >> placed in non-executable ".data" segment. This should not change >> anything meaningful in memory layout now, but might be required in >> case >> memory protection will also be implemented in compressed kernel for >> x86_32. >> >> Tested-by: Mario Limonciello >> Tested-by: Peter Jones >> Signed-off-by: Evgeniy Baskov > > Reviewed-by: Ard Biesheuvel > > One nit: the series modifies both the decompressor linker script and > the core kernel one, so please make it very explicit in the commit log > which one is being modified, and why it matters for this particular > context. > Thanks! I'll amend the log. > >> --- >> arch/x86/kernel/vmlinux.lds.S | 15 ++++++++------- >> 1 file changed, 8 insertions(+), 7 deletions(-) >> >> diff --git a/arch/x86/kernel/vmlinux.lds.S >> b/arch/x86/kernel/vmlinux.lds.S >> index 2e0ee14229bf..2e56d694c491 100644 >> --- a/arch/x86/kernel/vmlinux.lds.S >> +++ b/arch/x86/kernel/vmlinux.lds.S >> @@ -102,12 +102,11 @@ jiffies = jiffies_64; >> PHDRS { >> text PT_LOAD FLAGS(5); /* R_E */ >> data PT_LOAD FLAGS(6); /* RW_ */ >> -#ifdef CONFIG_X86_64 >> -#ifdef CONFIG_SMP >> +#if defined(CONFIG_X86_64) && defined(CONFIG_SMP) >> percpu PT_LOAD FLAGS(6); /* RW_ */ >> #endif >> - init PT_LOAD FLAGS(7); /* RWE */ >> -#endif >> + inittext PT_LOAD FLAGS(5); /* R_E */ >> + init PT_LOAD FLAGS(6); /* RW_ */ >> note PT_NOTE FLAGS(0); /* ___ */ >> } >> >> @@ -227,9 +226,10 @@ SECTIONS >> #endif >> >> INIT_TEXT_SECTION(PAGE_SIZE) >> -#ifdef CONFIG_X86_64 >> - :init >> -#endif >> + :inittext >> + >> + . = ALIGN(PAGE_SIZE); >> + >> >> /* >> * Section for code used exclusively before alternatives are >> run. All >> @@ -241,6 +241,7 @@ SECTIONS >> .altinstr_aux : AT(ADDR(.altinstr_aux) - LOAD_OFFSET) { >> *(.altinstr_aux) >> } >> + :init >> >> INIT_DATA_SECTION(16) >> >> -- >> 2.37.4 >>