]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commit
common/mutex_debug: fix arm64 SIGBUS/segfault due to data race
authorKefu Chai <tchaikov@gmail.com>
Tue, 1 Jul 2025 06:29:41 +0000 (14:29 +0800)
committerKefu Chai <tchaikov@gmail.com>
Thu, 3 Jul 2025 04:22:14 +0000 (12:22 +0800)
commit8bcf327c64f437cc893ddcea4c0c405adb4dc027
tree5268b8d8ef9b804bfe9d246f77cf087bd174f401
parentf768b9273887b71fd09e1c92ebbe6cced3dd26c8
common/mutex_debug: fix arm64 SIGBUS/segfault due to data race

The mutex_debugging_base::is_locked_by_me() member function was
experiencing random SIGBUS and segfault on ARM64 due to a data race on
the non-atomic locked_by member.

The racing occurs when:
- Thread A writes to locked_by during lock acquisition
- Thread B reads from locked_by in is_locked_by_me()
- These accesses happen concurrently without synchronization

On ARM64, std::thread::id (8 bytes when using libstdc++) writes/reads
are not atomic, causing the reader to potentially see partially written
or corrupted thread ID values, leading to undefined behavior in the
comparison operator.

Fix by making locked_by atomic and using proper memory ordering
in is_locked_by_me() to ensure synchronized access.

Fixes: https://tracker.ceph.com/issues/71547
Signed-off-by: Kefu Chai <tchaikov@gmail.com>
src/common/mutex_debug.h