[MDEV-20620] AddressSanitizer: use-after-poison in tree_walk_left_root_right with GROUP_CONCAT Created: 2019-09-18  Updated: 2023-05-09  Resolved: 2023-05-09

Status: Closed
Project: MariaDB Server
Component/s: Server
Affects Version/s: 10.1
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Oleksandr Byelkin
Resolution: Won't Fix Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-21379 Valgrind Invalid read in tree_walk_le... Closed

 Description   

Note: The test case uses group_concat_max_len= 4 to minimize the test data set. The problem is reproducible with normal values of group_concat_max_len on bigger data sets.

SET character_set_server= latin1;
SET group_concat_max_len= 4;
 
CREATE TABLE t (a DATETIME, b VARCHAR(10)) ENGINE=MyISAM;
INSERT INTO t VALUES ('1985-05-13 01:01:39','foo'),('2012-12-12 12:12:12','bar');
INSERT INTO t SELECT * FROM t;
INSERT INTO t SELECT * FROM t;
INSERT INTO t SELECT * FROM t;
 
SELECT GROUP_CONCAT(t1.a,'-',t1.b ORDER BY 1) AS f FROM t AS t1, t AS t2;
 
# Cleanup
DROP TABLE t;

10.1 ASAN 031c695b

==10308==ERROR: AddressSanitizer: use-after-poison on address 0x629000102148 at pc 0x7f7c338c5f7f bp 0x7f7c27fbfb20 sp 0x7f7c27fbf2d0
READ of size 32 at 0x629000102148 thread T6
    #0 0x7f7c338c5f7e  (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x5cf7e)
    #1 0x5585c27aff77 in tree_insert /data/src/10.1/mysys/tree.c:255
    #2 0x5585c1bd2310 in copy_to_tree /data/src/10.1/sql/item_sum.cc:3327
    #3 0x5585c27aede8 in tree_walk_left_root_right /data/src/10.1/mysys/tree.c:551
    #4 0x5585c27aed8f in tree_walk_left_root_right /data/src/10.1/mysys/tree.c:550
    #5 0x5585c27aed8f in tree_walk_left_root_right /data/src/10.1/mysys/tree.c:550
    #6 0x5585c27aed8f in tree_walk_left_root_right /data/src/10.1/mysys/tree.c:550
    #7 0x5585c27aed8f in tree_walk_left_root_right /data/src/10.1/mysys/tree.c:550
    #8 0x5585c27aed8f in tree_walk_left_root_right /data/src/10.1/mysys/tree.c:550
    #9 0x5585c27aed8f in tree_walk_left_root_right /data/src/10.1/mysys/tree.c:550
    #10 0x5585c27aed8f in tree_walk_left_root_right /data/src/10.1/mysys/tree.c:550
    #11 0x5585c27aed8f in tree_walk_left_root_right /data/src/10.1/mysys/tree.c:550
    #12 0x5585c27aed8f in tree_walk_left_root_right /data/src/10.1/mysys/tree.c:550
    #13 0x5585c27aed8f in tree_walk_left_root_right /data/src/10.1/mysys/tree.c:550
    #14 0x5585c27b2315 in tree_walk /data/src/10.1/mysys/tree.c:538
    #15 0x5585c1bec1f7 in Item_func_group_concat::repack_tree(THD*) /data/src/10.1/sql/item_sum.cc:3345
    #16 0x5585c1becb8b in Item_func_group_concat::add() /data/src/10.1/sql/item_sum.cc:3413
    #17 0x5585c1bed53d in Aggregator_simple::add() /data/src/10.1/sql/item_sum.h:672
    #18 0x5585c1559331 in Item_sum::aggregator_add() /data/src/10.1/sql/item_sum.h:521
    #19 0x5585c1559331 in update_sum_func /data/src/10.1/sql/sql_select.cc:23664
    #20 0x5585c15d4bb3 in end_send_group(JOIN*, st_join_table*, bool) /data/src/10.1/sql/sql_select.cc:19920
    #21 0x5585c182b0aa in JOIN_CACHE::generate_full_extensions(unsigned char*) /data/src/10.1/sql/sql_join_cache.cc:2411
    #22 0x5585c182ba2c in JOIN_CACHE::join_matching_records(bool) /data/src/10.1/sql/sql_join_cache.cc:2303
    #23 0x5585c182a168 in JOIN_CACHE::join_records(bool) /data/src/10.1/sql/sql_join_cache.cc:2097
    #24 0x5585c1587daf in sub_select_cache(JOIN*, st_join_table*, bool) /data/src/10.1/sql/sql_select.cc:18357
    #25 0x5585c1586e43 in sub_select(JOIN*, st_join_table*, bool) /data/src/10.1/sql/sql_select.cc:18527
    #26 0x5585c15bf482 in do_select /data/src/10.1/sql/sql_select.cc:18233
    #27 0x5585c1603c69 in JOIN::exec_inner() /data/src/10.1/sql/sql_select.cc:3277
    #28 0x5585c1604cb3 in JOIN::exec() /data/src/10.1/sql/sql_select.cc:2564
    #29 0x5585c15f7b72 in mysql_select(THD*, Item***, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) /data/src/10.1/sql/sql_select.cc:3501
    #30 0x5585c15fa1bf in handle_select(THD*, LEX*, select_result*, unsigned long) /data/src/10.1/sql/sql_select.cc:377
    #31 0x5585c14c96ef in execute_sqlcom_select /data/src/10.1/sql/sql_parse.cc:5691
    #32 0x5585c14e4f54 in mysql_execute_command(THD*) /data/src/10.1/sql/sql_parse.cc:3038
    #33 0x5585c14fb95d in mysql_parse(THD*, char*, unsigned int, Parser_state*) /data/src/10.1/sql/sql_parse.cc:7209
    #34 0x5585c1502c95 in dispatch_command(enum_server_command, THD*, char*, unsigned int) /data/src/10.1/sql/sql_parse.cc:1499
    #35 0x5585c1507e3c in do_command(THD*) /data/src/10.1/sql/sql_parse.cc:1131
    #36 0x5585c17ab9f6 in do_handle_one_connection(THD*) /data/src/10.1/sql/sql_connect.cc:1331
    #37 0x5585c17abfae in handle_one_connection /data/src/10.1/sql/sql_connect.cc:1242
    #38 0x5585c2110994 in pfs_spawn_thread /data/src/10.1/storage/perfschema/pfs.cc:1861
    #39 0x7f7c336534a3 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x74a3)
    #40 0x7f7c32069d0e in __clone (/lib/x86_64-linux-gnu/libc.so.6+0xe8d0e)
 
