]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
busdma: Add KMSAN integration
authorMark Johnston <markj@FreeBSD.org>
Tue, 10 Aug 2021 21:14:15 +0000 (17:14 -0400)
committerMark Johnston <markj@FreeBSD.org>
Wed, 11 Aug 2021 01:27:54 +0000 (21:27 -0400)
commit693c9516fa6070199d1406df3265687c5e8b184a
treedcfbacfc8785ee3178447d026c0609c0c4089165
parent3a1802fef4b535d22b7f0d3fa6e0bc2de5003922
busdma: Add KMSAN integration

Sanitizer instrumentation of course cannot automatically update shadow
state when devices write to host memory.  KMSAN thus hooks into busdma,
both to update shadow state after a device write, and to verify that the
kernel does not publish uninitalized bytes to devices.

To implement this, when KMSAN is configured, each dmamap embeds a memory
descriptor describing the region currently loaded into the map.
bus_dmamap_sync() uses the operation flags to determine whether to
validate the loaded region or to mark it as initialized in the shadow
map.

Note that in cases where the amount of data written is less than the
buffer size, the entire buffer is marked initialized even when it is
not.  For example, if a NIC writes a 128B packet into a 2KB buffer, the
entire buffer will be marked initialized, but subsequent accesses past
the first 128 bytes are likely caused by bugs.

Reviewed by: kib
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D31338
sys/dev/iommu/busdma_iommu.c
sys/dev/iommu/busdma_iommu.h
sys/kern/subr_bus_dma.c
sys/x86/include/bus_dma.h
sys/x86/include/busdma_impl.h
sys/x86/x86/busdma_bounce.c