x86/entry, ubsan, objtool: Whitelist __ubsan_handle_*()
authorPeter Zijlstra <peterz@infradead.org>
Wed, 3 Jun 2020 18:09:06 +0000 (20:09 +0200)
committerPeter Zijlstra <peterz@infradead.org>
Mon, 15 Jun 2020 12:10:09 +0000 (14:10 +0200)
The UBSAN instrumentation only inserts external CALLs when things go
'BAD', much like WARN(). So treat them similar to WARN()s for noinstr,
that is: allow them, at the risk of taking the machine down, to get
their message out.

Suggested-by: Marco Elver <elver@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Marco Elver <elver@google.com>
include/linux/compiler_types.h
tools/objtool/check.c

index 85b8d2370c244410e6888c53733fdd0d5caf2d73..14513e88b7e00137a741b8f3c62756e7b01aebf8 100644 (file)
@@ -199,7 +199,7 @@ struct ftrace_likely_data {
 /* Section for code which can't be instrumented at all */
 #define noinstr                                                                \
        noinline notrace __attribute((__section__(".noinstr.text")))    \
-       __no_kcsan __no_sanitize_address __no_sanitize_undefined
+       __no_kcsan __no_sanitize_address
 
 #endif /* __KERNEL__ */
 
index 5fbb90a80d2399b0cfcfbbbdddfbd688b494db69..3e214f879adae3354d7b33063012fc2f68e0efe5 100644 (file)
@@ -2190,10 +2190,36 @@ static inline const char *call_dest_name(struct instruction *insn)
        return "{dynamic}";
 }
 
+static inline bool noinstr_call_dest(struct symbol *func)
+{
+       /*
+        * We can't deal with indirect function calls at present;
+        * assume they're instrumented.
+        */
+       if (!func)
+               return false;
+
+       /*
+        * If the symbol is from a noinstr section; we good.
+        */
+       if (func->sec->noinstr)
+               return true;
+
+       /*
+        * The __ubsan_handle_*() calls are like WARN(), they only happen when
+        * something 'BAD' happened. At the risk of taking the machine down,
+        * let them proceed to get the message out.
+        */
+       if (!strncmp(func->name, "__ubsan_handle_", 15))
+               return true;
+
+       return false;
+}
+
 static int validate_call(struct instruction *insn, struct insn_state *state)
 {
        if (state->noinstr && state->instr <= 0 &&
-           (!insn->call_dest || !insn->call_dest->sec->noinstr)) {
+           !noinstr_call_dest(insn->call_dest)) {
                WARN_FUNC("call to %s() leaves .noinstr.text section",
                                insn->sec, insn->offset, call_dest_name(insn));
                return 1;