HomeFreeBSD

busdma: Add KMSAN integration

Description

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

Details

Provenance
markjAuthored on Aug 10 2021, 9:14 PM
Reviewer
kib
Differential Revision
D31338: busdma: Add hooks for KMSAN
Parents
rG3a1802fef4b5: busdma: Add an internal BUS_DMA_FORCE_MAP flag to x86 bounce_busdma
Branches
Unknown
Tags
Unknown