[MDEV-30957] AddressSanitizer: use-after-poison in Item_change_list::rollback_item_tree_changes #2 Created: 2023-03-29  Updated: 2023-11-28

Status: Open
Project: MariaDB Server
Component/s: Prepared Statements
Affects Version/s: 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10, 10.11, 11.0
Fix Version/s: 10.4, 10.5, 10.6, 10.11, 11.0

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Oleksandr Byelkin
Resolution: Unresolved Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-17869 AddressSanitizer: use-after-poison in... Closed

 Description   

A patch for MDEV-17869 is already in the trees. It fixed the failure on the test case described there, but not this one.

CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (b INT, c INT, d CHAR(3)) ENGINE=MyISAM;
 
EXECUTE IMMEDIATE "SELECT * FROM t1 LEFT JOIN t2 ON (t2.c = t1.a) HAVING t2.d = 'h' AND t1.a = 10 OR t2.b < 8";
 
# Cleanup
DROP TABLE t1, t2;

10.4 ff3d4395

==2851481==ERROR: AddressSanitizer: use-after-poison on address 0x62b000066308 at pc 0x559d50052199 bp 0x7fad6d540340 sp 0x7fad6d540338
WRITE of size 8 at 0x62b000066308 thread T5
    #0 0x559d50052198 in Item_change_list::rollback_item_tree_changes() /data/src/10.4/sql/sql_class.cc:3001
    #1 0x559d501d350a in Prepared_statement::cleanup_stmt() /data/src/10.4/sql/sql_prepare.cc:4103
    #2 0x559d501dae1b in Prepared_statement::execute(String*, bool) /data/src/10.4/sql/sql_prepare.cc:5052
    #3 0x559d501d60bc in Prepared_statement::execute_loop(String*, bool, unsigned char*, unsigned char*) /data/src/10.4/sql/sql_prepare.cc:4493
    #4 0x559d501dbb42 in Prepared_statement::execute_immediate(char const*, unsigned int) /data/src/10.4/sql/sql_prepare.cc:5148
    #5 0x559d501ccf62 in mysql_sql_stmt_execute_immediate(THD*) /data/src/10.4/sql/sql_prepare.cc:3012
    #6 0x559d5016c659 in mysql_execute_command(THD*) /data/src/10.4/sql/sql_parse.cc:3972
    #7 0x559d50188103 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.4/sql/sql_parse.cc:7986
    #8 0x559d5015e7c8 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.4/sql/sql_parse.cc:1857
    #9 0x559d5015b350 in do_command(THD*) /data/src/10.4/sql/sql_parse.cc:1378
    #10 0x559d5055067f in do_handle_one_connection(CONNECT*) /data/src/10.4/sql/sql_connect.cc:1420
    #11 0x559d5054ff96 in handle_one_connection /data/src/10.4/sql/sql_connect.cc:1324
    #12 0x559d511a0089 in pfs_spawn_thread /data/src/10.4/storage/perfschema/pfs.cc:1869
    #13 0x7fad752a7fd3 in start_thread nptl/pthread_create.c:442
    #14 0x7fad7532866b in clone3 ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
 
0x62b000066308 is located 16648 bytes inside of 24608-byte region [0x62b000062200,0x62b000068220)
allocated by thread T5 here:
    #0 0x7fad758b89cf in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x559d51ce4b97 in my_malloc /data/src/10.4/mysys/my_malloc.c:101
    #2 0x559d51cc0d33 in reset_root_defaults /data/src/10.4/mysys/my_alloc.c:152
    #3 0x559d50045afc in THD::init_for_queries() /data/src/10.4/sql/sql_class.cc:1383
    #4 0x559d5054f8b2 in prepare_new_connection_state(THD*) /data/src/10.4/sql/sql_connect.cc:1254
    #5 0x559d5054ffdc in thd_prepare_connection(THD*) /data/src/10.4/sql/sql_connect.cc:1339
    #6 0x559d505505de in do_handle_one_connection(CONNECT*) /data/src/10.4/sql/sql_connect.cc:1410
    #7 0x559d5054ff96 in handle_one_connection /data/src/10.4/sql/sql_connect.cc:1324
    #8 0x559d511a0089 in pfs_spawn_thread /data/src/10.4/storage/perfschema/pfs.cc:1869
    #9 0x7fad752a7fd3 in start_thread nptl/pthread_create.c:442
 
