Skip to content

Commit b120e22

Browse files
author
Tor Didriksen
committed
Bug#28897799 BACKPORT TO 5.7: WORKAROUND ASAN BUG FOR TIRPC
This is a backport of: Bug#28785835 WORKAROUND ASAN BUG FOR TIRPC Sun RPC, and XDR, is being removed from glibc, and into a separate libtirpc library. This is not compatible with libasan. The interceptor functions inserted into the code will segfault. As a workaround, do LD_PRELOAD=/lib64/libtirpc.so For dynamically linked libasan (default for gcc), we must preload that as well. This currently affects fedora, but will likely also affect other linux variants in the future. This patch also enables ASAN suppressions in asan.supp This patch also enables LSAN suppressions in lsan.supp Change-Id: I1bc777482535ce21595a48ae12679c325667d722 (cherry picked from commit aa9698313b6d412265608fe9f1ffc05938448f81)
1 parent ade9927 commit b120e22

File tree

6 files changed

+126
-4
lines changed

6 files changed

+126
-4
lines changed

mysql-test/asan.supp

+17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
# Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
2+
#
3+
# This program is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License as published by
5+
# the Free Software Foundation; version 2 of the License.
6+
#
7+
# This program is distributed in the hope that it will be useful,
8+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
# GNU General Public License for more details.
11+
#
12+
# You should have received a copy of the GNU General Public License
13+
# along with this program; if not, write to the Free Software
14+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15+
16+
# ASAN suppressions for gcc/clang
17+
118
# Warning: this works for clang-3.7 and later
219
odr_violation:*yaSSL*
320
odr_violation:*TaoCrypt*

mysql-test/lib/My/SafeProcess/CMakeLists.txt

+42-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
2-
#
1+
# Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
2+
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License as published by
55
# the Free Software Foundation; version 2 of the License.
@@ -22,13 +22,53 @@ SET(INSTALL_ARGS
2222
COMPONENT Test
2323
)
2424

25+
UNSET(HAVE_TIRPC)
26+
# rpcgen.cmake will store RPC_INCLUDE_DIR in the cache
27+
IF(RPC_INCLUDE_DIR STREQUAL "/usr/include/tirpc")
28+
ADD_DEFINITIONS(-DHAVE_TIRPC)
29+
SET(HAVE_TIRPC 1)
30+
ENDIF()
31+
2532
IF (WIN32)
2633
MYSQL_ADD_EXECUTABLE(my_safe_process safe_process_win.cc ${INSTALL_ARGS})
2734
MYSQL_ADD_EXECUTABLE(my_safe_kill safe_kill_win.cc ${INSTALL_ARGS})
2835
ELSE()
2936
MYSQL_ADD_EXECUTABLE(my_safe_process safe_process.cc ${INSTALL_ARGS})
3037
ENDIF()
3138

