Patch "kbuild: Disable KCSAN for autogenerated *.mod.c intermediaries" has been added to the 6.1-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    kbuild: Disable KCSAN for autogenerated *.mod.c intermediaries

to the 6.1-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     kbuild-disable-kcsan-for-autogenerated-.mod.c-interm.patch
and it can be found in the queue-6.1 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit d7f24306f9f690edebec84995576bae72c100241
Author: Borislav Petkov (AMD) <bp@xxxxxxxxx>
Date:   Tue Mar 26 21:25:48 2024 +0100

    kbuild: Disable KCSAN for autogenerated *.mod.c intermediaries
    
    [ Upstream commit 54babdc0343fff2f32dfaafaaa9e42c4db278204 ]
    
    When KCSAN and CONSTRUCTORS are enabled, one can trigger the
    
      "Unpatched return thunk in use. This should not happen!"
    
    catch-all warning.
    
    Usually, when objtool runs on the .o objects, it does generate a section
    .return_sites which contains all offsets in the objects to the return
    thunks of the functions present there. Those return thunks then get
    patched at runtime by the alternatives.
    
    KCSAN and CONSTRUCTORS add this to the object file's .text.startup
    section:
    
      -------------------
      Disassembly of section .text.startup:
    
      ...
    
      0000000000000010 <_sub_I_00099_0>:
        10:   f3 0f 1e fa             endbr64
        14:   e8 00 00 00 00          call   19 <_sub_I_00099_0+0x9>
                              15: R_X86_64_PLT32      __tsan_init-0x4
        19:   e9 00 00 00 00          jmp    1e <__UNIQUE_ID___addressable_cryptd_alloc_aead349+0x6>
                              1a: R_X86_64_PLT32      __x86_return_thunk-0x4
      -------------------
    
    which, if it is built as a module goes through the intermediary stage of
    creating a <module>.mod.c file which, when translated, receives a second
    constructor:
    
      -------------------
      Disassembly of section .text.startup:
    
      0000000000000010 <_sub_I_00099_0>:
        10:   f3 0f 1e fa             endbr64
        14:   e8 00 00 00 00          call   19 <_sub_I_00099_0+0x9>
                              15: R_X86_64_PLT32      __tsan_init-0x4
        19:   e9 00 00 00 00          jmp    1e <_sub_I_00099_0+0xe>
                              1a: R_X86_64_PLT32      __x86_return_thunk-0x4
    
      ...
    
      0000000000000030 <_sub_I_00099_0>:
        30:   f3 0f 1e fa             endbr64
        34:   e8 00 00 00 00          call   39 <_sub_I_00099_0+0x9>
                              35: R_X86_64_PLT32      __tsan_init-0x4
        39:   e9 00 00 00 00          jmp    3e <__ksymtab_cryptd_alloc_ahash+0x2>
                              3a: R_X86_64_PLT32      __x86_return_thunk-0x4
      -------------------
    
    in the .ko file.
    
    Objtool has run already so that second constructor's return thunk cannot
    be added to the .return_sites section and thus the return thunk remains
    unpatched and the warning rightfully fires.
    
    Drop KCSAN flags from the mod.c generation stage as those constructors
    do not contain data races one would be interested about.
    
    Debugged together with David Kaplan <David.Kaplan@xxxxxxx> and Nikolay
    Borisov <nik.borisov@xxxxxxxx>.
    
    Reported-by: Paul Menzel <pmenzel@xxxxxxxxxxxxx>
    Closes: https://lore.kernel.org/r/0851a207-7143-417e-be31-8bf2b3afb57d@xxxxxxxxxxxxx
    Signed-off-by: Borislav Petkov (AMD) <bp@xxxxxxxxx>
    Tested-by: Paul Menzel <pmenzel@xxxxxxxxxxxxx> # Dell XPS 13
    Reviewed-by: Nikolay Borisov <nik.borisov@xxxxxxxx>
    Reviewed-by: Marco Elver <elver@xxxxxxxxxx>
    Signed-off-by: Masahiro Yamada <masahiroy@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal
index 3af5e5807983a..650d59388336f 100644
--- a/scripts/Makefile.modfinal
+++ b/scripts/Makefile.modfinal
@@ -23,7 +23,7 @@ modname = $(notdir $(@:.mod.o=))
 part-of-module = y
 
 quiet_cmd_cc_o_c = CC [M]  $@
-      cmd_cc_o_c = $(CC) $(filter-out $(CC_FLAGS_CFI) $(CFLAGS_GCOV), $(c_flags)) -c -o $@ $<
+      cmd_cc_o_c = $(CC) $(filter-out $(CC_FLAGS_CFI) $(CFLAGS_GCOV) $(CFLAGS_KCSAN), $(c_flags)) -c -o $@ $<
 
 %.mod.o: %.mod.c FORCE
 	$(call if_changed_dep,cc_o_c)




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux