Skip to content

configure.ac: add sanitizer build support - #204

Open
yskzalloc wants to merge 7 commits into
namjaejeon:masterfrom
yskzalloc:v1-sanitizer-on-master
Open

configure.ac: add sanitizer build support#204
yskzalloc wants to merge 7 commits into
namjaejeon:masterfrom
yskzalloc:v1-sanitizer-on-master

Conversation

@yskzalloc

Copy link
Copy Markdown
Contributor

This series adds compile-time sanitizer support to ksmbd-tools via
Autotools configure flags, enabling runtime detection of common memory
and concurrency bugs during development and testing.

The following sanitizers are supported:

--enable-asan AddressSanitizer (address, leak, undefined)
--enable-msan MemorySanitizer (requires clang)
--enable-tsan ThreadSanitizer

These three sanitizers are mutually exclusive at build time, as they
cannot coexist in a single binary. MemorySanitizer additionally
requires clang, and configure will error out if CC is not clang.

The flags are wired into AM_CFLAGS/AM_LDFLAGS across all subdirectory
Makefile.am files. When none of the --enable-*san options are given,
the variables are empty and the build is unaffected.

A GitHub Actions CI step is also added to build-test all three
sanitizers with clang.

Yunseong Kim (4):

  • configure.ac: add --enable-asan
  • configure.ac: add --enable-msan
  • configure.ac: add --enable-tsan
  • ksmbd: github action: add clang build with sanitizer

Signed-off-by: Yunseong Kim yunseong.kim@est.tech

yskzalloc added 7 commits May 4, 2026 15:31
usm_handle_logout_request() updates user->failed_login_count
and user->flags when processing a logout request. However, it modifies
these fields without holding the user->update_lock.

Since the ksmbd_user object can be accessed concurrently by multiple
threads handling simultaneous login or logout requests for the same user,
this lockless modification leads to a data race, potentially corrupting
the login failure count or user state flags.

Fix this by acquiring the user->update_lock writer lock before updating
these fields to ensure thread safety.

Fixes: a114451 ("ksmbd-tools: throttle session setup failures to avoid dictionary attacks")
Signed-off-by: Yunseong Kim <yunseong.kim@est.tech>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
usm_add_guest_account() sets the KSMBD_USER_FLAG_GUEST_ACCOUNT flag
for a newly created guest user. However, it calls set_user_flag()
without holding the user->update_lock.

Modifying the user's flags locklessly at this stage can result in
a data race if another thread accesses the user object simultaneously.

Fix this by acquiring the user->update_lock writer lock before setting
the guest account flag to ensure thread-safe flag modification.

Fixes: 54d2a02 ("ksmbd-tools: simplify config parser")
Signed-off-by: Yunseong Kim <yunseong.kim@est.tech>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
__handle_login_request() reads user->flags and user->ngroups
to construct the login response status. However, these reads are
performed without holding the user->update_lock.

Since user->flags can be modified concurrently by other threads (for
example, during a logout request processing or when setting guest account
flags), this lockless access can lead to reading an inconsistent or
stale user state.

Fix this by acquiring the user->update_lock reader lock before accessing
these fields to ensure thread safety. As a minor cleanup, combine the
status flag assignments into a single line.

Fixes: c2b6ac1 ("cifsd-tools: factor out user login request handling")
Signed-off-by: Yunseong Kim <yunseong.kim@est.tech>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
Add AddressSanitizer support

Signed-off-by: Yunseong Kim <yunseong.kim@est.tech>
Add MemorySanitizer (initialization) support

Signed-off-by: Yunseong Kim <yunseong.kim@est.tech>
Add ThreadSanitizer support

Signed-off-by: Yunseong Kim <yunseong.kim@est.tech>
Test clang build for ksmbd-tools with mutual exclusive sanitizer

Signed-off-by: Yunseong Kim <yunseong.kim@est.tech>
@yskzalloc

Copy link
Copy Markdown
Contributor Author

P.S.
This work was greatly inspired by the uftrace project.

@neheb

neheb commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

@yskzalloc the meson build supports this natively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants