Message ID | c85903a7cfad37d14a7e5a4df9fc7119a3669fb3.1689130310.git.houwenlong.hwl@antgroup.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp889287vqm; Tue, 11 Jul 2023 20:41:27 -0700 (PDT) X-Google-Smtp-Source: APBJJlHHg75XtMUpe3rOiV4c/7sEvyzcdd6r710IhPjuT8WnKPGUG/G/zSbgg+bFSjNq6cNc3jBu X-Received: by 2002:a17:907:8186:b0:983:ba44:48af with SMTP id iy6-20020a170907818600b00983ba4448afmr15404297ejc.53.1689133286762; Tue, 11 Jul 2023 20:41:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689133286; cv=none; d=google.com; s=arc-20160816; b=x57oO57Rr2j45ETHMaJxihX1pKhL4OkadAuuYc/mS0/88AyTA4WL+VeibnHht62kFg Joz+HTxHKVuyyxBpTboqw3+A49DairN9zV6zThrB8FLJ/ANICyQ605N9SWZTN+XVKBe/ MiwDNymSR4E00GNWWLqP8Imk3Wv6A2CLpw1sRgDWtYcYe6uME9HWnY5D4h5WdMjXQi5e yd8fEzfFq3kGurAPFYsRS6YhQBzPckBfupiCUucPZlXWMGe47yfO/Tk3Rjklz0KJKpEk 4rXgSCe2Bd6VvtpfFj+1l/xnOY4/gewiPiBp7WCu8VEvJBMiRS++4GZv4fuAayLCBEMc UE/g== 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; bh=gqqTT4QCfa6L3lWH/ZJ9TDK+7cjlkDZowSBlDkgFYzo=; fh=H+xol+m9/22gljVAiQKilKMt6BHHgyiL3H+/V9q01Lk=; b=vUOzc0/pBMX7OBmlVzRi3BnbgkRm4zmA+cFUT+Rq4hcDHaMVjje33nf/Km5h2DA/9c vqvbfoB3nOVm3Houz2r3hwwjcjMw+5qWFaceJPeOlOSwwwxqTDO5a/Ybh8f7u9IT8dXO h/ybwzi4Rq7Sfy7CyTZ6UWfcIB8HL+E8/L6J/iTA+toGoGWbSXxam8BWfHnAwr53vwIs MknHN8Ls+MhGGhta0snrfJiGwVnEHOW75fq8lWsvas6IA00/SPAHOMkbU5Y7S4rbMT6+ 95V8UJB2Ot5FRbjM5FS/g6aSm4YQ8asgngFLz2lFXgMpzIow+9SB4zp7bKfQ1vXPMjnD 6csg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=antgroup.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p2-20020a170906140200b009591dd6c71esi3168518ejc.896.2023.07.11.20.41.01; Tue, 11 Jul 2023 20:41:26 -0700 (PDT) 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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=antgroup.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230254AbjGLDbY (ORCPT <rfc822;gnulinuxfreebsd@gmail.com> + 99 others); Tue, 11 Jul 2023 23:31:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229843AbjGLDbU (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 11 Jul 2023 23:31:20 -0400 Received: from out0-201.mail.aliyun.com (out0-201.mail.aliyun.com [140.205.0.201]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97704E5F for <linux-kernel@vger.kernel.org>; Tue, 11 Jul 2023 20:31:19 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018047206;MF=houwenlong.hwl@antgroup.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---.TrdHwby_1689132672; Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.TrdHwby_1689132672) by smtp.aliyun-inc.com; Wed, 12 Jul 2023 11:31:13 +0800 From: "Hou Wenlong" <houwenlong.hwl@antgroup.com> To: linux-kernel@vger.kernel.org Cc: "Lai Jiangshan" <jiangshan.ljs@antgroup.com>, "Hou Wenlong" <houwenlong.hwl@antgroup.com>, "Thomas Gleixner" <tglx@linutronix.de>, "Ingo Molnar" <mingo@redhat.com>, "Borislav Petkov" <bp@alien8.de>, "Dave Hansen" <dave.hansen@linux.intel.com>, " =?utf-8?q?maintainer=3AX86_A?= =?utf-8?q?RCHITECTURE_32-BIT_AND_64-BIT?= " <x86@kernel.org>, "H. Peter Anvin" <hpa@zytor.com>, "Josh Poimboeuf" <jpoimboe@kernel.org>, "Anshuman Khandual" <anshuman.khandual@arm.com>, "Mike Rapoport" <rppt@kernel.org>, "Pasha Tatashin" <pasha.tatashin@soleen.com> Subject: [PATCH RFC 1/7] x86/head/64: Mark startup_gdt and startup_gdt_descr as __initdata Date: Wed, 12 Jul 2023 11:30:05 +0800 Message-Id: <c85903a7cfad37d14a7e5a4df9fc7119a3669fb3.1689130310.git.houwenlong.hwl@antgroup.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <cover.1689130310.git.houwenlong.hwl@antgroup.com> References: <cover.1689130310.git.houwenlong.hwl@antgroup.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771184625265233636 X-GMAIL-MSGID: 1771184625265233636 |
Series |
[RFC,1/7] x86/head/64: Mark startup_gdt and startup_gdt_descr as __initdata
|
|
Commit Message
Hou Wenlong
July 12, 2023, 3:30 a.m. UTC
As startup_gdt and startup_gdt_descr are only used in booting, make them
as __initdata to allow them to be freed after boot.
Signed-off-by: Hou Wenlong <houwenlong.hwl@antgroup.com>
---
arch/x86/kernel/head64.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Comments
* Hou Wenlong <houwenlong.hwl@antgroup.com> wrote: > As startup_gdt and startup_gdt_descr are only used in booting, make them > as __initdata to allow them to be freed after boot. > > Signed-off-by: Hou Wenlong <houwenlong.hwl@antgroup.com> > --- > arch/x86/kernel/head64.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c > index 49f7629b17f7..dd357807ffb5 100644 > --- a/arch/x86/kernel/head64.c > +++ b/arch/x86/kernel/head64.c > @@ -69,7 +69,7 @@ EXPORT_SYMBOL(vmemmap_base); > /* > * GDT used on the boot CPU before switching to virtual addresses. > */ > -static struct desc_struct startup_gdt[GDT_ENTRIES] = { > +static struct desc_struct startup_gdt[GDT_ENTRIES] __initdata = { > [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff), > [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff), > [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff), > @@ -79,7 +79,7 @@ static struct desc_struct startup_gdt[GDT_ENTRIES] = { > * Address needs to be set at runtime because it references the startup_gdt > * while the kernel still uses a direct mapping. > */ > -static struct desc_ptr startup_gdt_descr = { > +static struct desc_ptr startup_gdt_descr __initdata = { > .size = sizeof(startup_gdt), > .address = 0, Yeah, so I think this and patch #1 are independently useful of the PIE feature, and I merged them into tip:x86/boot for a v6.7 merge. Mind re-sending any other patches for x86 that can be merged? For example patch #6 looks good too, but was mixed up a bit with a previous PIE-enablement patch. Moving the __head definition to a header should also probably done as a separate patch, followed by the widening of its use. Thanks, Ingo
On Mon, Oct 16, 2023 at 07:57:06PM +0800, Ingo Molnar wrote: > > * Hou Wenlong <houwenlong.hwl@antgroup.com> wrote: > > > As startup_gdt and startup_gdt_descr are only used in booting, make them > > as __initdata to allow them to be freed after boot. > > > > Signed-off-by: Hou Wenlong <houwenlong.hwl@antgroup.com> > > --- > > arch/x86/kernel/head64.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c > > index 49f7629b17f7..dd357807ffb5 100644 > > --- a/arch/x86/kernel/head64.c > > +++ b/arch/x86/kernel/head64.c > > @@ -69,7 +69,7 @@ EXPORT_SYMBOL(vmemmap_base); > > /* > > * GDT used on the boot CPU before switching to virtual addresses. > > */ > > -static struct desc_struct startup_gdt[GDT_ENTRIES] = { > > +static struct desc_struct startup_gdt[GDT_ENTRIES] __initdata = { > > [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff), > > [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff), > > [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff), > > @@ -79,7 +79,7 @@ static struct desc_struct startup_gdt[GDT_ENTRIES] = { > > * Address needs to be set at runtime because it references the startup_gdt > > * while the kernel still uses a direct mapping. > > */ > > -static struct desc_ptr startup_gdt_descr = { > > +static struct desc_ptr startup_gdt_descr __initdata = { > > .size = sizeof(startup_gdt), > > .address = 0, > > Yeah, so I think this and patch #1 are independently useful of the PIE > feature, and I merged them into tip:x86/boot for a v6.7 merge. > > Mind re-sending any other patches for x86 that can be merged? For example > patch #6 looks good too, but was mixed up a bit with a previous > PIE-enablement patch. Moving the __head definition to a header should also > probably done as a separate patch, followed by the widening of its use. > Hi Ingo, I have sent patch #6 separately for x86. Do you have any ideas about building the head code as PIE? Should I resend the patchset for the PIE feature? Thanks! > Thanks, > > Ingo
* Hou Wenlong <houwenlong.hwl@antgroup.com> wrote: > Hi Ingo, > > I have sent patch #6 separately for x86. Do you have any ideas about > building the head code as PIE? Should I resend the patchset for the PIE > feature? So I had a brief look, and despite reading 0/43 it was unclear to me what the precise advantages of building as PIE are. Ie. could you please outline: - *Exactly* how much PIE based KASLR randomization would gain us in terms of randomization granularity and effective number of randomization bits, compared to the current status quo? - How is code generation changed at the instruction level - how does kernel size change and what are the micro-advantages/disadvantages? - Are there any other advantages/motivation than improving KASLR? Ie. before asking us to apply ~50 patches and add a whole new build mode and the maintainance overhead to support it into infinity and beyond, could you please offer a better list of pros and cons? Thanks, Ingo
On October 17, 2023 6:02:27 AM PDT, Ingo Molnar <mingo@kernel.org> wrote: > >* Hou Wenlong <houwenlong.hwl@antgroup.com> wrote: > >> Hi Ingo, >> >> I have sent patch #6 separately for x86. Do you have any ideas about >> building the head code as PIE? Should I resend the patchset for the PIE >> feature? > >So I had a brief look, and despite reading 0/43 it was unclear to me what >the precise advantages of building as PIE are. > >Ie. could you please outline: > > - *Exactly* how much PIE based KASLR randomization would gain us in terms > of randomization granularity and effective number of randomization bits, > compared to the current status quo? > > - How is code generation changed at the instruction level - how does > kernel size change and what are the micro-advantages/disadvantages? > > - Are there any other advantages/motivation than improving KASLR? > >Ie. before asking us to apply ~50 patches and add a whole new build mode >and the maintainance overhead to support it into infinity and beyond, could >you please offer a better list of pros and cons? > >Thanks, > > Ingo If the goal is better KASLR, then what we really should spend time on was Kristen Accardi's fgKASLR patches, which not only exponentially(!) increases the randomization entrophy but also *actually* avoids the "one leak and it's over" problem. However, she gave up on it because she got no interest, despite working code.
On Tue, Oct 17, 2023 at 09:02:27PM +0800, Ingo Molnar wrote: > > * Hou Wenlong <houwenlong.hwl@antgroup.com> wrote: > > > Hi Ingo, > > > > I have sent patch #6 separately for x86. Do you have any ideas about > > building the head code as PIE? Should I resend the patchset for the PIE > > feature? > > So I had a brief look, and despite reading 0/43 it was unclear to me what > the precise advantages of building as PIE are. > > Ie. could you please outline: > > - *Exactly* how much PIE based KASLR randomization would gain us in terms > of randomization granularity and effective number of randomization bits, > compared to the current status quo? > > - How is code generation changed at the instruction level - how does > kernel size change and what are the micro-advantages/disadvantages? > > - Are there any other advantages/motivation than improving KASLR? > > Ie. before asking us to apply ~50 patches and add a whole new build mode > and the maintainance overhead to support it into infinity and beyond, could > you please offer a better list of pros and cons? > Hi Ingo, Thanks for your reply. I apologize for the confusion. Waht I meant to say is that I would like to resend the remaining part of this patchset that building the head code as PIE. As mentioned in the cover letter, building the head code as PIE can eliminate certain workarounds such as the "fixup_pointer" in head64.c and the inline assembly in mem_encrypt_identity.c. This is considered a cleanup. However, it is still necessary to use inline assembly to obtain the absolute symbol value during the pagetable building process. Regarding the entire PIE patchset, I agree that it is complex and there are no obvious use cases apart from improving KASLR. As mentioned earlier, the primary motivation is to increase the flexibility of the kernel image address rather than prioritizing security, enabling the kernel image to be placed at any virtual address. The use cases in our internal environment are specific and not widespread, so we do not feel an urgent need to push it forward at the moment. Thanks! > Thanks, > > Ingo
* H. Peter Anvin <hpa@zytor.com> wrote: > If the goal is better KASLR, then what we really should spend time on was > Kristen Accardi's fgKASLR patches, which not only exponentially(!) > increases the randomization entrophy but also *actually* avoids the "one > leak and it's over" problem. Agreed. Going by this version of function-granularity KASLR from 3 years ago: https://lwn.net/Articles/824307/ https://lwn.net/ml/linux-kernel/20200623172327.5701-1-kristen@linux.intel.com/ The fgKASLR feature looks entirely viable to me. Back then I presumed it would get iterated beyond v3, and then it fell off my radar. :-/ If Kristen or someone else would like to dust this off & submit a fresh version it would be much appreciated! Thanks, Ingo
On Wed, Oct 18, 2023 at 01:45:40PM +0200, Ingo Molnar wrote: > > * H. Peter Anvin <hpa@zytor.com> wrote: > > > If the goal is better KASLR, then what we really should spend time on was > > Kristen Accardi's fgKASLR patches, which not only exponentially(!) > > increases the randomization entrophy but also *actually* avoids the "one > > leak and it's over" problem. > > Agreed. Going by this version of function-granularity KASLR from 3 years > ago: > > https://lwn.net/Articles/824307/ > https://lwn.net/ml/linux-kernel/20200623172327.5701-1-kristen@linux.intel.com/ > > The fgKASLR feature looks entirely viable to me. Back then I presumed it > would get iterated beyond v3, and then it fell off my radar. :-/ > > If Kristen or someone else would like to dust this off & submit a fresh > version it would be much appreciated! That actually got up to v10: https://lkml.kernel.org/lkml/20220209185752.1226407-1-alexandr.lobakin@intel.com Anyway, I'm also very interested in this. If nobody else is working on it then I could give it a try. BTW I've wondered if translation-unit granularity would be more preferable than function granularity due to improved i-cache locality and (possibly) easier livepatch compatibility.
diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index 49f7629b17f7..dd357807ffb5 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -69,7 +69,7 @@ EXPORT_SYMBOL(vmemmap_base); /* * GDT used on the boot CPU before switching to virtual addresses. */ -static struct desc_struct startup_gdt[GDT_ENTRIES] = { +static struct desc_struct startup_gdt[GDT_ENTRIES] __initdata = { [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff), [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff), [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff), @@ -79,7 +79,7 @@ static struct desc_struct startup_gdt[GDT_ENTRIES] = { * Address needs to be set at runtime because it references the startup_gdt * while the kernel still uses a direct mapping. */ -static struct desc_ptr startup_gdt_descr = { +static struct desc_ptr startup_gdt_descr __initdata = { .size = sizeof(startup_gdt), .address = 0, };