0x629000102148 is located 12104 bytes inside of 16460-byte region [0x6290000ff200,0x62900010324c)
allocated by thread T6 here:
    #0 0x7f7c3392ad28 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1d28)
    #1 0x5585c27b9240 in sf_malloc /data/src/10.1/mysys/safemalloc.c:115
    #2 0x5585c2916352  (/data/bld/10.1-asan/bin/mysqld+0x1dcb352)
 
Thread T6 created by T0 here:
    #0 0x7f7c33899f59 in __interceptor_pthread_create (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x30f59)
    #1 0x5585c211c318 in spawn_thread_v1 /data/src/10.1/storage/perfschema/pfs.cc:1911
 
SUMMARY: AddressSanitizer: use-after-poison (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x5cf7e) 
Shadow bytes around the buggy address:
  0x0c52800183d0: 00 f7 00 00 00 00 00 00 00 f7 00 00 00 00 00 00
  0x0c52800183e0: 00 f7 00 00 00 00 00 00 00 f7 00 00 00 00 00 00
  0x0c52800183f0: 00 f7 00 00 00 00 00 00 00 f7 00 00 00 00 00 00
  0x0c5280018400: 00 f7 00 00 00 00 00 00 00 f7 00 00 00 00 00 00
  0x0c5280018410: 00 f7 00 00 00 00 00 00 00 f7 00 00 00 00 00 00
=>0x0c5280018420: 00 f7 00 00 00 00 00 00 00[f7]f7 f7 f7 f7 f7 f7
  0x0c5280018430: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
  0x0c5280018440: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
  0x0c5280018450: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
  0x0c5280018460: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
  0x0c5280018470: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 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
  Heap right redzone:      fb
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack partial redzone:   f4
  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
==10308==ABORTING

Couldn't reproduce on 5.5 or 10.2+. Maybe 10.2+ versions are really unaffected, or maybe they just have some different default settings which prevents the failure from happening.

No obvious effect on a non-ASAN build.



 Comments   
Comment by Elena Stepanova [ 2023-05-09 ]

10.1 is long EOL, and as the description says, it wasn't reproducible on 10.2+.

Generated at Thu Feb 08 09:00:53 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.