https://github.com/google/kmsan
Revision e6bc8833d80fb695515a8144aa1dc13468db9d4d authored by Alexander Potapenko on 27 February 2023, 15:44:58 UTC, committed by Alexander Potapenko on 19 June 2023, 08:56:03 UTC
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: Marco Elver <elver@google.com>
Signed-off-by: Alexander Potapenko <glider@google.com>
Link: https://lore.kernel.org/all/20230224085942.1791837-1-elver@google.com/
Acked-by: Kees Cook <keescook@chromium.org>
1 parent 11aac78
History
Tip revision: e6bc8833d80fb695515a8144aa1dc13468db9d4d authored by Alexander Potapenko on 27 February 2023, 15:44:58 UTC
string: use __builtin_memcpy() in strlcpy/strlcat
Tip revision: e6bc883
File Mode Size
damon
kasan
kfence
kmsan
Kconfig -rw-r--r-- 37.5 KB
Kconfig.debug -rw-r--r-- 10.3 KB
Makefile -rw-r--r-- 5.0 KB
backing-dev.c -rw-r--r-- 27.6 KB
balloon_compaction.c -rw-r--r-- 8.2 KB
bootmem_info.c -rw-r--r-- 3.4 KB
cma.c -rw-r--r-- 15.6 KB
cma.h -rw-r--r-- 1.4 KB
cma_debug.c -rw-r--r-- 4.5 KB
cma_sysfs.c -rw-r--r-- 2.4 KB
compaction.c -rw-r--r-- 86.2 KB
debug.c -rw-r--r-- 6.8 KB
debug_page_ref.c -rw-r--r-- 1.4 KB
debug_vm_pgtable.c -rw-r--r-- 40.1 KB
dmapool.c -rw-r--r-- 13.1 KB
dmapool_test.c -rw-r--r-- 2.9 KB
early_ioremap.c -rw-r--r-- 6.7 KB
fadvise.c -rw-r--r-- 5.6 KB
failslab.c -rw-r--r-- 1.6 KB
filemap.c -rw-r--r-- 116.4 KB
folio-compat.c -rw-r--r-- 3.1 KB
frontswap.c -rw-r--r-- 7.9 KB
gup.c -rw-r--r-- 89.9 KB
gup_test.c -rw-r--r-- 9.0 KB
gup_test.h -rw-r--r-- 1.2 KB
highmem.c -rw-r--r-- 20.1 KB
hmm.c -rw-r--r-- 17.0 KB
huge_memory.c -rw-r--r-- 87.9 KB
hugetlb.c -rw-r--r-- 210.7 KB
hugetlb_cgroup.c -rw-r--r-- 24.7 KB
hugetlb_vmemmap.c -rw-r--r-- 16.8 KB
hugetlb_vmemmap.h -rw-r--r-- 1.6 KB
hwpoison-inject.c -rw-r--r-- 2.8 KB
init-mm.c -rw-r--r-- 1.7 KB
internal.h -rw-r--r-- 34.0 KB
interval_tree.c -rw-r--r-- 3.1 KB
io-mapping.c -rw-r--r-- 993 bytes
ioremap.c -rw-r--r-- 1.4 KB
khugepaged.c -rw-r--r-- 75.3 KB
kmemleak.c -rw-r--r-- 60.9 KB
ksm.c -rw-r--r-- 95.5 KB
list_lru.c -rw-r--r-- 13.8 KB
maccess.c -rw-r--r-- 5.9 KB
madvise.c -rw-r--r-- 38.5 KB
mapping_dirty_helpers.c -rw-r--r-- 10.5 KB
memblock.c -rw-r--r-- 61.8 KB
memcontrol.c -rw-r--r-- 203.6 KB
memfd.c -rw-r--r-- 9.6 KB
memory-failure.c -rw-r--r-- 71.7 KB
memory-tiers.c -rw-r--r-- 18.4 KB
memory.c -rw-r--r-- 162.1 KB
memory_hotplug.c -rw-r--r-- 64.2 KB
mempolicy.c -rw-r--r-- 78.4 KB
mempool.c -rw-r--r-- 16.1 KB
memremap.c -rw-r--r-- 15.0 KB
memtest.c -rw-r--r-- 2.9 KB
migrate.c -rw-r--r-- 69.8 KB
migrate_device.c -rw-r--r-- 27.4 KB
mincore.c -rw-r--r-- 7.1 KB
mlock.c -rw-r--r-- 19.4 KB
mm_init.c -rw-r--r-- 77.4 KB
mm_slot.h -rw-r--r-- 1.4 KB
mmap.c -rw-r--r-- 101.2 KB
mmap_lock.c -rw-r--r-- 6.2 KB
mmu_gather.c -rw-r--r-- 9.8 KB
mmu_notifier.c -rw-r--r-- 35.0 KB
mmzone.c -rw-r--r-- 2.5 KB
mprotect.c -rw-r--r-- 23.8 KB
mremap.c -rw-r--r-- 29.1 KB
msync.c -rw-r--r-- 2.9 KB
nommu.c -rw-r--r-- 44.3 KB
oom_kill.c -rw-r--r-- 33.5 KB
page-writeback.c -rw-r--r-- 94.2 KB
page_alloc.c -rw-r--r-- 199.4 KB
page_counter.c -rw-r--r-- 6.8 KB
page_ext.c -rw-r--r-- 13.7 KB
page_idle.c -rw-r--r-- 5.3 KB
page_io.c -rw-r--r-- 13.4 KB
page_isolation.c -rw-r--r-- 20.7 KB
page_owner.c -rw-r--r-- 18.0 KB
page_poison.c -rw-r--r-- 2.5 KB
page_reporting.c -rw-r--r-- 11.6 KB
page_reporting.h -rw-r--r-- 1.6 KB
page_table_check.c -rw-r--r-- 6.1 KB
page_vma_mapped.c -rw-r--r-- 8.7 KB
pagewalk.c -rw-r--r-- 16.3 KB
percpu-internal.h -rw-r--r-- 7.1 KB
percpu-km.c -rw-r--r-- 3.2 KB
percpu-stats.c -rw-r--r-- 5.8 KB
percpu-vm.c -rw-r--r-- 11.7 KB
percpu.c -rw-r--r-- 102.2 KB
pgalloc-track.h -rw-r--r-- 1.3 KB
pgtable-generic.c -rw-r--r-- 5.8 KB
process_vm_access.c -rw-r--r-- 8.2 KB
ptdump.c -rw-r--r-- 4.2 KB
readahead.c -rw-r--r-- 25.9 KB
rmap.c -rw-r--r-- 73.9 KB
rodata_test.c -rw-r--r-- 1.2 KB
secretmem.c -rw-r--r-- 6.4 KB
shmem.c -rw-r--r-- 114.3 KB
shrinker_debug.c -rw-r--r-- 6.3 KB
shuffle.c -rw-r--r-- 4.6 KB
shuffle.h -rw-r--r-- 1.2 KB
slab.c -rw-r--r-- 102.0 KB
slab.h -rw-r--r-- 22.2 KB
slab_common.c -rw-r--r-- 37.0 KB
slub.c -rw-r--r-- 160.7 KB
sparse-vmemmap.c -rw-r--r-- 11.8 KB
sparse.c -rw-r--r-- 25.6 KB
swap.c -rw-r--r-- 30.8 KB
swap.h -rw-r--r-- 3.9 KB
swap_cgroup.c -rw-r--r-- 5.2 KB
swap_slots.c -rw-r--r-- 9.2 KB
swap_state.c -rw-r--r-- 23.9 KB
swapfile.c -rw-r--r-- 92.6 KB
truncate.c -rw-r--r-- 25.9 KB
usercopy.c -rw-r--r-- 8.1 KB
userfaultfd.c -rw-r--r-- 19.7 KB
util.c -rw-r--r-- 28.7 KB
vmalloc.c -rw-r--r-- 114.1 KB
vmpressure.c -rw-r--r-- 13.9 KB
vmscan.c -rw-r--r-- 221.9 KB
vmstat.c -rw-r--r-- 54.8 KB
workingset.c -rw-r--r-- 25.2 KB
z3fold.c -rw-r--r-- 43.8 KB
zbud.c -rw-r--r-- 17.8 KB
zpool.c -rw-r--r-- 11.4 KB
zsmalloc.c -rw-r--r-- 65.4 KB
zswap.c -rw-r--r-- 41.5 KB

back to top