запуск автотестов с включенным asan (address sanitizer)

Илья Шипицин chipitsine на gmail.com
Пт Сен 4 18:12:30 UTC 2020


Добрый день!

для тестирования самодельного модуля, использовали такую методику

взяли https://github.com/nginx/nginx-tests
собрали nginx с самодельным модулем и gcc asan (не суть, могли бы взять
clang asan).
собрали кучу вариантов прохода по коду (это круто), нашли сколько-то
дефектов в своем модуле.

интересные вещи возникают с asan, причем, воспроизводятся на оригинальном
nginx.
это непонятно. можете прокомментировать ?

1. беру nginx из официальной репы. смотрю "nginx -V", добавляю
-fsanitize=address к cc-opts
2. выставляю ASAN_OPTIONS="log_path=asan.log"
3. запукаю тесты, смотрю, что упало в asan.log (а там есть сработки, это
немного неожиданно)

скрипт

#!/bin/bash

set -e

sysctl kernel.core_pattern=/tmp/core-%e-%s-%u-%g-%p-%t
ulimit -c unlimited
export version=1.19.2

mkdir t
cd t

wget http://nginx.org/download/nginx-${version}.tar.gz
tar xf nginx-${version}.tar.gz

cd nginx-${version}

./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx
--modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid
--lock-path=/var/run/nginx.lock
--http-client-body-temp-path=/var/cache/nginx/client_temp
--http-proxy-temp-path=/var/cache/nginx/proxy_temp
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp
--http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx
--with-compat --with-file-aio --with-threads --with-http_addition_module
--with-http_auth_request_module --with-http_dav_module
--with-http_flv_module --with-http_gunzip_module
--with-http_gzip_static_module --with-http_mp4_module
--with-http_random_index_module --with-http_realip_module
--with-http_secure_link_module --with-http_slice_module
--with-http_ssl_module --with-http_stub_status_module
--with-http_sub_module --with-http_v2_module --with-mail
--with-mail_ssl_module --with-stream --with-stream_realip_module
--with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-g
-O0
-fdebug-prefix-map=/data/builder/debuild/nginx-1.19.2/debian/debuild-base/nginx-1.19.2=.
-fstack-protector-strong -Wformat -Werror=format-security
-Wp,-D_FORTIFY_SOURCE=2 -fPIC -fsanitize=address'
--with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now
-Wl,--as-needed -pie -fsanitize=address -lasan' --with-debug


make
export ASAN_OPTIONS="log_path=asan.log"
export TEST_NGINX_BINARY=`pwd`/objs/nginx
export TEST_NGINX_GLOBALS='user root; '
export TEST_NGINX_GLOBALS_HTTP='error_log /tmp/e.log;'
git clone https://github.com/nginx/nginx-tests
prove -r nginx-tests


сработки

# locate asan.log
/root/t/nginx-1.19.2/nginx-tests/asan.log.46464
/root/t/nginx-1.19.2/nginx-tests/asan.log.46728
/root/t/nginx-1.19.2/nginx-tests/asan.log.46866
/root/t/nginx-1.19.2/nginx-tests/asan.log.46876
/root/t/nginx-1.19.2/nginx-tests/asan.log.47784
/root/t/nginx-1.19.2/nginx-tests/asan.log.47931
/root/t/nginx-1.19.2/nginx-tests/asan.log.47957
/root/t/nginx-1.19.2/nginx-tests/asan.log.47983
/root/t/nginx-1.19.2/nginx-tests/asan.log.48005
/root/t/nginx-1.19.2/nginx-tests/asan.log.48760
/root/t/nginx-1.19.2/nginx-tests/asan.log.48770
/root/t/nginx-1.19.2/nginx-tests/asan.log.48818
/root/t/nginx-1.19.2/nginx-tests/asan.log.49079
/root/t/nginx-1.19.2/nginx-tests/asan.log.49329

пример первой

# cat /root/t/nginx-1.19.2/nginx-tests/asan.log.46464

=================================================================
==46464==ERROR: LeakSanitizer: detected memory leaks

Indirect leak of 16384 byte(s) in 1 object(s) allocated from:
    #0 0x7f36e86dbaa5 in posix_memalign
