From: Kees Cook <keescook@chromium.org>
To: Kristen Carlson Accardi <kristen@linux.intel.com>
Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Arnd Bergmann <arnd@arndb.de>,
arjan@linux.intel.com, linux-kernel@vger.kernel.org,
kernel-hardening@lists.openwall.com, rick.p.edgecombe@intel.com,
Tony Luck <tony.luck@intel.com>,
linux-arch@vger.kernel.org
Subject: Re: [PATCH v2 5/9] x86: Make sure _etext includes function sections
Date: Thu, 21 May 2020 11:11:18 -0700 [thread overview]
Message-ID: <202005211109.4EE4DCBA3@keescook> (raw)
In-Reply-To: <20200521165641.15940-6-kristen@linux.intel.com>
On Thu, May 21, 2020 at 09:56:36AM -0700, Kristen Carlson Accardi wrote:
> When using -ffunction-sections to place each function in
> it's own text section so it can be randomized at load time, the
> linker considers these .text.* sections "orphaned sections", and
> will place them after the first similar section (.text). In order
> to accurately represent the end of the text section and the
> orphaned sections, _etext must be moved so that it is after both
> .text and .text.* The text size must also be calculated to
> include .text AND .text.*
>
> Signed-off-by: Kristen Carlson Accardi <kristen@linux.intel.com>
> Reviewed-by: Tony Luck <tony.luck@intel.com>
> Tested-by: Tony Luck <tony.luck@intel.com>
> ---
> arch/x86/kernel/vmlinux.lds.S | 18 +++++++++++++++++-
> include/asm-generic/vmlinux.lds.h | 2 +-
> 2 files changed, 18 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
> index 1bf7e312361f..044f7528a2f0 100644
> --- a/arch/x86/kernel/vmlinux.lds.S
> +++ b/arch/x86/kernel/vmlinux.lds.S
> @@ -147,8 +147,24 @@ SECTIONS
> #endif
> } :text =0xcccc
>
> - /* End of text section, which should occupy whole number of pages */
> +#ifdef CONFIG_FG_KASLR
> + /*
> + * -ffunction-sections creates .text.* sections, which are considered
> + * "orphan sections" and added after the first similar section (.text).
> + * Adding this ALIGN statement causes the address of _etext
> + * to be below that of all the .text.* orphaned sections
> + */
> + . = ALIGN(PAGE_SIZE);
> +#endif
> _etext = .;
> +
> + /*
> + * the size of the .text section is used to calculate the address
> + * range for orc lookups. If we just use SIZEOF(.text), we will
> + * miss all the .text.* sections. Calculate the size using _etext
> + * and _stext and save the value for later.
> + */
> + text_size = _etext - _stext;
> . = ALIGN(PAGE_SIZE);
I don't think there's any need for this #ifdef (nor the trailing ALIGN).
I think leave the comment to explain why the ALIGN is being moved before
the _etext.
A repeated ALIGN won't move the position:
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -147,9 +147,11 @@ SECTIONS
#endif
} :text =0xcccc
+ . = ALIGN(PAGE_SIZE);
/* End of text section, which should occupy whole number of * pages */
_etext = .;
. = ALIGN(PAGE_SIZE);
+ _ktext = .;
X86_ALIGN_RODATA_BEGIN
RO_DATA(PAGE_SIZE)
$ nm vmlinux | grep '_[ek]text'
ffffffff81e02000 R _etext
ffffffff81e02000 R _ktext
--
Kees Cook
next prev parent reply other threads:[~2020-05-21 18:11 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-21 16:56 [PATCH v2 0/9] Function Granular KASLR Kristen Carlson Accardi
2020-05-21 16:56 ` [PATCH v2 1/9] objtool: Do not assume order of parent/child functions Kristen Carlson Accardi
2020-05-21 16:56 ` [PATCH v2 2/9] x86: tools/relocs: Support >64K section headers Kristen Carlson Accardi
2020-05-21 16:56 ` [PATCH v2 3/9] x86/boot: Allow a "silent" kaslr random byte fetch Kristen Carlson Accardi
2020-05-21 16:56 ` [PATCH v2 4/9] x86: Makefile: Add build and config option for CONFIG_FG_KASLR Kristen Carlson Accardi
2020-05-21 20:00 ` Kees Cook
2020-05-21 16:56 ` [PATCH v2 5/9] x86: Make sure _etext includes function sections Kristen Carlson Accardi
2020-05-21 18:11 ` Kees Cook [this message]
2020-05-21 16:56 ` [PATCH v2 6/9] x86/tools: Add relative relocs for randomized functions Kristen Carlson Accardi
2020-05-21 19:54 ` Kees Cook
2020-05-21 16:56 ` [PATCH v2 7/9] x86: Add support for function granular KASLR Kristen Carlson Accardi
2020-05-21 21:08 ` Kees Cook
2020-05-21 21:42 ` Kristen Carlson Accardi
2020-06-04 17:27 ` Kristen Carlson Accardi
2020-06-04 22:37 ` Kees Cook
2020-05-21 16:56 ` [PATCH v2 8/9] kallsyms: Hide layout Kristen Carlson Accardi
2020-05-21 21:14 ` Kees Cook
2020-05-21 16:56 ` [PATCH v2 9/9] module: Reorder functions Kristen Carlson Accardi
2020-05-21 21:33 ` Kees Cook
2020-06-09 20:14 ` Kristen Carlson Accardi
2020-06-09 20:42 ` Kees Cook
2020-06-09 20:59 ` Kristen Carlson Accardi
2020-05-21 21:54 ` [PATCH v2 0/9] Function Granular KASLR Kees Cook
2020-05-21 22:26 ` Thomas Gleixner
2020-05-21 23:30 ` Kees Cook
2020-05-21 23:43 ` Thomas Gleixner
2020-05-21 23:44 ` Kristen Carlson Accardi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202005211109.4EE4DCBA3@keescook \
--to=keescook@chromium.org \
--cc=arjan@linux.intel.com \
--cc=arnd@arndb.de \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=kernel-hardening@lists.openwall.com \
--cc=kristen@linux.intel.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=rick.p.edgecombe@intel.com \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).