linux-stable/tools/objtool
Jann Horn b0b8e56b82 objtool: Permit __kasan_check_{read,write} under UACCESS
Building linux-next with JUMP_LABEL=n and KASAN=y, I got this objtool
warning:

arch/x86/lib/copy_mc.o: warning: objtool: copy_mc_to_user()+0x22: call to
__kasan_check_read() with UACCESS enabled

What happens here is that copy_mc_to_user() branches on a static key in a
UACCESS region:

        __uaccess_begin();
        if (static_branch_unlikely(&copy_mc_fragile_key))
                ret = copy_mc_fragile(to, from, len);
        ret = copy_mc_generic(to, from, len);
        __uaccess_end();

and the !CONFIG_JUMP_LABEL version of static_branch_unlikely() uses
static_key_enabled(), which uses static_key_count(), which uses
atomic_read(), which calls instrument_atomic_read(), which uses
kasan_check_read(), which is __kasan_check_read().

Let's permit these KASAN helpers in UACCESS regions - static keys should
probably work under UACCESS, I think.

PeterZ adds:

  It's not a matter of permitting, it's a matter of being safe and
  correct. In this case it is, because it's a thin wrapper around
  check_memory_region() which was already marked safe.

  check_memory_region() is correct because the only thing it ends up
  calling is kasa_report() and that is also marked safe because that is
  annotated with user_access_save/restore() before it does anything else.

  On top of that, all of KASAN is noinstr, so nothing in here will end up
  in tracing and/or call schedule() before the user_access_save().

Signed-off-by: Jann Horn <jannh@google.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-10-02 09:28:08 -05:00
..
arch/x86 objtool: Decode unwind hint register depending on architecture 2020-09-10 10:43:13 -05:00
Documentation objtool: Add support for intra-function calls 2020-04-30 20:14:33 +02:00
.gitignore .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
arch.h objtool: Decode unwind hint register depending on architecture 2020-09-10 10:43:13 -05:00
Build objtool: Enable compilation of objtool for all architectures 2020-05-20 09:17:28 -05:00
builtin-check.c objtool: Move ORC logic out of check() 2020-09-01 17:19:11 -05:00
builtin-orc.c objtool: Move ORC logic out of check() 2020-09-01 17:19:11 -05:00
builtin.h objtool: Implement noinstr validation 2020-04-22 10:53:50 +02:00
cfi.h objtool: Fix !CFI insn_state propagation 2020-04-22 10:53:50 +02:00
check.c objtool: Permit __kasan_check_{read,write} under UACCESS 2020-10-02 09:28:08 -05:00
check.h objtool: Refactor jump table code to support other architectures 2020-09-10 10:43:13 -05:00
elf.c x86/static_call: Add inline static call implementation for x86-64 2020-09-01 09:58:05 +02:00
elf.h x86/static_call: Add inline static call implementation for x86-64 2020-09-01 09:58:05 +02:00
Makefile objtool: Define 'struct orc_entry' only when needed 2020-09-01 17:19:12 -05:00
objtool.c objtool: Move object file loading out of check() 2020-09-01 17:19:07 -05:00
objtool.h objtool: Abstract alternative special case handling 2020-09-10 10:43:13 -05:00
orc_dump.c objtool: Make unwind hint definitions available to other architectures 2020-09-10 10:43:13 -05:00
orc_gen.c objtool: Make unwind hint definitions available to other architectures 2020-09-10 10:43:13 -05:00
special.c objtool: Abstract alternative special case handling 2020-09-10 10:43:13 -05:00
special.h objtool: Refactor jump table code to support other architectures 2020-09-10 10:43:13 -05:00
sync-check.sh objtool: Make unwind hint definitions available to other architectures 2020-09-10 10:43:13 -05:00
warn.h objtool: Rename find_containing_func() 2020-03-25 18:28:29 +01:00
weak.c objtool: Abstract alternative special case handling 2020-09-10 10:43:13 -05:00