(/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10eaa5)
    #1 0x5627781c130d in ngx_memalign src/os/unix/ngx_alloc.c:57
    #2 0x5627781231ef in ngx_palloc_block src/core/ngx_palloc.c:186
    #3 0x562778123166 in ngx_palloc_small src/core/ngx_palloc.c:173
    #4 0x562778122f91 in ngx_palloc src/core/ngx_palloc.c:127
    #5 0x5627782744f4 in ngx_http_add_variable
src/http/ngx_http_variables.c:449
    #6 0x56277828046b in ngx_http_variables_add_core_vars
src/http/ngx_http_variables.c:2622
    #7 0x56277822fd37 in ngx_http_core_preconfiguration
src/http/ngx_http_core_module.c:3262
    #8 0x562778213c81 in ngx_http_block src/http/ngx_http.c:227
    #9 0x56277817679d in ngx_conf_handler src/core/ngx_conf_file.c:463
    #10 0x5627781757c4 in ngx_conf_parse src/core/ngx_conf_file.c:319
    #11 0x56277816b106 in ngx_init_cycle src/core/ngx_cycle.c:275
    #12 0x5627781188ae in main src/core/nginx.c:291
    #13 0x7f36e7fa40b2 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

Indirect leak of 16384 byte(s) in 1 object(s) allocated from:
    #0 0x7f36e86dbaa5 in posix_memalign
(/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10eaa5)
    #1 0x5627781c130d in ngx_memalign src/os/unix/ngx_alloc.c:57
    #2 0x5627781231ef in ngx_palloc_block src/core/ngx_palloc.c:186
    #3 0x562778123166 in ngx_palloc_small src/core/ngx_palloc.c:173
    #4 0x562778122f91 in ngx_palloc src/core/ngx_palloc.c:127
    #5 0x562778123957 in ngx_pcalloc src/core/ngx_palloc.c:302
    #6 0x5627783a72da in ngx_http_proxy_create_loc_conf
src/http/modules/ngx_http_proxy_module.c:2854
    #7 0x56277821386d in ngx_http_block src/http/ngx_http.c:209
    #8 0x56277817679d in ngx_conf_handler src/core/ngx_conf_file.c:463
    #9 0x5627781757c4 in ngx_conf_parse src/core/ngx_conf_file.c:319
    #10 0x56277816b106 in ngx_init_cycle src/core/ngx_cycle.c:275
    #11 0x5627781188ae in main src/core/nginx.c:291
    #12 0x7f36e7fa40b2 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

Indirect leak of 16384 byte(s) in 1 object(s) allocated from:
    #0 0x7f36e86dbaa5 in posix_memalign
(/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10eaa5)
    #1 0x5627781c130d in ngx_memalign src/os/unix/ngx_alloc.c:57
    #2 0x5627781231ef in ngx_palloc_block src/core/ngx_palloc.c:186
    #3 0x562778123166 in ngx_palloc_small src/core/ngx_palloc.c:173
    #4 0x562778122f91 in ngx_palloc src/core/ngx_palloc.c:127
    #5 0x562778123957 in ngx_pcalloc src/core/ngx_palloc.c:302
    #6 0x562778126bba in ngx_hash_init src/core/ngx_hash.c:392
    #7 0x562778281545 in ngx_http_variables_init_vars
src/http/ngx_http_variables.c:2730
    #8 0x56277821470b in ngx_http_block src/http/ngx_http.c:314
    #9 0x56277817679d in ngx_conf_handler src/core/ngx_conf_file.c:463
    #10 0x5627781757c4 in ngx_conf_parse src/core/ngx_conf_file.c:319
    #11 0x56277816b106 in ngx_init_cycle src/core/ngx_cycle.c:275
    #12 0x5627781188ae in main src/core/nginx.c:291
    #13 0x7f36e7fa40b2 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

Indirect leak of 16384 byte(s) in 1 object(s) allocated from:
    #0 0x7f36e86dbaa5 in posix_memalign
