Details
-
Bug
-
Status: Open (View Workflow)
-
Critical
-
Resolution: Unresolved
-
12.3, 13.1
-
None
Description
Item_trigger_type_of_statement (INSERTING / UPDATING / DELETING) keeps the THD that parsed the trigger in m_thd and evaluates m_thd->current_active_stmt(). The parsed trigger stays with the cached TABLE, so another connection that reuses it reads the parsing connection's statement stack: the trigger takes the wrong branch while that connection is alive, and reads a freed THD after it disconnects. Same mechanism as MDEV-42409 / MDEV-42410, but needs no plugin or Oracle mode.
Server options: --thread-cache-size=0 (needed only for the use-after-free; with thread cache the freed THD object is reused, and the wrong result remains)
CREATE TABLE t1 (a INT, b VARCHAR(10)); |
--delimiter $
|
CREATE TRIGGER tr BEFORE INSERT OR UPDATE ON t1 FOR EACH ROW |
SET NEW.b= IF(INSERTING, 'INSERTING', IF(UPDATING, 'UPDATING', 'NEITHER'))$ |
--delimiter ;
|
connect (c1,localhost,root,,test); |
INSERT INTO t1 VALUES (1, NULL); |
connection default; |
INSERT INTO t1 VALUES (2, NULL); |
--echo # BUG if row 2 is not INSERTING
|
SELECT * FROM t1; |
disconnect c1;
|
let $wait_condition= SELECT COUNT(*)=1 FROM information_schema.processlist; |
--source include/wait_condition.inc
|
UPDATE t1 SET a= a + 10; |
SELECT * FROM t1; |
DROP TABLE t1; |
12.3.4-MariaDB-asan-debug-log source revision: f74586eebfe2a186087cfdda42be2d0ba398f01c
|
==310331==ERROR: AddressSanitizer: heap-use-after-free on address 0x52c0000b02f0 at pc 0x6485afd72519 bp 0x760f41c03810 sp 0x760f41c03800
|
READ of size 8 at 0x52c0000b02f0 thread T7
|
#0 0x6485afd72518 in Dynamic_array<active_dml_stmt>::back() /12.3/src/sql/sql_array.h:176
|
#1 0x6485afd72518 in Statement::current_active_stmt() /12.3/src/sql/sql_class.cc:4444
|
#2 0x6485b093eff4 in Item_trigger_type_of_statement::val_bool() /12.3/src/sql/item.cc:11297
|
#3 0x6485b09eb28e in Item_func_if::find_item() const /12.3/src/sql/item_cmpfunc.h:1454
|
#4 0x6485b07b6b9a in Item_func_case_abbreviation2_switch::str_op(String*) /12.3/src/sql/item_cmpfunc.h:1436
|
#5 0x6485b065fa93 in Item_func_hybrid_field_type::str_op_with_null_check(String*) /12.3/src/sql/item_func.h:969
|
#6 0x6485b062ac71 in Item_func_hybrid_field_type::val_str_from_str_op(String*) /12.3/src/sql/item_func.h:978
|
#7 0x6485b062ac71 in Type_handler_string_result::Item_func_hybrid_field_type_val_str(Item_func_hybrid_field_type*, String*) const /12.3/src/sql/sql_type.cc:5844
|
#8 0x6485afe83cb9 in Item_func_hybrid_field_type::val_str(String*) /12.3/src/sql/item_func.h:1058
|
#9 0x6485b096c716 in Item::save_str_in_field(Field*, bool) /12.3/src/sql/item.cc:7649
|
#10 0x6485b0615745 in Type_handler_string_result::Item_save_in_field(Item*, Field*, bool) const /12.3/src/sql/sql_type.cc:4443
|
#11 0x6485b092b9ec in Item::save_in_field(Field*, bool) /12.3/src/sql/item.cc:7733
|
#12 0x6485b0945fec in Item_trigger_field::set_value(THD*, sp_rcontext*, Item**) /12.3/src/sql/item.cc:11083
|
#13 0x6485b05e6efd in Item_trigger_field::set_value(THD*, Item**) /12.3/src/sql/item.h:7818
|
#14 0x6485b05e6efd in sp_instr_set_trigger_field::exec_core(THD*, unsigned int*) /12.3/src/sql/sp_instr.cc:1719
|
#15 0x6485b05f237c in sp_lex_keeper::reset_lex_and_exec_core(THD*, unsigned int*, bool, sp_instr*, bool) /12.3/src/sql/sp_instr.cc:420
|
#16 0x6485b05f7868 in sp_lex_keeper::validate_lex_and_exec_core(THD*, unsigned int*, bool, sp_lex_instr*) /12.3/src/sql/sp_instr.cc:602
|
#17 0x6485b05f9b8f in sp_instr_set_trigger_field::execute(THD*, unsigned int*) /12.3/src/sql/sp_instr.cc:1711
|
#18 0x6485afc5e8e9 in sp_head::execute(THD*, bool) /12.3/src/sql/sp_head.cc:1345
|
#19 0x6485afc60c01 in sp_head::execute_trigger(THD*, st_mysql_const_lex_string const*, st_mysql_const_lex_string const*, st_grant_info*) /12.3/src/sql/sp_head.cc:1860
|
#20 0x6485b01ef2bd in Table_triggers_list::process_triggers(THD*, trg_event_type, trg_action_time_type, bool, bool*, List<Item>*) /12.3/src/sql/sql_trigger.cc:2854
|
#21 0x6485afd1261e in fill_record_n_invoke_before_triggers(THD*, TABLE*, List<Item>&, List<Item>&, bool, trg_event_type, bool*) /12.3/src/sql/sql_base.cc:9532
|
#22 0x6485b024e339 in Sql_cmd_update::update_single_table(THD*) /12.3/src/sql/sql_update.cc:997
|
#23 0x6485b02520bd in Sql_cmd_update::execute_inner(THD*) /12.3/src/sql/sql_update.cc:3274
|
#24 0x6485b000802a in Sql_cmd_dml::execute(THD*) /12.3/src/sql/sql_select.cc:35178
|
#25 0x6485afedc7bc in mysql_execute_command(THD*, bool) /12.3/src/sql/sql_parse.cc:4445
|
#26 0x6485afee706e in mysql_parse(THD*, char*, unsigned int, Parser_state*) /12.3/src/sql/sql_parse.cc:7947
|
#27 0x6485afeeaac8 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /12.3/src/sql/sql_parse.cc:1903
|
#28 0x6485afeef2b5 in do_command(THD*, bool) /12.3/src/sql/sql_parse.cc:1437
|
#29 0x6485b03b35e0 in do_handle_one_connection(CONNECT*, bool) /12.3/src/sql/sql_connect.cc:1529
|
#30 0x6485b03b39e6 in handle_one_connection /12.3/src/sql/sql_connect.cc:1441
|
#31 0x760f4da5ea41 in asan_thread_start ../../../../src/libsanitizer/asan/asan_interceptors.cpp:234
|
#32 0x760f4cc9cb63 in start_thread nptl/pthread_create.c:447
|
#33 0x760f4cd29e8b in clone3 ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
|
|
|
0x52c0000b02f0 is located 240 bytes inside of 29128-byte region [0x52c0000b0200,0x52c0000b73c8)
|
freed by thread T8 here:
|
#0 0x760f4dafc4d8 in free ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:52
|
#1 0x6485b1ada74c in my_free /12.3/src/mysys/my_malloc.c:218
|
|
|
previously allocated by thread T8 here:
|
#0 0x760f4dafd9c7 in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
|
#1 0x6485b1ada2fb in my_malloc /12.3/src/mysys/my_malloc.c:93
|
|
|
Thread T7 created by T0 here:
|
#0 0x760f4daf51f9 in pthread_create ../../../../src/libsanitizer/asan/asan_interceptors.cpp:245
|
#1 0x6485afad235c in create_thread_to_handle_connection(CONNECT*) /12.3/src/sql/mysqld.cc:6606
|
|
|
Thread T8 created by T0 here:
|
#0 0x760f4daf51f9 in pthread_create ../../../../src/libsanitizer/asan/asan_interceptors.cpp:245
|
#1 0x6485afad235c in create_thread_to_handle_connection(CONNECT*) /12.3/src/sql/mysqld.cc:6606
|
|
|
SUMMARY: AddressSanitizer: heap-use-after-free /12.3/src/sql/sql_array.h:176 in Dynamic_array<active_dml_stmt>::back()
|
Shadow bytes around the buggy address:
|
0x52c0000b0000: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
|
0x52c0000b0080: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
|
0x52c0000b0100: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
|
0x52c0000b0180: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
|
0x52c0000b0200: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
|
=>0x52c0000b0280: fd fd fd fd fd fd fd fd fd fd fd fd fd fd[fd]fd
|
0x52c0000b0300: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
|
0x52c0000b0380: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
|
0x52c0000b0400: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
|
0x52c0000b0480: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
|
0x52c0000b0500: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
|
Shadow byte legend (one shadow byte represents 8 application bytes):
|
Addressable: 00
|
Partially addressable: 01 02 03 04 05 06 07
|
Heap left redzone: fa
|
Freed heap region: fd
|
Stack left redzone: f1
|
Stack mid redzone: f2
|
Stack right redzone: f3
|
Stack after return: f5
|
Stack use after scope: f8
|
Global redzone: f9
|
Global init order: f6
|
Poisoned by user: f7
|
Container overflow: fc
|
Array cookie: ac
|
Intra object redzone: bb
|
ASan internal: fe
|
Left alloca redzone: ca
|
Right alloca redzone: cb
|
==310331==ABORTING
|
Attachments
Issue Links
- relates to
-
MDEV-10164 Add support for TRIGGERS that fire on multiple events
-
- Closed
-
-
MDEV-42409 Server crashes in THD::get_variable / Item_func_xml_method_getNumberVal::val_real when trigger runs in another connection
-
- Open
-
-
MDEV-42410 Server crashes in Item_method_base::get_variable / Item_func_assoc_array_count::val_int when trigger runs in another connection
-
- Confirmed
-