Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Register
  • Sign in
  • L linux
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • Deployments
    • Deployments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • Kirill Smelkov
  • linux
  • Repository
You need to sign in or sign up before continuing.
  • linux
  • lib
  • string.c
Find file BlameHistoryPermalink
  • Alexander Potapenko's avatar
    string: use __builtin_memcpy() in strlcpy/strlcat · f9cfb191
    Alexander Potapenko authored May 30, 2023
    
    
    lib/string.c is built with -ffreestanding, which prevents the compiler
    from replacing certain functions with calls to their library versions.
    
    On the other hand, this also prevents Clang and GCC from instrumenting
    calls to memcpy() when building with KASAN, KCSAN or KMSAN:
     - KASAN normally replaces memcpy() with __asan_memcpy() with the
       additional cc-param,asan-kernel-mem-intrinsic-prefix=1;
     - KCSAN and KMSAN replace memcpy() with __tsan_memcpy() and
       __msan_memcpy() by default.
    
    To let the tools catch memory accesses from strlcpy/strlcat, replace
    the calls to memcpy() with __builtin_memcpy(), which KASAN, KCSAN and
    KMSAN are able to replace even in -ffreestanding mode.
    
    This preserves the behavior in normal builds (__builtin_memcpy() ends up
    being replaced with memcpy()), and does not introduce new instrumentation
    in unwanted places, as strlcpy/strlcat are already instrumented.
    
    Suggested-by: default avatarMarco Elver <elver@google.com>
    Signed-off-by: default avatarAlexander Potapenko <glider@google.com>
    Reviewed-by: default avatarMarco Elver <elver@google.com>
    Link: https://lore.kernel.org/all/20230224085942.1791837-1-elver@google.com/
    
    
    Acked-by: default avatarKees Cook <keescook@chromium.org>
    Signed-off-by: default avatarKees Cook <keescook@chromium.org>
    Link: https://lore.kernel.org/r/20230530083911.1104336-1-glider@google.com
    f9cfb191
GitLab Nexedi Edition | About GitLab | About Nexedi | 沪ICP备2021021310号-2 | 沪ICP备2021021310号-7