Thread T5 created by T0 here:
    #0 0x7fad75849726 in __interceptor_pthread_create ../../../../src/libsanitizer/asan/asan_interceptors.cpp:207
    #1 0x559d511a0476 in spawn_thread_v1 /data/src/10.4/storage/perfschema/pfs.cc:1919
    #2 0x559d4fe69ef8 in inline_mysql_thread_create /data/src/10.4/include/mysql/psi/mysql_thread.h:1275
    #3 0x559d4fe81572 in create_thread_to_handle_connection(CONNECT*) /data/src/10.4/sql/mysqld.cc:6284
    #4 0x559d4fe81cbd in create_new_thread(CONNECT*) /data/src/10.4/sql/mysqld.cc:6354
    #5 0x559d4fe8218b in handle_accepted_socket(st_mysql_socket, st_mysql_socket) /data/src/10.4/sql/mysqld.cc:6452
    #6 0x559d4fe83037 in handle_connections_sockets() /data/src/10.4/sql/mysqld.cc:6610
    #7 0x559d4fe80cd5 in mysqld_main(int, char**) /data/src/10.4/sql/mysqld.cc:5942
    #8 0x559d4fe68088 in main /data/src/10.4/sql/main.cc:25
    #9 0x7fad75246189 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
 
SUMMARY: AddressSanitizer: use-after-poison /data/src/10.4/sql/sql_class.cc:3001 in Item_change_list::rollback_item_tree_changes()
Shadow bytes around the buggy address:
  0x0c5680004c10: f7 00 00 f7 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c5680004c20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c5680004c30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c5680004c40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c5680004c50: 00 00 00 00 00 00 00 00 00 00 00 00 f7 00 00 f7
=>0x0c5680004c60: f7[f7]f7 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c5680004c70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c5680004c80: 00 00 00 00 00 00 f7 00 00 00 00 00 00 00 00 00
  0x0c5680004c90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 f7 00
  0x0c5680004ca0: 00 00 00 00 f7 00 00 00 00 00 00 00 00 00 00 00
  0x0c5680004cb0: 00 00 00 00 00 00 00 00 00 00 00 00 f7 f7 f7 f7
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
==2851481==ABORTING



 Comments   
Comment by Alice Sherepa [ 2023-09-27 ]

also with prepare+execute, not only execute immediate.
if t1 is InnoDB table - then - not reproducible.

CREATE TABLE t1 ( c int) engine=myisam;
INSERT INTO t1 values (1);
CREATE TABLE t2 ( i int);
INSERT INTO t2 values (1),(2),(3),(4);
 
prepare stmt from "SELECT * FROM t1,t2 HAVING t1.c = 'p' AND t2.i >= 9 OR t1.c < 'l' ;";
execute stmt;
drop table t1,t2;