(/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10eaa5)
    #1 0x5627781c130d in ngx_memalign src/os/unix/ngx_alloc.c:57
    #2 0x5627781231ef in ngx_palloc_block src/core/ngx_palloc.c:186
    #3 0x562778123166 in ngx_palloc_small src/core/ngx_palloc.c:173
    #4 0x562778122f91 in ngx_palloc src/core/ngx_palloc.c:127
    #5 0x562778123957 in ngx_pcalloc src/core/ngx_palloc.c:302
    #6 0x5627783dfe02 in ngx_http_scgi_create_loc_conf
src/http/modules/ngx_http_scgi_module.c:1232
    #7 0x56277822dbd8 in ngx_http_core_location
src/http/ngx_http_core_module.c:2968
    #8 0x56277817679d in ngx_conf_handler src/core/ngx_conf_file.c:463
    #9 0x5627781757c4 in ngx_conf_parse src/core/ngx_conf_file.c:319
    #10 0x56277822cfe6 in ngx_http_core_server
src/http/ngx_http_core_module.c:2875
    #11 0x56277817679d in ngx_conf_handler src/core/ngx_conf_file.c:463
    #12 0x5627781757c4 in ngx_conf_parse src/core/ngx_conf_file.c:319
    #13 0x562778213db5 in ngx_http_block src/http/ngx_http.c:237
    #14 0x56277817679d in ngx_conf_handler src/core/ngx_conf_file.c:463
    #15 0x5627781757c4 in ngx_conf_parse src/core/ngx_conf_file.c:319
    #16 0x56277816b106 in ngx_init_cycle src/core/ngx_cycle.c:275
    #17 0x5627781188ae in main src/core/nginx.c:291
    #18 0x7f36e7fa40b2 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

Indirect leak of 16384 byte(s) in 1 object(s) allocated from:
    #0 0x7f36e86dbaa5 in posix_memalign
(/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10eaa5)
    #1 0x5627781c130d in ngx_memalign src/os/unix/ngx_alloc.c:57
    #2 0x5627781231ef in ngx_palloc_block src/core/ngx_palloc.c:186
    #3 0x562778123166 in ngx_palloc_small src/core/ngx_palloc.c:173
    #4 0x562778122f91 in ngx_palloc src/core/ngx_palloc.c:127
    #5 0x562778123957 in ngx_pcalloc src/core/ngx_palloc.c:302
    #6 0x5627783d1c12 in ngx_http_uwsgi_create_loc_conf
src/http/modules/ngx_http_uwsgi_module.c:1443
    #7 0x5627782b22d9 in ngx_http_upstream src/http/ngx_http_upstream.c:5805
    #8 0x56277817679d in ngx_conf_handler src/core/ngx_conf_file.c:463
    #9 0x5627781757c4 in ngx_conf_parse src/core/ngx_conf_file.c:319
    #10 0x562778213db5 in ngx_http_block src/http/ngx_http.c:237
    #11 0x56277817679d in ngx_conf_handler src/core/ngx_conf_file.c:463
    #12 0x5627781757c4 in ngx_conf_parse src/core/ngx_conf_file.c:319
    #13 0x56277816b106 in ngx_init_cycle src/core/ngx_cycle.c:275
    #14 0x5627781188ae in main src/core/nginx.c:291
    #15 0x7f36e7fa40b2 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

Indirect leak of 16384 byte(s) in 1 object(s) allocated from:
    #0 0x7f36e86dbaa5 in posix_memalign
(/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10eaa5)
    #1 0x5627781c130d in ngx_memalign src/os/unix/ngx_alloc.c:57
    #2 0x5627781225ac in ngx_create_pool src/core/ngx_palloc.c:23
    #3 0x562778169b2d in ngx_init_cycle src/core/ngx_cycle.c:69
    #4 0x5627781188ae in main src/core/nginx.c:291
    #5 0x7f36e7fa40b2 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

Indirect leak of 8192 byte(s) in 1 object(s) allocated from:
    #0 0x7f36e86dabc8 in malloc
