linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arvind Sankar <nivedita@alum.mit.edu>
To: Borislav Petkov <bp@alien8.de>
Cc: Arvind Sankar <nivedita@alum.mit.edu>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	x86@kernel.org, linux-kernel@vger.kernel.org,
	Kees Cook <keescook@chromium.org>,
	Thomas Lendacky <Thomas.Lendacky@amd.com>,
	Michael Matz <matz@suse.de>
Subject: Re: [PATCH] x86/tools/relocs: Add _etext and __end_of_kernel_reserve to S_REL
Date: Mon, 13 Jan 2020 11:13:10 -0500	[thread overview]
Message-ID: <20200113161310.GA191743@rani.riverdale.lan> (raw)
In-Reply-To: <20200113134306.GF13310@zn.tnic>

On Mon, Jan 13, 2020 at 02:43:06PM +0100, Borislav Petkov wrote:
> On Sat, Jan 11, 2020 at 12:20:48PM -0500, Arvind Sankar wrote:
> > I'm not sure if that's the same issue. The root cause for the one I
> > reported is described in more detail in [1], and the change that makes
> > these symbols no longer absolute is commit d2667025dd30 in binutils-gdb
> > (sourceware.org seems to be taking too long to respond from here so I
> > don't have the web link).
> 
> My binutils guy says that the proper fix should be to make those two
> symbols section-relative, i.e., move _etext at the end of the .text
> section and so on.
> 
> Please check whether this fixes the build issue too because if it does,
> it would be The RightThing(tm).

According to Kees in [1] commit 392bef709659 ("x86/build: Move _etext to
actual end of .text"), keeping _etext inside the .text section was
incorrect in some situations with clang. That commit was later reverted
because it broke old toolchains, and the new commit that did the same
thing commit b907693883fd ("x86/vmlinux: Actually use _etext for the end
of the text segment") does not mention that rationale.

Kees, is it still required to keep _etext out of .text, or can it be
moved back in? If it has to remain outside, 
	_etext = _stext + SIZEOF(.text);
seems to leave _etext as a relative symbol, even though from the
binutils documentation I'd have expected SIZEOF(.text), as a number, to
be treated as an absolute expression outside an output section. Could
you check if that would work for your case?

The __end_of_kernel_reserve can be made relative by just assigning it
__bss_stop instead of the location counter.

I will note that the purpose of S_REL in relocs.c was originally to
handle exactly this case of symbols defined outside output sections:

/*
 * These symbols are known to be relative, even if the linker marks them
 * as absolute (typically defined outside any section in the linker script.)
 */
        [S_REL] =

> 
> > I'm running gentoo, but building the kernel using binutils-2.21.1
> > compiled from the GNU source tarball, and gcc-4.6.4 again compiled from
> > source. (It's not something I normally need but I was investigating
> > something else to see what exactly happens with older toolchains.)
> > 
> > I used the below to compile the kernel (I added in
> > readelf/objdump/objcopy just now, and it does build until the relocs
> > error). The config is x86-64 defconfig with CONFIG_RETPOLINE overridden
> > to n (since gcc 4.6.4 doesn't support retpoline).
> > 
> > make O=~/kernel64 -j LD=~/old/bin/ld AS=~/old/bin/as READELF=~/old/bin/readelf \
> > 	OBJDUMP=~/old/bin/objdump OBJCOPY=~/old/bin/objcopy GCC=~/old/bin/gcc
> 
> Make this all part of your commit message because it explains in detail
> how exactly you've triggered it so that anyone else reading this can
> reproduce her/himself.

How to reproduce is just "build with old binutils". I don't see it's
reasonable to include a tutorial on how to build the kernel with a
toolchain that's not installed in the default PATH, as part of the commit
message.

> 
> Thx.
> 
> -- 
> Regards/Gruss,
>     Boris.
> 
> https://people.kernel.org/tglx/notes-about-netiquette

[1] x86/build: Move _etext to actual end of .text

When building x86 with Clang LTO and CFI, CFI jump regions are
automatically added to the end of the .text section late in linking. As a
result, the _etext position was being labelled before the appended jump
regions, causing confusion about where the boundaries of the executable
region actually are in the running kernel, and broke at least the fault
injection code. This moves the _etext mark to outside (and immediately
after) the .text area, as it already the case on other architectures
(e.g. arm64, arm).

  reply	other threads:[~2020-01-13 16:13 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 [this message]
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
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=20200113161310.GA191743@rani.riverdale.lan \
    --to=nivedita@alum.mit.edu \
    --cc=Thomas.Lendacky@amd.com \
    --cc=bp@alien8.de \
    --cc=hpa@zytor.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matz@suse.de \
    --cc=mingo@redhat.com \
    --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).