Skip to content

Commit e267e39

Browse files
Add UndefinedBehaviorSanitizer (UBSan) support.
1 parent beea70e commit e267e39

File tree

3 files changed

+122
-0
lines changed

3 files changed

+122
-0
lines changed

.github/workflows/ubsan.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: UBSan (UndefinedBehaviorSanitizer)
2+
3+
# Undefined behavior detection using UndefinedBehaviorSanitizer
4+
# This workflow builds memtier_benchmark with UBSan enabled and runs
5+
# the full test suite to detect undefined behavior issues.
6+
7+
on: [push, pull_request]
8+
9+
jobs:
10+
test-with-ubsan:
11+
runs-on: ubuntu-latest
12+
name: Undefined behavior detection (UBSan)
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Install build dependencies
18+
run: |
19+
sudo apt-get -qq update
20+
sudo apt-get install -y \
21+
build-essential \
22+
autoconf \
23+
automake \
24+
pkg-config \
25+
libevent-dev \
26+
zlib1g-dev \
27+
libssl-dev
28+
29+
- name: Build with UBSan
30+
run: |
31+
autoreconf -ivf
32+
./configure --enable-ubsan
33+
make -j
34+
35+
- name: Setup Python
36+
uses: actions/setup-python@v2
37+
with:
38+
python-version: '3.10'
39+
architecture: x64
40+
41+
- name: Install Python test dependencies
42+
run: pip install -r ./tests/test_requirements.txt
43+
44+
- name: Install Redis
45+
run: |
46+
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
47+
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
48+
sudo apt-get -qq update
49+
sudo apt-get install redis
50+
sudo service redis-server stop
51+
52+
- name: Increase connection limit
53+
run: |
54+
sudo sysctl -w net.ipv4.tcp_fin_timeout=10
55+
sudo sysctl -w net.ipv4.tcp_tw_reuse=1
56+
ulimit -n 40960
57+
58+
- name: Generate TLS test certificates
59+
run: ./tests/gen-test-certs.sh
60+
61+
- name: Test OSS TCP with UBSan
62+
timeout-minutes: 10
63+
run: |
64+
UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./tests/run_tests.sh
65+
66+
- name: Test OSS TCP TLS with UBSan
67+
timeout-minutes: 10
68+
run: |
69+
UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 TLS=1 ./tests/run_tests.sh
70+
71+
- name: Test OSS TCP TLS v1.2 with UBSan
72+
timeout-minutes: 10
73+
run: |
74+
UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 TLS_PROTOCOLS='TLSv1.2' TLS=1 ./tests/run_tests.sh
75+
76+
- name: Test OSS TCP TLS v1.3 with UBSan
77+
timeout-minutes: 10
78+
run: |
79+
UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 TLS_PROTOCOLS='TLSv1.3' TLS=1 ./tests/run_tests.sh
80+
81+
- name: Test OSS-CLUSTER TCP with UBSan
82+
timeout-minutes: 10
83+
run: |
84+
UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 OSS_STANDALONE=0 OSS_CLUSTER=1 ./tests/run_tests.sh
85+
86+
- name: Test OSS-CLUSTER TCP TLS with UBSan
87+
timeout-minutes: 10
88+
run: |
89+
UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 OSS_STANDALONE=0 OSS_CLUSTER=1 TLS=1 ./tests/run_tests.sh
90+

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,28 @@ To verify ASAN is enabled:
157157

158158
$ ldd ./memtier_benchmark | grep asan
159159

160+
161+
**Undefined behavior detection with UBSan**
162+
163+
164+
memtier_benchmark supports building with UndefinedBehaviorSanitizer (UBSan) to detect undefined behavior such as integer overflows, null pointer dereferences, and alignment issues.
165+
166+
To build with UBSan enabled:
167+
168+
$ ./configure --enable-ubsan
169+
$ make
170+
171+
To run tests with undefined behavior detection:
172+
173+
$ UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./tests/run_tests.sh
174+
175+
UBSan can be combined with ASAN for comprehensive testing:
176+
177+
$ ./configure --enable-sanitizers --enable-ubsan
178+
$ make
179+
180+
**Note:** UBSan can be used together with ASAN/LSAN, but not with ThreadSanitizer (TSAN).
181+
160182
## Using Docker
161183

162184
Use available images on Docker Hub:

configure.ac

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ AS_IF([test "x$enable_sanitizers" = "xyes"], [
7979
LDFLAGS="$LDFLAGS -fsanitize=address -fsanitize=leak"
8080
], [])
8181

82+
# UndefinedBehaviorSanitizer (UBSan) is optional and can be combined with ASAN.
83+
AC_ARG_ENABLE([ubsan],
84+
[AS_HELP_STRING([--enable-ubsan],
85+
[Enable UndefinedBehaviorSanitizer for undefined behavior detection])])
86+
AS_IF([test "x$enable_ubsan" = "xyes"], [
87+
AC_MSG_NOTICE([Enabling UndefinedBehaviorSanitizer])
88+
CXXFLAGS="$CXXFLAGS -fsanitize=undefined -fno-omit-frame-pointer"
89+
LDFLAGS="$LDFLAGS -fsanitize=undefined"
90+
], [])
91+
8292
# clock_gettime requires -lrt on old glibc only.
8393
AC_SEARCH_LIBS([clock_gettime], [rt], , AC_MSG_ERROR([rt is required libevent.]))
8494

0 commit comments

Comments
 (0)