(/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10dbc8)
    #1 0x5627781c10fb in ngx_alloc src/os/unix/ngx_alloc.c:22
    #2 0x562778123488 in ngx_palloc_large src/core/ngx_palloc.c:220
    #3 0x562778122fa6 in ngx_palloc src/core/ngx_palloc.c:131
    #4 0x56277812479e in ngx_array_push src/core/ngx_array.c:76
    #5 0x5627781293c2 in ngx_hash_add_key src/core/ngx_hash.c:840
    #6 0x5627782747a6 in ngx_http_add_variable
src/http/ngx_http_variables.c:468
    #7 0x562778384f28 in ngx_http_map_block
src/http/modules/ngx_http_map_module.c:230
    #8 0x56277817679d in ngx_conf_handler src/core/ngx_conf_file.c:463
    #9 0x5627781757c4 in ngx_conf_parse src/core/ngx_conf_file.c:319
    #10 0x562778213db5 in ngx_http_block src/http/ngx_http.c:237
    #11 0x56277817679d in ngx_conf_handler src/core/ngx_conf_file.c:463
    #12 0x5627781757c4 in ngx_conf_parse src/core/ngx_conf_file.c:319
    #13 0x56277816b106 in ngx_init_cycle src/core/ngx_cycle.c:275
    #14 0x5627781188ae in main src/core/nginx.c:291
    #15 0x7f36e7fa40b2 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

Indirect leak of 6464 byte(s) in 1 object(s) allocated from:
    #0 0x7f36e86dabc8 in malloc
(/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10dbc8)
    #1 0x5627781c10fb in ngx_alloc src/os/unix/ngx_alloc.c:22
    #2 0x562778123488 in ngx_palloc_large src/core/ngx_palloc.c:220
    #3 0x562778122fa6 in ngx_palloc src/core/ngx_palloc.c:131
    #4 0x562778126c4a in ngx_hash_init src/core/ngx_hash.c:399
    #5 0x562778281545 in ngx_http_variables_init_vars
src/http/ngx_http_variables.c:2730
    #6 0x56277821470b in ngx_http_block src/http/ngx_http.c:314
    #7 0x56277817679d in ngx_conf_handler src/core/ngx_conf_file.c:463
    #8 0x5627781757c4 in ngx_conf_parse src/core/ngx_conf_file.c:319
    #9 0x56277816b106 in ngx_init_cycle src/core/ngx_cycle.c:275
    #10 0x5627781188ae in main src/core/nginx.c:291
    #11 0x7f36e7fa40b2 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

Indirect leak of 4280 byte(s) in 1 object(s) allocated from:
    #0 0x7f36e86dabc8 in malloc
(/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10dbc8)
    #1 0x5627781c10fb in ngx_alloc src/os/unix/ngx_alloc.c:22
    #2 0x562778123488 in ngx_palloc_large src/core/ngx_palloc.c:220
    #3 0x562778122fa6 in ngx_palloc src/core/ngx_palloc.c:131
    #4 0x562778123957 in ngx_pcalloc src/core/ngx_palloc.c:302
    #5 0x5627781288aa in ngx_hash_keys_array_init src/core/ngx_hash.c:723
    #6 0x5627782803af in ngx_http_variables_add_core_vars
src/http/ngx_http_variables.c:2608
    #7 0x56277822fd37 in ngx_http_core_preconfiguration
src/http/ngx_http_core_module.c:3262
    #8 0x562778213c81 in ngx_http_block src/http/ngx_http.c:227
    #9 0x56277817679d in ngx_conf_handler src/core/ngx_conf_file.c:463
    #10 0x5627781757c4 in ngx_conf_parse src/core/ngx_conf_file.c:319
    #11 0x56277816b106 in ngx_init_cycle src/core/ngx_cycle.c:275
    #12 0x5627781188ae in main src/core/nginx.c:291
    #13 0x7f36e7fa40b2 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

Indirect leak of 4280 byte(s) in 1 object(s) allocated from:
    #0 0x7f36e86dabc8 in malloc
(/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10dbc8)
    #1 0x5627781c10fb in ngx_alloc src/os/unix/ngx_alloc.c:22
    #2 0x562778123488 in ngx_palloc_large src/core/ngx_palloc.c:220
    #3 0x562778122fa6 in ngx_palloc src/core/ngx_palloc.c:131
    #4 0x562778123957 in ngx_pcalloc src/core/ngx_palloc.c:302
    #5 0x5627781287f3 in ngx_hash_keys_array_init src/core/ngx_hash.c:717
    #6 0x5627782803af in ngx_http_variables_add_core_vars
