]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
objtool, panic: Disable SMAP in __stack_chk_fail()
authorJosh Poimboeuf <jpoimboe@kernel.org>
Mon, 24 Mar 2025 21:56:07 +0000 (14:56 -0700)
committerIngo Molnar <mingo@kernel.org>
Tue, 25 Mar 2025 22:00:15 +0000 (23:00 +0100)
__stack_chk_fail() can be called from uaccess-enabled code.  Make sure
uaccess gets disabled before calling panic().

Fixes the following warning:

  kernel/trace/trace_branch.o: error: objtool: ftrace_likely_update+0x1ea: call to __stack_chk_fail() with UACCESS enabled

Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/a3e97e0119e1b04c725a8aa05f7bc83d98e657eb.1742852847.git.jpoimboe@kernel.org
kernel/panic.c
tools/objtool/check.c

index d8635d5cecb2505da1c08a4f70814e9b87ac3b37..f9f0c5148f6aa7a45fa302d41e32d44887d4d7a9 100644 (file)
@@ -832,9 +832,15 @@ device_initcall(register_warn_debugfs);
  */
 __visible noinstr void __stack_chk_fail(void)
 {
+       unsigned long flags;
+
        instrumentation_begin();
+       flags = user_access_save();
+
        panic("stack-protector: Kernel stack is corrupted in: %pB",
                __builtin_return_address(0));
+
+       user_access_restore(flags);
        instrumentation_end();
 }
 EXPORT_SYMBOL(__stack_chk_fail);
index 0caabf0e8faf2cdafd4afd4aea2d2bb9e759e043..3bf29923d5c0234d371b42500d17654da3d3ec26 100644 (file)
@@ -1194,12 +1194,15 @@ static const char *uaccess_safe_builtin[] = {
        "__ubsan_handle_load_invalid_value",
        /* STACKLEAK */
        "stackleak_track_stack",
+       /* TRACE_BRANCH_PROFILING */
+       "ftrace_likely_update",
+       /* STACKPROTECTOR */
+       "__stack_chk_fail",
        /* misc */
        "csum_partial_copy_generic",
        "copy_mc_fragile",
        "copy_mc_fragile_handle_tail",
        "copy_mc_enhanced_fast_string",
-       "ftrace_likely_update", /* CONFIG_TRACE_BRANCH_PROFILING */
        "rep_stos_alternative",
        "rep_movs_alternative",
        "__copy_user_nocache",