objtool: Add relocation check for alternative sections
authorJosh Poimboeuf <jpoimboe@redhat.com>
Mon, 10 Feb 2020 18:32:40 +0000 (12:32 -0600)
committerBorislav Petkov <bp@suse.de>
Tue, 11 Feb 2020 12:39:52 +0000 (13:39 +0100)
commitdc4197236c20e761f2007c641afd193f81a00a74
treef1cbb0b2024c73a6faba15a7d000b47b1d1ea8f1
parenta22961409c02b93ffa7ed78f67fb57a1ba6c787d
objtool: Add relocation check for alternative sections

Relocations in alternative code can be dangerous, because the code is
copy/pasted to the text section after relocations have been resolved,
which can corrupt PC-relative addresses.

However, relocations might be acceptable in some cases, depending on the
architecture.  For example, the x86 alternatives code manually fixes up
the target addresses for PC-relative jumps and calls.

So disallow relocations in alternative code, except where the x86 arch
code allows it.

This code may need to be tweaked for other arches when objtool gets
support for them.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Julien Thierry <jthierry@redhat.com>
Link: https://lkml.kernel.org/r/7b90b68d093311e4e8f6b504a9e1c758fd7e0002.1581359535.git.jpoimboe@redhat.com
tools/objtool/check.c