From patchwork Tue Nov 22 11:12:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evgeniy Baskov X-Patchwork-Id: 24273 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2137976wrr; Tue, 22 Nov 2022 03:15:57 -0800 (PST) X-Google-Smtp-Source: AA0mqf4ZwNDnLiH6nj5J7UWg5C4QxWJh5CPntqEgrTH/hGQOH4VUCga47uodoUJwDzM+Qjj/I/MS X-Received: by 2002:a17:906:3ad8:b0:7a8:dddc:7ec6 with SMTP id z24-20020a1709063ad800b007a8dddc7ec6mr19158315ejd.734.1669115757118; Tue, 22 Nov 2022 03:15:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669115757; cv=none; d=google.com; s=arc-20160816; b=VOHdj6yyIbHx0ufH/d0Od0llwnqdZpc3p68H+VS9YA9GrErwcqisviE15EAQXXSxDQ d235CG7nGeOpTxk3SthdLjY6LD8Ecatzy+hkLU90LPyDpUn4KICaa1Tp4qVc6VpERoSP rz7jgWHrFxSXS+J5QDRZACc0QAzOvjE4bDLSnUB+HjyiqX81HUGabVRpMbqJlHnP9y0C fXeuo7LS348iKnJqa6EcZcOqnPVdFga43cL4cdtoFm5jYr622j4MyD44OyS4qgUgyYpI CdNCLJc0o0rQoMpjrSjgIGNsf/oqLXOjGs3mvnFrDESHH+NaVBeSY9e4YOotssjycyMe w5KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=xEdZo96L/X/k5EK1tUjYWv8AfvCbFTfDMc/tPKn5ymE=; b=Ba+t7Q7TrlzKD8l/GZtxN0TS4b5EaE4TanMh0pBZDwKpDs7xoFQoSzO/DguhJtSDnN dHIwOAGRXkWA0wb4r8YRxKrGJeodBHRvRN51o0u80vgum8Z9BlQ5WQ/GfYPZ0mOv9mPw ctTosMqOo4CFMJvQtw3FU2qhFUuD5cblH70e+BO/9jPpFTWIeoRjAKMqOe7GRwkJ12Gb cnMmNVnvTA8c33aIvN36bINN0CHaQME4AhZj9X8V0ClyUJNx8PkPwK2QoiWwWVqqkkjr Oj/xQT2a3BYIufd4o4pSItufxDV80O0SUG837ZcxBxu5U4LGfGCL7Dz6rcN/V9RhB7gr VfZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=llCPffPp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d14-20020a50fe8e000000b00457137b2571si9990089edt.346.2022.11.22.03.15.33; Tue, 22 Nov 2022 03:15:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=llCPffPp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233120AbiKVLNG (ORCPT + 99 others); Tue, 22 Nov 2022 06:13:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232968AbiKVLMq (ORCPT ); Tue, 22 Nov 2022 06:12:46 -0500 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 834B3FFA; Tue, 22 Nov 2022 03:12:44 -0800 (PST) Received: from localhost.localdomain (unknown [83.149.199.65]) by mail.ispras.ru (Postfix) with ESMTPSA id 8F049419E9F3; Tue, 22 Nov 2022 11:12:40 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 8F049419E9F3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1669115560; bh=xEdZo96L/X/k5EK1tUjYWv8AfvCbFTfDMc/tPKn5ymE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=llCPffPp9XbdFvHbdQAmffv4PUcBa8H99ZDXMpKwLr15FmVaV3Tdh05sV4qZ7iy97 /UeGG/pFVrytjvXeAMngUpCObusBUhKT2AvWbMrobvGk7W45dqjdv+/GfcWs33Gg6T sgQo9X3pd5/ZET81Lsm9OMuS5jgHJiKI/HwF/pMw= From: Evgeniy Baskov To: Ard Biesheuvel Cc: Evgeniy Baskov , 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: [PATCH v3 02/24] x86/build: Remove RWX sections and align on 4KB Date: Tue, 22 Nov 2022 14:12:11 +0300 Message-Id: X-Mailer: git-send-email 2.37.4 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750194724569928252?= X-GMAIL-MSGID: =?utf-8?q?1750194724569928252?= 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 Signed-off-by: Evgeniy Baskov --- 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 15f29053cec4..6587e0201b50 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); /* ___ */ } @@ -226,9 +225,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 @@ -240,6 +240,7 @@ SECTIONS .altinstr_aux : AT(ADDR(.altinstr_aux) - LOAD_OFFSET) { *(.altinstr_aux) } + :init INIT_DATA_SECTION(16)