From: Julien Thierry <jthierry@redhat.com>
To: Josh Poimboeuf <jpoimboe@redhat.com>, x86@kernel.org
Cc: linux-kernel@vger.kernel.org, Borislav Petkov <bp@suse.de>,
Peter Zijlstra <peterz@infradead.org>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH 3/3] objtool: Add relocation check for alternative sections
Date: Tue, 11 Feb 2020 08:16:01 +0000 [thread overview]
Message-ID: <1bc9dfd5-0652-c5e1-7ab2-cdd025edc01b@redhat.com> (raw)
In-Reply-To: <7b90b68d093311e4e8f6b504a9e1c758fd7e0002.1581359535.git.jpoimboe@redhat.com>
On 2/10/20 6:32 PM, Josh Poimboeuf wrote:
> 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>
> ---
> tools/objtool/check.c | 21 +++++++++++++++++++++
> 1 file changed, 21 insertions(+)
>
> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> index 5ea2ce7ed8a3..2d52a40e6cb9 100644
> --- a/tools/objtool/check.c
> +++ b/tools/objtool/check.c
> @@ -786,6 +786,27 @@ static int handle_group_alt(struct objtool_file *file,
> insn->ignore = orig_insn->ignore_alts;
> insn->func = orig_insn->func;
>
> + /*
> + * Since alternative replacement code is copy/pasted by the
> + * kernel after applying relocations, generally such code can't
> + * have relative-address relocation references to outside the
> + * .altinstr_replacement section, unless the arch's
> + * alternatives code can adjust the relative offsets
> + * accordingly.
> + *
> + * The x86 alternatives code adjusts the offsets only when it
> + * encounters a branch instruction at the very beginning of the
> + * replacement group.
Yes, arm64 is a bit more permissive regarding this although it does
disallow some patterns.
I guess once we introduce other archs there should be some function:
bool arch_validate_alt_insn(struct instruction *new, struct instruction
*new, struct special_alt *alt);
> + */
> + if ((insn->offset != special_alt->new_off ||
> + (insn->type != INSN_CALL && !is_static_jump(insn))) &&
> + find_rela_by_dest_range(insn->sec, insn->offset, insn->len)) {
> +
> + WARN_FUNC("unsupported relocation in alternatives section",
> + insn->sec, insn->offset);
> + return -1;
> + }
> +
> if (!is_static_jump(insn))
> continue;
>
>
Reviewed-by: Julien Thierry <jthierry@redhat.com>
Cheers,
--
Julien Thierry
next prev parent reply other threads:[~2020-02-11 8:16 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-10 18:32 [PATCH 0/3] objtool: Relocation sanity check for alternatives Josh Poimboeuf
2020-02-10 18:32 ` [PATCH 1/3] objtool: Fail the kernel build on fatal errors Josh Poimboeuf
2020-02-11 7:51 ` Julien Thierry
2020-02-11 12:47 ` [tip: core/objtool] " tip-bot2 for Josh Poimboeuf
2020-02-13 22:11 ` Josh Poimboeuf
2020-02-14 0:10 ` Thomas Gleixner
2020-02-14 17:57 ` Josh Poimboeuf
2020-02-19 22:43 ` Nick Desaulniers
2020-02-20 0:44 ` Philip Li
2020-02-20 19:09 ` Nick Desaulniers
2020-02-10 18:32 ` [PATCH 2/3] objtool: Add is_static_jump() helper Josh Poimboeuf
2020-02-11 7:52 ` Julien Thierry
2020-02-11 12:47 ` [tip: core/objtool] " tip-bot2 for Josh Poimboeuf
2020-02-10 18:32 ` [PATCH 3/3] objtool: Add relocation check for alternative sections Josh Poimboeuf
2020-02-11 1:51 ` Linus Torvalds
2020-02-11 8:47 ` Borislav Petkov
2020-02-11 8:16 ` Julien Thierry [this message]
2020-02-11 12:47 ` [tip: core/objtool] " tip-bot2 for Josh Poimboeuf
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=1bc9dfd5-0652-c5e1-7ab2-cdd025edc01b@redhat.com \
--to=jthierry@redhat.com \
--cc=bp@suse.de \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=torvalds@linux-foundation.org \
--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
Powered by JetHome