Version: '11.2.2-MariaDB-debug-log'  
=================================================================
==4009886==ERROR: AddressSanitizer: use-after-poison on address 0x6290001095d0 at pc 0x556d62469c56 bp 0x7f1b4ffbd4f0 sp 0x7f1b4ffbd4e0
WRITE of size 8 at 0x6290001095d0 thread T24
    #0 0x556d62469c55 in Item_change_list::rollback_item_tree_changes() /11.2/src/sql/sql_class.cc:3025
    #1 0x556d6265401c in Prepared_statement::cleanup_stmt(bool) /11.2/src/sql/sql_prepare.cc:4016
    #2 0x556d6265c83f in Prepared_statement::execute(String*, bool) /11.2/src/sql/sql_prepare.cc:5059
    #3 0x556d62657282 in Prepared_statement::execute_loop(String*, bool, unsigned char*, unsigned char*) /11.2/src/sql/sql_prepare.cc:4433
    #4 0x556d62650449 in mysql_sql_stmt_execute(THD*) /11.2/src/sql/sql_prepare.cc:3470
    #5 0x556d625acc97 in mysql_execute_command(THD*, bool) /11.2/src/sql/sql_parse.cc:3971
    #6 0x556d625c6e7e in mysql_parse(THD*, char*, unsigned int, Parser_state*) /11.2/src/sql/sql_parse.cc:7810
    #7 0x556d6259f225 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /11.2/src/sql/sql_parse.cc:1893
    #8 0x556d6259bf6f in do_command(THD*, bool) /11.2/src/sql/sql_parse.cc:1406
    #9 0x556d62a7abb0 in do_handle_one_connection(CONNECT*, bool) /11.2/src/sql/sql_connect.cc:1445
    #10 0x556d62a7a50d in handle_one_connection /11.2/src/sql/sql_connect.cc:1347
    #11 0x556d636e88ef in pfs_spawn_thread /11.2/src/storage/perfschema/pfs.cc:2201
    #12 0x7f1b65975608 in start_thread /build/glibc-SzIz7B/glibc-2.31/nptl/pthread_create.c:477
    #13 0x7f1b65546132 in __clone (/lib/x86_64-linux-gnu/libc.so.6+0x11f132)
 
0x6290001095d0 is located 976 bytes inside of 16516-byte region [0x629000109200,0x62900010d284)
allocated by thread T24 here:
    #0 0x7f1b65f02808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x556d64329bab in sf_malloc /11.2/src/mysys/safemalloc.c:126
    #2 0x556d642f6dfc in my_malloc /11.2/src/mysys/my_malloc.c:89
    #3 0x556d642d17ad in root_alloc /11.2/src/mysys/my_alloc.c:71
    #4 0x556d642d27cb in reset_root_defaults /11.2/src/mysys/my_alloc.c:250
    #5 0x556d6245ce22 in THD::init_for_queries() /11.2/src/sql/sql_class.cc:1391
    #6 0x556d62a79dc0 in prepare_new_connection_state(THD*) /11.2/src/sql/sql_connect.cc:1274
    #7 0x556d62a7a58c in thd_prepare_connection(THD*) /11.2/src/sql/sql_connect.cc:1368
    #8 0x556d62a7aad6 in do_handle_one_connection(CONNECT*, bool) /11.2/src/sql/sql_connect.cc:1435
    #9 0x556d62a7a50d in handle_one_connection /11.2/src/sql/sql_connect.cc:1347
    #10 0x556d636e88ef in pfs_spawn_thread /11.2/src/storage/perfschema/pfs.cc:2201
    #11 0x7f1b65975608 in start_thread /build/glibc-SzIz7B/glibc-2.31/nptl/pthread_create.c:477
 
Thread T24 created by T0 here:
    #0 0x7f1b65e2f815 in __interceptor_pthread_create ../../../../src/libsanitizer/asan/asan_interceptors.cc:208
    #1 0x556d636e44cc in my_thread_create /11.2/src/storage/perfschema/my_thread.h:52
    #2 0x556d636e8ce2 in pfs_spawn_thread_v1 /11.2/src/storage/perfschema/pfs.cc:2252
    #3 0x556d621dc019 in inline_mysql_thread_create /11.2/src/include/mysql/psi/mysql_thread.h:1139
    #4 0x556d621f4aa5 in create_thread_to_handle_connection(CONNECT*) /11.2/src/sql/mysqld.cc:6169
    #5 0x556d621f5135 in create_new_thread(CONNECT*) /11.2/src/sql/mysqld.cc:6231
    #6 0x556d621f54a2 in handle_accepted_socket(st_mysql_socket, st_mysql_socket) /11.2/src/sql/mysqld.cc:6293
    #7 0x556d621f5e98 in handle_connections_sockets() /11.2/src/sql/mysqld.cc:6417
    #8 0x556d621f42b2 in mysqld_main(int, char**) /11.2/src/sql/mysqld.cc:6064
    #9 0x556d621db0cc in main /11.2/src/sql/main.cc:34
    #10 0x7f1b6544b082 in __libc_start_main ../csu/libc-start.c:308

Generated at Thu Feb 08 10:20:10 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.