Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
10.5.25, 10.11.8
Description
Compile with clang-18 and -DWITH_ASAN=1, this was a RelWithDebInfo build.
main.union |
main.union w1 [ fail ]
|
Test ended at 2024-07-05 00:52:49
|
|
CURRENT_TEST: main.union
|
mysqltest: At line 879: query 'CREATE TABLE t3 SELECT REPEAT(a,20000000) AS a FROM t1 UNION SELECT b FROM t2' failed: <Unknown> (2013): Lost connection to server during query
|
|
The result from queries just before the failure was:
|
< snip >
|
SELECT left(a,100000000) FROM t1 UNION SELECT b FROM t2;
|
left(a,100000000)
|
a
|
b
|
create table t3 SELECT left(a,100000000) FROM t1 UNION SELECT b FROM t2;
|
show create table t3;
|
Table Create Table
|
t3 CREATE TABLE `t3` (
|
`left(a,100000000)` longtext DEFAULT NULL
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
drop tables t1,t2,t3;
|
SET @tmp_max= @@global.max_allowed_packet;
|
SET @@global.max_allowed_packet=25000000;
|
Warnings:
|
Warning 1292 Truncated incorrect max_allowed_packet value: '25000000'
|
connect newconn, localhost, root,,;
|
CREATE TABLE t1 (a mediumtext);
|
CREATE TABLE t2 (b varchar(20));
|
INSERT INTO t1 VALUES ('a');
|
CREATE TABLE t3 SELECT REPEAT(a,20000000) AS a FROM t1 UNION SELECT b FROM t2;
|
|
More results from queries before failure can be found in /home/buildbot/amd64-ubuntu-2404-clang18-asan/build/mysql-test/var/1/log/union.log
|
10.11-3ee6f69d49a58422f994f51a0bd7a0cb1242a3dd |
#6 0x000055fff57cb5eb in __sanitizer::Abort() ()
|
#7 0x000055fff57c9775 in __sanitizer::Die() ()
|
#8 0x000055fff57a9e9f in __asan::ScopedInErrorReport::~ScopedInErrorReport() ()
|
#9 0x000055fff57acf25 in __asan::ReportGenericError(unsigned long, unsigned long, unsigned long, unsigned long, bool, unsigned long, unsigned int, bool) ()
|
#10 0x000055fff57a2fba in __asan_memcpy ()
|
#11 0x000055fff66070e2 in _ma_rec_pack (info=info@entry=0x529000dbb218, to=0x7fec5922307a "", to@entry=0x7fec59223078 "", from=0x519000234ce1 "", from@entry=0x519000234ce0 "\376") at /home/buildbot/amd64-ubuntu-2404-clang18-asan/build/storage/maria/ma_dynrec.c:1013
|
#12 0x000055fff6608878 in _ma_write_blob_record (info=0x529000dbb218, record=0x519000234ce0 "\376") at /home/buildbot/amd64-ubuntu-2404-clang18-asan/build/storage/maria/ma_dynrec.c:266
|
#13 0x000055fff66da4fe in maria_write (info=0x529000dbb218, record=<optimized out>) at /home/buildbot/amd64-ubuntu-2404-clang18-asan/build/storage/maria/ma_write.c:284
|
#14 0x000055fff5d1c758 in handler::ha_write_tmp_row (this=0x51d0002544b8, buf=<optimized out>) at /home/buildbot/amd64-ubuntu-2404-clang18-asan/build/sql/sql_class.h:7649
|
#15 select_unit::write_record (this=0x529000e36948) at /home/buildbot/amd64-ubuntu-2404-clang18-asan/build/sql/sql_union.cc:418
|
#16 0x000055fff5d1c055 in select_unit::send_data (this=0x529000e36948, values=...) at /home/buildbot/amd64-ubuntu-2404-clang18-asan/build/sql/sql_union.cc:157
|
#17 0x000055fff5b9fa2e in select_result_sink::send_data_with_check (this=0x2a50f, items=..., u=<optimized out>, sent=<optimized out>) at /home/buildbot/amd64-ubuntu-2404-clang18-asan/build/sql/sql_class.h:5912
|
#18 end_send (join=join@entry=0x529000e36a38, join_tab=join_tab@entry=0x0, end_of_records=<optimized out>) at /home/buildbot/amd64-ubuntu-2404-clang18-asan/build/sql/sql_select.cc:23628
|
#19 0x000055fff5baebdd in do_select (join=join@entry=0x529000e36a38, procedure=<optimized out>) at /home/buildbot/amd64-ubuntu-2404-clang18-asan/build/sql/sql_select.cc:21815
|
#20 0x000055fff5baced7 in JOIN::exec_inner (this=0x529000e36a38) at /home/buildbot/amd64-ubuntu-2404-clang18-asan/build/sql/sql_select.cc:4912
|
#21 0x000055fff5bab0d8 in JOIN::exec (this=0x529000e36a38) at /home/buildbot/amd64-ubuntu-2404-clang18-asan/build/sql/sql_select.cc:4690
|
#22 0x000055fff5d192a3 in st_select_lex_unit::exec (this=0x52b0000c12f0) at /home/buildbot/amd64-ubuntu-2404-clang18-asan/build/sql/sql_union.cc:2248
|
#23 0x000055fff5d12cdf in mysql_union (thd=thd@entry=0x52b0000bd218, lex=<optimized out>, result=result@entry=0x529000e36800, unit=0x52b0000c12f0, setup_tables_done_option=setup_tables_done_option@entry=0) at /home/buildbot/amd64-ubuntu-2404-clang18-asan/build/sql/sql_union.cc:42
|
#24 0x000055fff5b52827 in handle_select (thd=thd@entry=0x52b0000bd218, lex=0x2a596, lex@entry=0x52b0000c1218, result=result@entry=0x529000e36800, setup_tables_done_option=setup_tables_done_option@entry=0) at /home/buildbot/amd64-ubuntu-2404-clang18-asan/build/sql/sql_select.cc:576
|
#25 0x000055fff5cf5128 in Sql_cmd_create_table_like::execute (this=<optimized out>, thd=0x52b0000bd218) at /home/buildbot/amd64-ubuntu-2404-clang18-asan/build/sql/sql_table.cc:12694
|
#26 0x000055fff5ab6c60 in mysql_execute_command (thd=0x52b0000bd218, is_called_from_prepared_stmt=<optimized out>) at /home/buildbot/amd64-ubuntu-2404-clang18-asan/build/sql/sql_parse.cc:6125
|
#27 0x000055fff5aab1f3 in mysql_parse (thd=thd@entry=0x52b0000bd218, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x7fec5965c7c0) at /home/buildbot/amd64-ubuntu-2404-clang18-asan/build/sql/sql_parse.cc:8126
|
#28 0x000055fff5aa6cb5 in dispatch_command (command=<optimized out>, thd=0x52b0000bd218, packet=<optimized out>, packet_length=<optimized out>, blocking=<optimized out>) at /home/buildbot/amd64-ubuntu-2404-clang18-asan/build/sql/sql_parse.cc:1894
|
#29 0x000055fff5aabc92 in do_command (thd=0x52b0000bd218, blocking=true) at /home/buildbot/amd64-ubuntu-2404-clang18-asan/build/sql/sql_parse.cc:1407
|
#30 0x000055fff5e0c61e in do_handle_one_connection (connect=<optimized out>, put_in_cache=<optimized out>) at /home/buildbot/amd64-ubuntu-2404-clang18-asan/build/sql/sql_connect.cc:1415
|
#31 0x000055fff5e0c021 in handle_one_connection (arg=0x508000002738) at /home/buildbot/amd64-ubuntu-2404-clang18-asan/build/sql/sql_connect.cc:1317
|
#32 0x000055fff57a2b3d in asan_thread_start(void*) ()
|
#33 0x00007fec64649a94 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
|
#34 0x00007fec646d6a34 in clone () from /lib/x86_64-linux-gnu/libc.so.6
|
ref: https://buildbot.dev.mariadb.org/#/builders/371/builds/7/steps/7/logs/stdio
Also present on 10.5-9e8546e2bda81c2c97acb1e9f973ff466a82dca7
Attachments
Issue Links
- blocks
-
MDBF-740 bump clang-14 asan builder to use clang 20 (and do ubsan too)
-
- Open
-
- is blocked by
-
MDEV-36412 Concerns compilation issue on community edition for x86_64 with X32 ABI
-
- Open
-
- relates to
-
MDEV-31151 Inaccurate stack size caculation caused stack overflow in pinbox allocator
-
- Closed
-
-
MDEV-33209 Stack overflow in main.json_debug_nonembedded due to incorrect debug injection
-
- Closed
-
The problem here is that when using clang + asan, we do not get a correct value for the thread stack as some local variables are not allocated at the normal stack.
Here follows a longer description and a solution for this issue.
Taking the address of a variable on stack is not always working.
It looks like that for example clang 18.1.3, when compiling with
-O2 -fsanitize=addressan it puts local variables and things allocated by
alloca() in other areas than on the stack.
The following code shows the issue
Thread 6 "mariadbd" hit Breakpoint 3, do_handle_one_connection (connect=0x5080000027b8,
put_in_cache=<optimized out>) at /work/server/sql/sql_connect.cc:1399
THD *thd;
1399 thd->thread_stack= (char*) &thd;
(gdb) p &thd
(THD **) 0x7fffedee7060
(gdb) p $sp
(void *) 0x7fffef4e7bc0
The address of thd is 24M away from the stack pointer
(gdb) info reg
rax 0x52b000080998 90915868248472
rbx 0x7fffef4e7bc0 140737208286144
rcx 0xa5600010133 11364483531059
rdx 0x4 4
rsi 0x7ffff4f000d0 140737302757584
rdi 0x52b00007e218 90915868238360
rbp 0x7fffef4e7c50 0x7fffef4e7c50
rsp 0x7fffef4e7bc0 0x7fffef4e7bc0
r8 0x60 96
r9 0x524000060000 90434831777792
r10 0x7fffffffffff 140737488355327
r11 0x4 4
r12 0x555558e5de60 93825052040800
r13 0x7fffedee7060 140737185214560
r14 0xe1ad14c050 969271459920
r15 0x52b00007e218 90915868238360
rip 0x5555565c07f7 0x5555565c07f7
r13 is pointing to the address of the thd. Probably some kind of "local stack"
used by the sanitizer
I have verified this with gdb on a recursive call that calls alloca() in a loop.
In this case all objects are stored in a local heap, not on the stack.
This makes the sanitizer a bit unpredictable when working with code that
uses alloca() as it does not behave in the same way as code in production that
may fail because of stack over usage.
To get the stack pointer safely, one can use asm functions like:
#include <stdint.h>
{
uint64_t sp;
}
To solve this issue in a portable way, we should add two functions:
my_get_stack_pointer() that will return the address of the current stack pointer.
The proposed solution is using asm instructions for intel 32/64 bit, powerpc, arm 32/64 bit
and sparc 32/64 bit. Supported compilers are gcc and clang and MSCV.
For MSCV 64 bit we are using _AddressOfReturnAddress()
As a fallback for other compilers/arch we use the address of a local variable.
my_get_stack_bounds() that will return the address of the base stack and stack size using
pthread_attr_getstack() or NtCurrentTed() with fallback to using the address of a local
variable and user provided stack size.
Server changes are:
the stack before calling store_globals().
When using estimates for stack start, we reduce stack_size with
MY_STACK_SAFE_MARGIN (8192) to take into account the stack used before
calling store_globals().