39+
# Sun RPC, and XDR, is being removed from glibc, and into a separate libtirpc
40+
# library. This is not compatible with libasan. The interceptor functions
41+
# inserted into the code will segfault.
42+
# As a workaround, do LD_PRELOAD=/lib64/libtirpc.so
43+
# For dynamically linked libasan (default for gcc), we must preload that as well
44+
IF(HAVE_ASAN AND HAVE_TIRPC)
45+
TARGET_INCLUDE_DIRECTORIES(my_safe_process
46+
PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
47+
48+
ADD_CUSTOM_COMMAND(
49+
OUTPUT asan_test.c
50+
COMMAND ${CMAKE_COMMAND} -E echo "int main() { return 0; }" > asan_test.c
51+
VERBATIM
52+
)
53+
SET_SOURCE_FILES_PROPERTIES(asan_test.c PROPERTIES GENERATED TRUE)
54+
55+
ADD_EXECUTABLE(asan_test asan_test.c)
56+
ADD_CUSTOM_COMMAND(
57+
OUTPUT ldd_asan_test_result
58+
DEPENDS asan_test
59+
COMMAND ldd asan_test > ldd_asan_test_result)
60+
61+
ADD_CUSTOM_TARGET(extract_asan_library_name
62+
DEPENDS ldd_asan_test_result
63+
COMMAND ${CMAKE_COMMAND}
64+
-DINFILE=${CMAKE_CURRENT_BINARY_DIR}/ldd_asan_test_result
65+
-DOUTFILE=${CMAKE_CURRENT_BINARY_DIR}/asan_library_name.h
66+
-P ${CMAKE_CURRENT_SOURCE_DIR}/read_ldd_output.cmake
67+
)
68+
69+
ADD_DEPENDENCIES(my_safe_process extract_asan_library_name)
70+
ENDIF()
71+
3272
INSTALL(TARGETS my_safe_process
3373
DESTINATION "${INSTALL_MYSQLTESTDIR}/lib/My/SafeProcess" COMPONENT Test
3474
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
#
3+
# This program is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License as published by
5+
# the Free Software Foundation; version 2 of the License.
6+
#
7+
# This program is distributed in the hope that it will be useful,
8+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
# GNU General Public License for more details.
11+
#
12+
# You should have received a copy of the GNU General Public License
13+
# along with this program; if not, write to the Free Software
14+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15+
16+
FILE(READ ${INFILE} LDD_FILE_CONTENTS)
17+
STRING(REPLACE "\n" ";" LDD_FILE_LINES ${LDD_FILE_CONTENTS})
18+
19+
SET(ASAN_LIBRARY_NAME)
20+
FOREACH(LINE ${LDD_FILE_LINES})
21+
STRING(REGEX MATCH "^[\t ]*(libasan.so.[0-9]) => ([/a-z0-9.]+)" XXX ${LINE})
22+
IF(CMAKE_MATCH_1)
23+
# MESSAGE(STATUS "LINE ${LINE}")
24+
# MESSAGE(STATUS "XXX ${XXX}")
25+
# MESSAGE(STATUS "CMAKE_MATCH_1 ${CMAKE_MATCH_1}")
26+
# MESSAGE(STATUS "CMAKE_MATCH_2 ${CMAKE_MATCH_2}")
27+
SET(ASAN_LIBRARY_NAME ${CMAKE_MATCH_2})
28+
ENDIF()
29+
ENDFOREACH()
30+
FILE(WRITE ${OUTFILE}
31+
"const char *asan_library_name=\"${ASAN_LIBRARY_NAME}\";")

mysql-test/lib/My/SafeProcess/safe_process.cc

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -54,6 +54,9 @@
5454
#include <signal.h>
5555
#include <string.h>
5656
#include <errno.h>
57+
#include <string>
58+
59+
#include "my_config.h"
5760

5861
int verbose= 0;
5962
volatile sig_atomic_t terminated= 0;
@@ -293,6 +296,16 @@ int main(int argc, char* const argv[] )
293296
// Close write end
294297
close(pfd[1]);
295298

299+
#if defined(HAVE_ASAN) && defined(HAVE_TIRPC)
300+
#include "asan_library_name.h"
301+
std::string ld_preload = "LD_PRELOAD=";
302+
if (strlen(asan_library_name) > 0) {
303+
ld_preload.append(asan_library_name);
304+
ld_preload.append(":");
305+
}
306+
ld_preload.append("/lib64/libtirpc.so");
307+
putenv(strdup(ld_preload.c_str()));
308+
#endif
296309
if (execvp(child_argv[0], child_argv) < 0)
297310
die("Failed to exec child");
298311
}

mysql-test/lsan.supp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
#
3+
# This program is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License as published by
5+
# the Free Software Foundation; version 2 of the License.
6+
#
7+
# This program is distributed in the hope that it will be useful,
8+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
# GNU General Public License for more details.
11+
#
12+
# You should have received a copy of the GNU General Public License
13+
# along with this program; if not, write to the Free Software
14+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15+
16+
# LSAN suppressions for gcc/clang
17+
leak:Perl_safesyscalloc
18+
leak:Perl_safesysmalloc
19+
leak:Perl_safesysrealloc

mysql-test/mysql-test-run.pl

+3-1
Original file line numberDiff line numberDiff line change
@@ -2854,7 +2854,9 @@ sub environment_setup {
28542854
$ENV{'VALGRIND_TEST'}= $opt_valgrind;
28552855

28562856
# Make sure LeakSanitizer exits if leaks are found
2857-
$ENV{'LSAN_OPTIONS'}= "exitcode=42";
2857+
$ENV{'LSAN_OPTIONS'} = "exitcode=42,suppressions=${glob_mysql_test_dir}/lsan.supp";
2858+
2859+
$ENV{'ASAN_OPTIONS'} = "suppressions=${glob_mysql_test_dir}/asan.supp";
28582860

28592861
# Add dir of this perl to aid mysqltest in finding perl
28602862
my $perldir= dirname($^X);

0 commit comments

Comments
 (0)