Page MenuHomeFreeBSD

libkern: implement string functions as wrappers on ASAN/CSAN kernels
Needs ReviewPublic

Authored by khng on Sep 4 2025, 8:54 PM.
Tags
None
Referenced Files
F133218227: D52389.id161582.diff
Fri, Oct 24, 1:50 AM
Unknown Object (File)
Tue, Oct 21, 1:50 PM
Unknown Object (File)
Tue, Oct 21, 1:50 PM
Unknown Object (File)
Tue, Oct 21, 2:04 AM
Unknown Object (File)
Tue, Oct 21, 2:04 AM
Unknown Object (File)
Tue, Oct 21, 2:04 AM
Unknown Object (File)
Mon, Oct 20, 4:25 PM
Unknown Object (File)
Sat, Oct 18, 4:04 AM
Subscribers

Details

Reviewers
markj
Summary

For kernel modules, if they are not ASAN-instrumented, or if they
call those functions without going through the preprocessor macros
defined, they would end up calling non-SAN_INTERCEPTOR baseline
str* functions exported by the kernel.

The above situations happens when an environment runs a large set of
modules that are not build as a part of the FreeBSD tree, or are already
there as standalone .ko files.

The baseline strlen was implemented in a way that scans for non-nul
characters in word units first before doing a byte-by-byte comparison.
However this does not always play well with ASAN-enabled kernel and the
implementation might hit kernel panic due to hitting RedZonePartial ASAN
reports.

In this commit, for ASAN/CSAN-enabled kernels, str* is implemented as
wrappers instead.

MFC after: 1 week
Sponsored by: Juniper Networks, Inc.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 66838
Build 63721: arc lint + arc unit

Event Timeline

khng requested review of this revision.Sep 4 2025, 8:54 PM
khng planned changes to this revision.Sep 5 2025, 12:13 AM
khng retitled this revision from libkern: implement strlen as a wrapper for SAN-enabled kernel to libkern: implement str*/mem* as wrappers for SAN-enabled kernel.Sep 5 2025, 2:18 PM
khng edited the summary of this revision. (Show Details)
khng planned changes to this revision.Sep 5 2025, 5:11 PM

Have to rethink the whole patch again.

khng retitled this revision from libkern: implement str*/mem* as wrappers for SAN-enabled kernel to libkern: implement string functions as wrappers on ASAN/CSAN kernels.Sep 5 2025, 5:27 PM
khng edited the summary of this revision. (Show Details)
khng retitled this revision from libkern: implement string functions as wrappers on ASAN/CSAN kernels to libkern: implement string functions as wrappers on ASAN/CSAN kernels.Sep 5 2025, 5:30 PM

Only implement this for string stuff. mem* stuff will end up calling into itself again because of the use of __builtin_mem*.