linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tom Lendacky <thomas.lendacky@amd.com>
To: Arvind Sankar <nivedita@alum.mit.edu>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	"H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
	Kees Cook <keescook@chromium.org>,
	Mauro Rossi <issor.oruam@gmail.com>, Michael Matz <matz@suse.de>
Subject: Re: [PATCH v3] x86/vmlinux: Fix vmlinux.lds.S with pre-2.23 binutils
Date: Mon, 13 Jan 2020 15:46:04 -0600	[thread overview]
Message-ID: <3e46154d-6e5e-1c16-90fe-f2c5daa44b60@amd.com> (raw)
In-Reply-To: <20200113195337.604646-1-nivedita@alum.mit.edu>

On 1/13/20 1:53 PM, Arvind Sankar wrote:
> Prior to binutils-2.23, ld treats the location counter as absolute if
> used outside an output section definition. From version 2.23 onwards,
> the location counter is treated as relative to an adjacent output
> section (usually the previous one, unless there isn't one or the
> location counter has been assigned to previously, in which case the next
> one).
> 
> The result is that a symbol definition in the linker script, such as
> 	_etext = .;
> that appears outside an output section definition makes _etext an
> absolute symbol prior to binutils-2.23 and a relative symbol from
> version 2.23 onwards. So when using a 2.21 or 2.22 vintage linker, the
> build fails with
> 	Invalid absolute R_X86_64_32S relocation: _etext
> for x86-64, and a similar message with R_386_32 for x86-32.
> 
> This can be reproduced with the official 2.21.1 and 2.22 binutils
> releases.
> 
> Commit b907693883fd ("x86/vmlinux: Actually use _etext for the end of
> the text segment") moved _etext out of the .text section to place it
> after the exception table, however since commit f0d7ee17d57c
> ("x86/vmlinux: Move EXCEPTION_TABLE to RO_DATA segment") this is no
> longer needed. Move _etext back inside .text to make it relative even
> with older linkers.
> 
> Commit c603a309cc75 ("x86/mm: Identify the end of the kernel area to be
> reserved") defines __end_of_kernel_reserve using the location counter
> outside an output section definition. Use __bss_stop instead of the
> location counter for the definition to make it relative with older
> linkers.
> 
> Fixes: b907693883fd ("x86/vmlinux: Actually use _etext for the end of the text segment")
> Fixes: c603a309cc75 ("x86/mm: Identify the end of the kernel area to be reserved")
> Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
> ---
> v3: Modify vmlinux.lds.S instead of adding more workarounds to tools/relocs.c
> 
>  arch/x86/kernel/vmlinux.lds.S | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
> index 3a1a819da137..bad4e22384dc 100644
> --- a/arch/x86/kernel/vmlinux.lds.S
> +++ b/arch/x86/kernel/vmlinux.lds.S
> @@ -144,10 +144,12 @@ SECTIONS
>  		*(.text.__x86.indirect_thunk)
>  		__indirect_thunk_end = .;
>  #endif
> +
> +		/* End of text section */
> +		_etext = .;
>  	} :text =0xcccc
>  
> -	/* End of text section, which should occupy whole number of pages */
> -	_etext = .;
> +	/* .text should occupy whole number of pages */
>  	. = ALIGN(PAGE_SIZE);
>  
>  	X86_ALIGN_RODATA_BEGIN
> @@ -372,7 +374,7 @@ SECTIONS
>  	 * explicitly reserved using memblock_reserve() or it will be discarded
>  	 * and treated as available memory.
>  	 */
> -	__end_of_kernel_reserve = .;
> +	__end_of_kernel_reserve = __bss_stop;

The only thing I worry about is if someone inserts a section between
the bss section and here and doesn't update this value.

Thanks,
Tom

>  
>  	. = ALIGN(PAGE_SIZE);
>  	.brk : AT(ADDR(.brk) - LOAD_OFFSET) {
> 

  reply	other threads:[~2020-01-13 21:46 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-10 20:23 [PATCH] x86/tools/relocs: Add _etext and __end_of_kernel_reserve to S_REL Arvind Sankar
2020-01-10 20:38 ` Borislav Petkov
2020-01-10 20:50   ` Arvind Sankar
2020-01-10 21:50     ` [PATCH v2] " Arvind Sankar
2020-01-10 21:52       ` Arvind Sankar
2020-01-11 13:02     ` [PATCH] " Borislav Petkov
2020-01-11 17:20       ` Arvind Sankar
2020-01-11 17:32         ` Arvind Sankar
2020-01-13 13:43         ` Borislav Petkov
2020-01-13 16:13           ` Arvind Sankar
2020-01-13 16:38             ` Borislav Petkov
2020-01-13 17:59               ` Arvind Sankar
2020-01-13 18:08                 ` Borislav Petkov
2020-01-14  4:17                   ` Arvind Sankar
2020-01-14 11:25                     ` Borislav Petkov
2020-01-14 16:32                       ` Arvind Sankar
2020-01-14  4:08               ` Arvind Sankar
2020-01-13 19:53             ` [PATCH v3] x86/vmlinux: Fix vmlinux.lds.S with pre-2.23 binutils Arvind Sankar
2020-01-13 21:46               ` Tom Lendacky [this message]
2020-01-13 23:06                 ` Arvind Sankar
2020-01-14  1:53               ` Kees Cook
2020-01-14  1:57                 ` H. Peter Anvin
2020-01-14  2:20                   ` Kees Cook
2020-01-14  3:58                   ` Arvind Sankar
2020-01-14  5:05                     ` hpa
2020-01-14 16:51                 ` Borislav Petkov
2020-01-14 21:50                   ` hpa
2020-01-15  0:21                   ` Arvind Sankar
2020-01-15 12:24                     ` Borislav Petkov
2020-03-16 16:02                       ` [PATCH] Documentation/changes: Raise minimum supported binutils version to 2.23 Borislav Petkov
2020-03-16 20:54                         ` Kees Cook
2020-03-23 20:44                         ` Jason A. Donenfeld
2020-03-23 20:51                           ` Kees Cook
2020-03-23 21:11                             ` Jason A. Donenfeld
2020-03-25 17:33                               ` David Laight
2020-03-24  9:02                             ` Masahiro Yamada
2020-03-24  9:12                               ` Masahiro Yamada
2020-03-24 15:38                                 ` Arvind Sankar
2020-03-24 17:31                                   ` Masahiro Yamada
2020-03-24 21:36                                     ` Arvind Sankar
2020-03-24  9:14                               ` Borislav Petkov
2020-03-24  9:40                                 ` Masahiro Yamada
2020-03-24 12:00                                   ` Borislav Petkov
2020-03-24 16:22                                 ` Jason A. Donenfeld
2020-03-24 16:28                                   ` Borislav Petkov
2020-03-24 16:37                                     ` Linus Torvalds
2020-03-24 16:48                                       ` Borislav Petkov
2020-03-24 21:42                                         ` Arvind Sankar
2020-03-24 22:01                                           ` Arvind Sankar
2020-03-24 22:14                                           ` Linus Torvalds
2020-03-24 23:49                                             ` Arvind Sankar
2020-03-24 17:53                                       ` Kees Cook
2020-03-23 20:50                         ` [PATCH] Documentation/changes: Raise minimum supported binutilsa " Nick Desaulniers
2020-01-13 23:38       ` [PATCH] x86/tools/relocs: Add _etext and __end_of_kernel_reserve to S_REL Arvind Sankar
2020-01-10 20:56   ` Kees Cook
     [not found]     ` <CAEQFVGa4fksPRtiLtBckSgbJY_JSHr07hoy5+5w-pAYym16YVg@mail.gmail.com>
2020-01-11 19:40       ` Fwd: " Mauro Rossi

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=3e46154d-6e5e-1c16-90fe-f2c5daa44b60@amd.com \
    --to=thomas.lendacky@amd.com \
    --cc=bp@alien8.de \
    --cc=hpa@zytor.com \
    --cc=issor.oruam@gmail.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matz@suse.de \
    --cc=mingo@redhat.com \
    --cc=nivedita@alum.mit.edu \
    --cc=tglx@linutronix.de \
    --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).