src/http/ngx_http_variables.c:2608
    #7 0x56277822fd37 in ngx_http_core_preconfiguration
src/http/ngx_http_core_module.c:3262
    #8 0x562778213c81 in ngx_http_block src/http/ngx_http.c:227
    #9 0x56277817679d in ngx_conf_handler src/core/ngx_conf_file.c:463
    #10 0x5627781757c4 in ngx_conf_parse src/core/ngx_conf_file.c:319
    #11 0x56277816b106 in ngx_init_cycle src/core/ngx_cycle.c:275
    #12 0x5627781188ae in main src/core/nginx.c:291
    #13 0x7f36e7fa40b2 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

Indirect leak of 4280 byte(s) in 1 object(s) allocated from:
    #0 0x7f36e86dabc8 in malloc
(/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10dbc8)
    #1 0x5627781c10fb in ngx_alloc src/os/unix/ngx_alloc.c:22
    #2 0x562778123488 in ngx_palloc_large src/core/ngx_palloc.c:220
    #3 0x562778122fa6 in ngx_palloc src/core/ngx_palloc.c:131
    #4 0x562778123957 in ngx_pcalloc src/core/ngx_palloc.c:302
    #5 0x56277812873c in ngx_hash_keys_array_init src/core/ngx_hash.c:712
    #6 0x5627782803af in ngx_http_variables_add_core_vars
src/http/ngx_http_variables.c:2608
    #7 0x56277822fd37 in ngx_http_core_preconfiguration
src/http/ngx_http_core_module.c:3262
    #8 0x562778213c81 in ngx_http_block src/http/ngx_http.c:227
    #9 0x56277817679d in ngx_conf_handler src/core/ngx_conf_file.c:463
    #10 0x5627781757c4 in ngx_conf_parse src/core/ngx_conf_file.c:319
    #11 0x56277816b106 in ngx_init_cycle src/core/ngx_cycle.c:275
    #12 0x5627781188ae in main src/core/nginx.c:291
    #13 0x7f36e7fa40b2 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

Indirect leak of 4096 byte(s) in 1 object(s) allocated from:
    #0 0x7f36e86dabc8 in malloc
(/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10dbc8)
    #1 0x5627781c10fb in ngx_alloc src/os/unix/ngx_alloc.c:22
    #2 0x562778123488 in ngx_palloc_large src/core/ngx_palloc.c:220
    #3 0x562778122fa6 in ngx_palloc src/core/ngx_palloc.c:131
    #4 0x56277812479e in ngx_array_push src/core/ngx_array.c:76
    #5 0x5627781293c2 in ngx_hash_add_key src/core/ngx_hash.c:840
    #6 0x5627782747a6 in ngx_http_add_variable
src/http/ngx_http_variables.c:468
    #7 0x56277828046b in ngx_http_variables_add_core_vars
src/http/ngx_http_variables.c:2622
    #8 0x56277822fd37 in ngx_http_core_preconfiguration
src/http/ngx_http_core_module.c:3262
    #9 0x562778213c81 in ngx_http_block src/http/ngx_http.c:227
    #10 0x56277817679d in ngx_conf_handler src/core/ngx_conf_file.c:463
    #11 0x5627781757c4 in ngx_conf_parse src/core/ngx_conf_file.c:319
    #12 0x56277816b106 in ngx_init_cycle src/core/ngx_cycle.c:275
    #13 0x5627781188ae in main src/core/nginx.c:291
    #14 0x7f36e7fa40b2 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

SUMMARY: AddressSanitizer: 129896 byte(s) leaked in 12 allocation(s).



реально утечки )) ?
----------- следущая часть -----------
Вложение в формате HTML было извлечено…
URL: <http://mailman.nginx.org/pipermail/nginx-ru/attachments/20200904/9dc72374/attachment-0001.htm>


Подробная информация о списке рассылки nginx-ru