As noted in MDEV-20377, MemorySanitizer (cmake -DWITH_MSAN=ON) requires that all libraries be instrumented, with the possible exception of libc. Currently, libmariadb insists on linking with GNUTLS instead of WolfSSL, which we can easily build ourselves by specifying -DWITH_SSL=bundled.
An instrumented library is a must-have for WITH_MSAN builds, and it would also improve the coverage of other sanitizers (WITH_ASAN, WITH_UBSAN, WITH_TSAN).
Because libmariadb is normally licensed under the GNU LGPL version 2, which WolfSSL is believed to be incompatible with, we could consider introducing some configuration parameter, similar to the existing cmake flag NOT_FOR_DISTRIBUTION. That flag is already being used in cmake/readline.cmake and cmake/aws_sdk.cmake. However, its purpose appears to allow something GPLv2 incompatible to be built, while here the result should still be GPLv2 compatible while being LGPLv2 incompatible. Perhaps the option should be called NOT_LGPL or similar, and it should apply to Connector/C only, not to the MariaDB server?
Attachments
Issue Links
relates to
MDEV-18531Use WolfSSL instead of YaSSL as "bundled" SSL
Closed
MDEV-21835Implement option 'system-wolfssl' in build flag WITH_SSL
Closed
MDEV-26761main.mysql_client_test test_mdev19838 fails with MemorySanitizer
Marko Mäkelä
added a comment - The following patch made the trick:
--- config.h.in 2021-06-06 23:06:29.000000000 +0300
+++ config.h.in 2021-10-04 16:09:18.636629855 +0300
@@ -45,9 +45,6 @@
/* Define to 1 if you have the `gmp' library (-lgmp). */
#undef HAVE_LIBGMP
-/* Define if compiler and linker supports __attribute__ ifunc */
-#undef HAVE_LINK_IFUNC
-
/* Define to 1 if you have the <malloc.h> header file. */
#undef HAVE_MALLOC_H
And we got the next error:
CURRENT_TEST: main.userstat
==929302==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x7fb162bd545a in decrypt_packet_tls13 /mariadb/gnutls28-3.7.2/lib/cipher.c:899:27
#1 0x7fb162bd545a in _gnutls_decrypt /mariadb/gnutls28-3.7.2/lib/cipher.c:157:7
It looks like we have to rebuild gnutls28 once more:
cd gnutls28-3.7.2
CC=clang-11 CXX=clang++-11 ./configure C{,XX}FLAGS="-fno-omit-frame-pointer -O2 -g -fsanitize=memory" LDFLAGS="-fsanitize=memory" --with-included-libtasn1 --with-included-unistring --without-p11-kit --disable-hardware-acceleration
automake --add-missing
make clean
make -j$(nproc)
..
And that was it, for this test:
main.userstat 'innodb' [ pass ] 1345
mysqltest: At line 21: query 'reap' failed: 1290: The MariaDB server is running with the --max-thread-mem-used=45500 option so it cannot execute this statement
The result from queries just before the failure was:
SELECT VARIABLE_VALUE-@local_mem_used FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='MEMORY_USED';
VARIABLE_VALUE-@local_mem_used
-0
+640
DROP PROCEDURE sp1;
# End of 10.3 tests
#
mysqltest: Result length mismatch
- saving '/dev/shm/10.5msan/mysql-test/var/2/log/main.sp/' to '/dev/shm/10.5msan/mysql-test/var/log/main.sp/'
Furthermore, the test innodb.alter_large_dml tends to trigger DEBUG_SYNC timeout.
Marko Mäkelä
added a comment - Some genuine errors were caught in mysql_client_test.c . This broke the tests main.mysql_client_test_nonblock main.mysql_client_test main.mysql_client_test_comp .
We still have the following failures:
10.5 ead38354e60e0fb241de8abe0ed6a57c14dfb820
main.truncate_notembedded w3 [ fail ]
Test ended at 2021-10-04 19:52:02
CURRENT_TEST: main.truncate_notembedded
mysqltest: At line 21: query 'reap' failed: 1290: The MariaDB server is running with the --max-thread-mem-used=45500 option so it cannot execute this statement
The result from queries just before the failure was:
#
# MDEV-23365: Assertion `!is_set() || (m_status == DA_OK_BULK &&
# is_bulk_op())' failed upon killed TRUNCATE
#
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
LOCK TABLE t1 READ;
connect con1,localhost,root,,test;
SET SESSION max_session_mem_used= 45500;
LOCK TABLE t1 WRITE;cause
connection default;
SELECT * FROM t1;
a
UNLOCK TABLES;
connection con1;
- saving '/dev/shm/10.5msan/mysql-test/var/3/log/main.truncate_notembedded/' to '/dev/shm/10.5msan/mysql-test/var/log/main.truncate_notembedded/'
main.sp w2 [ fail ]
Test ended at 2021-10-04 19:52:15
CURRENT_TEST: main.sp
/dev/shm/10.5msan/client/mysqltest: Error on delete of '/dev/shm/10.5msan/mysql-test/var/2/tmp//t1.frm' (Errcode: 2 "No such file or directory")
/dev/shm/10.5msan/client/mysqltest: Error on delete of '/dev/shm/10.5msan/mysql-test/var/2/tmp//t1.MYD' (Errcode: 2 "No such file or directory")
--- /mariadb/10.5m/mysql-test/main/sp.result 2021-10-04 12:13:51.991511056 +0300
+++ /mariadb/10.5m/mysql-test/main/sp.reject 2021-10-04 19:52:15.586545147 +0300
@@ -8889,7 +8889,7 @@
SELECT 1 latin1 latin1_swedish_ci latin1_swedish_ci
SELECT VARIABLE_VALUE-@local_mem_used FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='MEMORY_USED';
VARIABLE_VALUE-@local_mem_used
-0
+640
DROP PROCEDURE sp1;
# End of 10.3 tests
#
mysqltest: Result length mismatch
- saving '/dev/shm/10.5msan/mysql-test/var/2/log/main.sp/' to '/dev/shm/10.5msan/mysql-test/var/log/main.sp/'
Furthermore, the test innodb.alter_large_dml tends to trigger DEBUG_SYNC timeout.
Here is proof that the test innodb.alter_large_dml sometimes passes with MemorySanitizer. This run was only with --parallel=3. Normally, with much more concurrent tests, the test would almost always timeout.
Marko Mäkelä
added a comment - Here is proof that the test innodb.alter_large_dml sometimes passes with MemorySanitizer. This run was only with --parallel=3 . Normally, with much more concurrent tests, the test would almost always timeout.
10.5 ead38354e60e0fb241de8abe0ed6a57c14dfb820
innodb.alter_large_dml 'innodb' w1 [ pass ] 209421
The server error log would contain the following:
2021-10-04 19:52:01 0 [Note] InnoDB: 10.5.13 started; log sequence number 47822; transaction id 27
…
2021-10-04 19:55:32 0 [Note] InnoDB: Shutdown completed; log sequence number 785123071; transaction id 57
2021-10-04 19:55:32 0 [Note] Debug sync points hit: 2568158
2021-10-04 19:55:32 0 [Note] Debug sync points executed: 8
2021-10-04 19:55:32 0 [Note] Debug sync points max active per thread: 3
2021-10-04 19:55:32 0 [Note] /dev/shm/10.5msan/sql/mariadbd: Shutdown complete
I attached a script build-msan.sh in MDEV-20377 for building all dependencies using the specified version of clang. I tested it on clang version 13 today. Previously I was using version 11 for MemorySanitizer builds.
Marko Mäkelä
added a comment - I attached a script build-msan.sh in MDEV-20377 for building all dependencies using the specified version of clang . I tested it on clang version 13 today. Previously I was using version 11 for MemorySanitizer builds.
Starting with clang-14, llvm-symbolizer depends on libgmp. Therefore, it will fail to work if LD_LIBRARY_PATH points to something that includes an MSAN instrumented libgmp. As noted in MDEV-30936, this can be resolved by making the environment variable MSAN_SYMBOLIZER_PATH point to a simple wrapper script:
#!/bin/sh
unset LD_LIBRARY_PATH
exec llvm-symbolizer-15 "$@"
For clang-15, there is another script build-msan15.sh attached to MDEV-20377.
Marko Mäkelä
added a comment - Starting with clang-14 , llvm-symbolizer depends on libgmp . Therefore, it will fail to work if LD_LIBRARY_PATH points to something that includes an MSAN instrumented libgmp . As noted in MDEV-30936 , this can be resolved by making the environment variable MSAN_SYMBOLIZER_PATH point to a simple wrapper script:
#!/bin/sh
unset LD_LIBRARY_PATH
exec llvm-symbolizer-15 "$@"
For clang-15 , there is another script build-msan15.sh attached to MDEV-20377 .
People
Marko Mäkelä
Marko Mäkelä
Votes:
0Vote for this issue
Watchers:
11Start watching this issue
Dates
Created:
Updated:
Resolved:
Git Integration
Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.
{"report":{"fcp":1813.5999999046326,"ttfb":717.8999998569489,"pageVisibility":"visible","entityId":84830,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"6ae6247f-70fb-4d6a-abb2-91f00d029686","navigationType":0,"readyForUser":2040.5,"redirectCount":0,"resourceLoadedEnd":1983.5,"resourceLoadedStart":731.3999998569489,"resourceTiming":[{"duration":455,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":731.3999998569489,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":731.3999998569489,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1186.3999998569489,"responseStart":0,"secureConnectionStart":0},{"duration":455.10000014305115,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/2bf333562ca6724060a9d5f1535471f6/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":731.5999999046326,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":731.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1186.7000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":465.7000000476837,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":731.7999999523163,"connectEnd":731.7999999523163,"connectStart":731.7999999523163,"domainLookupEnd":731.7999999523163,"domainLookupStart":731.7999999523163,"fetchStart":731.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":731.7999999523163,"responseEnd":1197.5,"responseStart":1197.5,"secureConnectionStart":731.7999999523163},{"duration":548.2999999523163,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/2bf333562ca6724060a9d5f1535471f6/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":732,"connectEnd":732,"connectStart":732,"domainLookupEnd":732,"domainLookupStart":732,"fetchStart":732,"redirectEnd":0,"redirectStart":0,"requestStart":732,"responseEnd":1280.2999999523163,"responseStart":1280.2999999523163,"secureConnectionStart":732},{"duration":551.6999998092651,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":732.2000000476837,"connectEnd":732.2000000476837,"connectStart":732.2000000476837,"domainLookupEnd":732.2000000476837,"domainLookupStart":732.2000000476837,"fetchStart":732.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":732.2000000476837,"responseEnd":1283.8999998569489,"responseStart":1283.8999998569489,"secureConnectionStart":732.2000000476837},{"duration":552.2000000476837,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":732.2999999523163,"connectEnd":732.2999999523163,"connectStart":732.2999999523163,"domainLookupEnd":732.2999999523163,"domainLookupStart":732.2999999523163,"fetchStart":732.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":732.2999999523163,"responseEnd":1284.5,"responseStart":1284.5,"secureConnectionStart":732.2999999523163},{"duration":552.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":732.5,"connectEnd":732.5,"connectStart":732.5,"domainLookupEnd":732.5,"domainLookupStart":732.5,"fetchStart":732.5,"redirectEnd":0,"redirectStart":0,"requestStart":732.5,"responseEnd":1285,"responseStart":1285,"secureConnectionStart":732.5},{"duration":623.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":732.5999999046326,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":732.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1356.0999999046326,"responseStart":0,"secureConnectionStart":0},{"duration":552.7999999523163,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":732.7999999523163,"connectEnd":732.7999999523163,"connectStart":732.7999999523163,"domainLookupEnd":732.7999999523163,"domainLookupStart":732.7999999523163,"fetchStart":732.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":732.7999999523163,"responseEnd":1285.5999999046326,"responseStart":1285.5999999046326,"secureConnectionStart":732.7999999523163},{"duration":623.2999999523163,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":733,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":733,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1356.2999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":553.1000001430511,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":733.0999999046326,"connectEnd":733.0999999046326,"connectStart":733.0999999046326,"domainLookupEnd":733.0999999046326,"domainLookupStart":733.0999999046326,"fetchStart":733.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":733.0999999046326,"responseEnd":1286.2000000476837,"responseStart":1286.2000000476837,"secureConnectionStart":733.0999999046326},{"duration":909.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":739.7999999523163,"connectEnd":739.7999999523163,"connectStart":739.7999999523163,"domainLookupEnd":739.7999999523163,"domainLookupStart":739.7999999523163,"fetchStart":739.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":739.7999999523163,"responseEnd":1649.2999999523163,"responseStart":1649.2999999523163,"secureConnectionStart":739.7999999523163},{"duration":1243.6000001430511,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":739.8999998569489,"connectEnd":739.8999998569489,"connectStart":739.8999998569489,"domainLookupEnd":739.8999998569489,"domainLookupStart":739.8999998569489,"fetchStart":739.8999998569489,"redirectEnd":0,"redirectStart":0,"requestStart":739.8999998569489,"responseEnd":1983.5,"responseStart":1983.5,"secureConnectionStart":739.8999998569489},{"duration":248.20000004768372,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1401.5,"connectEnd":1401.5,"connectStart":1401.5,"domainLookupEnd":1401.5,"domainLookupStart":1401.5,"fetchStart":1401.5,"redirectEnd":0,"redirectStart":0,"requestStart":1401.5,"responseEnd":1649.7000000476837,"responseStart":1649.7000000476837,"secureConnectionStart":1401.5}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":118,"responseStart":718,"responseEnd":731,"domLoading":730,"domInteractive":2147,"domContentLoadedEventStart":2147,"domContentLoadedEventEnd":2209,"domComplete":2864,"loadEventStart":2864,"loadEventEnd":2865,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":2100.899999856949},{"name":"bigPipe.sidebar-id.end","time":2102.2000000476837},{"name":"bigPipe.activity-panel-pipe-id.start","time":2102.399999856949},{"name":"bigPipe.activity-panel-pipe-id.end","time":2106.5999999046326},{"name":"activityTabFullyLoaded","time":2265}],"measures":[],"correlationId":"bb643f49acc509","effectiveType":"4g","downlink":9.5,"rtt":0,"serverDuration":130,"dbReadsTimeInMs":15,"dbConnsTimeInMs":24,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
The following patch made the trick:
--- config.h.in 2021-06-06 23:06:29.000000000 +0300
+++ config.h.in 2021-10-04 16:09:18.636629855 +0300
@@ -45,9 +45,6 @@
/* Define to 1 if you have the `gmp' library (-lgmp). */
#undef HAVE_LIBGMP
-/* Define if compiler and linker supports __attribute__ ifunc */
-#undef HAVE_LINK_IFUNC
-
/* Define to 1 if you have the <malloc.h> header file. */
#undef HAVE_MALLOC_H
And we got the next error:
CURRENT_TEST: main.userstat
==929302==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x7fb162bd545a in decrypt_packet_tls13 /mariadb/gnutls28-3.7.2/lib/cipher.c:899:27
#1 0x7fb162bd545a in _gnutls_decrypt /mariadb/gnutls28-3.7.2/lib/cipher.c:157:7
It looks like we have to rebuild gnutls28 once more:
cd gnutls28-3.7.2
CC=clang-11 CXX=clang++-11 ./configure C{,XX}FLAGS="-fno-omit-frame-pointer -O2 -g -fsanitize=memory" LDFLAGS="-fsanitize=memory" --with-included-libtasn1 --with-included-unistring --without-p11-kit --disable-hardware-acceleration
automake --add-missing
make clean
make -j$(nproc)
..
And that was it, for this test:
main.userstat 'innodb' [ pass ] 1345