google / kmsan

KernelMemorySanitizer, a detector of uses of uninitialized memory in the Linux kernel
Other
406 stars 63 forks source link

arch/x86/kernel/module.c:230:49: error: call to undeclared library function 'memcpy' #89

Closed tklengyel closed 1 year ago

tklengyel commented 2 years ago

Trying to compile latest linux git (49da070062390094112b423ba443ea193527b2e4) after KMSAN merge on Ubuntu 22.04 with clang-15 I get the following error:

make LLVM=-15 CC=clang-15 bzImage
...
arch/x86/kernel/module.c:230:49: error: call to undeclared library function 'memcpy' with type 'void *(void *, const void *, unsigned long)'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
        void *(*write)(void *, const void *, size_t) = memcpy;
ramosian-glider commented 2 years ago

Any chance you could share the config you were using to build the kernel? Thanks!

tklengyel commented 2 years ago

Here you go kmsan-failure.zip

ramosian-glider commented 2 years ago

Ok, this must have something to do with CONFIG_FORTIFY_SOURCE=y, looking...

ramosian-glider commented 2 years ago

Another finding is that CONFIG_FRAME_WARN makes no sense under KMSAN, and configs like CONFIG_WERROR and CONFIG_KVM_WERROR enforce build-time-errors because of that warning.

ramosian-glider commented 2 years ago

And another one:

ld: arch/x86/purgatory/purgatory.ro: in function `purgatory':
(.text+0x1a): undefined reference to `__msan_get_context_state'
ld: (.text+0x35): undefined reference to `__msan_poison_alloca'
ld: (.text+0x69): undefined reference to `__msan_metadata_ptr_for_store_4'
ld: (.text+0x126): undefined reference to `__msan_metadata_ptr_for_store_8'
ld: (.text+0x153): undefined reference to `__msan_metadata_ptr_for_load_8'
tklengyel commented 2 years ago

FYI the config is largely based off of the default Ubuntu config, just ran through olddefconfig and disabled some signing/lockdown options.

ramosian-glider commented 2 years ago

FYI the config is largely based off of the default Ubuntu config, just ran through olddefconfig and disabled some signing/lockdown options.

Ok, then it really makes sense for me to make it work. It's nice that it uncovered so many problems at once.

ramosian-glider commented 2 years ago

Another one:

  MODPOST Module.symvers
ERROR: modpost: "kmsan_copy_page_meta" [fs/nilfs2/nilfs2.ko] undefined!
ERROR: modpost: "kmsan_copy_page_meta" [drivers/gpu/drm/ttm/ttm.ko] undefined!
ERROR: modpost: "kmsan_copy_page_meta" [drivers/block/drbd/drbd.ko] undefined!
make[1]: *** [scripts/Makefile.modpost:126: Module.symvers] Error 1
ramosian-glider commented 2 years ago

After setting CONFIG_FRAME_WARN=0 (we cannot override what's written in the config for that flag) in the original config, I am able to build the current KMSAN master (which is almost identical to Linux v6.1-rc4). Yet it is unable to boot, probably there are more config flags that don't paly well with KMSAN.

ramosian-glider commented 2 years ago

@tklengyel please note that according to your config you are using Clang 14, which does not support all the required features:

    1 #
    2 # Automatically generated file; DO NOT EDIT.
    3 # Linux/x86 6.0.0 Kernel Configuration
    4 #
    5 CONFIG_CC_VERSION_TEXT="Ubuntu clang version 14.0.0-1ubuntu1"
    6 CONFIG_GCC_VERSION=0
    7 CONFIG_CC_IS_CLANG=y
    8 CONFIG_CLANG_VERSION=140000
    9 CONFIG_AS_IS_LLVM=y
   10 CONFIG_AS_VERSION=140000
...
10502 CONFIG_HAVE_ARCH_KMSAN=y
10503 CONFIG_HAVE_KMSAN_COMPILER=y
10504 CONFIG_KMSAN=y
10505 # end of Memory Debugging

-- it does not have CONFIG_HAVE_KMSAN_PARAM_RETVAL=y or CONFIG_KMSAN_CHECK_PARAM_RETVAL=y

This shouldn't prevent KMSAN from booting though.

tklengyel commented 2 years ago

@ramosian-glider Thanks, have already moved on to clang-15, this was just the backup of the config I tried first. Very first thing I tried was to move to clang-15 to see if that resolved the compile issue (it did not) ;)

ramosian-glider commented 2 years ago

@tklengyel can you please try to disable the following configs and see if that helps?

tklengyel commented 1 year ago

I just checked with the latest tip of linux (9d646009f65d62d32815f376465a3b92d8d9b046) and I no longer have this issue popping up.