linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: x86@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org,
	ebiggers@google.com, herbert@gondor.apana.org.au,
	Jason@zx2c4.com, Josh Poimboeuf <jpoimboe@redhat.com>
Subject: [PATCH 4/2] objtool: Fix SLS validation for KCOV tail-call replacement
Date: Thu, 24 Mar 2022 00:07:12 +0100	[thread overview]
Message-ID: <20220323230712.GA8939@worktop.programming.kicks-ass.net> (raw)
In-Reply-To: <20220322114809.381992456@infradead.org>


Since not all compilers have a function attribute to disable KCOV
instrumentation, objtool can rewrite KCOV instrumentation in noinstr
functions as per commit:

  f56dae88a81f ("objtool: Handle __sanitize_cov*() tail calls")

However, this has subtle interaction with the SLS validation from
commit:

  1cc1e4c8aab4 ("objtool: Add straight-line-speculation validation")

In that when a tail-call instrucion is replaced with a RET an
additional INT3 instruction is also written, but is not represented in
the decoded instruction stream.

This then leads to false positive missing INT3 objtool warnings in
noinstr code.

Instead of adding additional struct instruction objects, mark the RET
instruction with retpoline_safe to suppress the warning (since we know
there really is an INT3).

Fixes: 1cc1e4c8aab4 ("objtool: Add straight-line-speculation validation")
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 tools/objtool/check.c |   43 +++++++++++++++++++++++++++++--------------
 1 file changed, 29 insertions(+), 14 deletions(-)

--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -1090,6 +1099,17 @@ static void annotate_call_site(struct ob
 			               : arch_nop_insn(insn->len));
 
 		insn->type = sibling ? INSN_RETURN : INSN_NOP;
+
+		if (sibling) {
+			/*
+			 * We've replaced the tail-call JMP insn by two new
+			 * insn: RET; INT3, except we only have a single struct
+			 * insn here. Mark it retpoline_safe to avoid the SLS
+			 * warning, instead of adding another insn.
+			 */
+			insn->retpoline_safe = true;
+		}
+
 		return;
 	}
 

  parent reply	other threads:[~2022-03-23 23:07 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-22 11:48 [PATCH 0/2] crypto objtool cleanup Peter Zijlstra
2022-03-22 11:48 ` [PATCH 1/2] x86/chacha20: Avoid spurious jumps to other functions Peter Zijlstra
2022-03-22 12:18   ` Martin Willi
2022-03-25  4:22   ` Herbert Xu
2022-03-22 11:48 ` [PATCH 2/2] objtool: Fix IBT tail-call detection Peter Zijlstra
2022-04-05  8:29   ` [tip: x86/urgent] " tip-bot2 for Peter Zijlstra
2022-03-23 23:05 ` [PATCH 3/2] x86/poly1305: Fixup SLS Peter Zijlstra
2022-03-25  4:22   ` Herbert Xu
2022-03-23 23:07 ` Peter Zijlstra [this message]
2022-04-05  8:29   ` [tip: x86/urgent] objtool: Fix SLS validation for kcov tail-call replacement tip-bot2 for Peter Zijlstra
2022-03-25 12:30 ` [PATCH 5/2] x86/sm3: Fixup SLS Peter Zijlstra
2022-03-30  5:19   ` Herbert Xu

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=20220323230712.GA8939@worktop.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=Jason@zx2c4.com \
    --cc=ebiggers@google.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=jpoimboe@redhat.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).