Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-15981

ASAN: heap-use-after-free in update_connection_info upon EXECUTE IMMEDATE with server_audit plugin installed

    Details

      Description

      Note: in addition to the problem as such, it is a bit worrisome that the plugin does some job even though auditing has not been turned on.

      install soname 'server_audit';
      set @general_log.save= @@general_log, @slow_log.save= @@slow_query_log;
      set global general_log= off, slow_query_log= off;
       
      --exec $MYSQL -e "execute immediate 'select 1'"
       
      # Cleanup
      set global general_log= @general_log.save;
      set global slow_query_log= @slow_log.save;
      uninstall soname 'server_audit';
      

      10.2 ASAN 469a4b02c

      ==11786==ERROR: AddressSanitizer: heap-use-after-free on address 0x62b000024900 at pc 0x7fd2606edea8 bp 0x7fd2537b9d30 sp 0x7fd2537b9cf8
      READ of size 1 at 0x62b000024900 thread T6
          #0 0x7fd2606edea7 in __interceptor_strncasecmp (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x39ea7)
          #1 0x7fd253ad5790 in update_connection_info /data/src/10.2/plugin/server_audit/server_audit.c:1871
          #2 0x7fd253ad63de in auditing /data/src/10.2/plugin/server_audit/server_audit.c:1996
          #3 0x562f49dec530 in plugins_dispatch /data/src/10.2/sql/sql_audit.cc:384
          #4 0x562f49dec742 in mysql_audit_notify(THD*, unsigned int, void const*) /data/src/10.2/sql/sql_audit.cc:423
          #5 0x562f49ab4905 in mysql_audit_general /data/src/10.2/sql/sql_audit.h:196
          #6 0x562f49abf358 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.2/sql/sql_parse.cc:2390
          #7 0x562f49ab94a9 in do_command(THD*) /data/src/10.2/sql/sql_parse.cc:1374
          #8 0x562f49df4e27 in do_handle_one_connection(CONNECT*) /data/src/10.2/sql/sql_connect.cc:1335
          #9 0x562f49df483c in handle_one_connection /data/src/10.2/sql/sql_connect.cc:1241
          #10 0x562f4a800637 in pfs_spawn_thread /data/src/10.2/storage/perfschema/pfs.cc:1862
          #11 0x7fd26049e493 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x7493)
          #12 0x7fd25e88493e in __clone (/lib/x86_64-linux-gnu/libc.so.6+0xe893e)
       
      0x62b000024900 is located 5888 bytes inside of 24716-byte region [0x62b000023200,0x62b00002928c)
      freed by thread T6 here:
          #0 0x7fd260708527 in __interceptor_free (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x54527)
          #1 0x562f4b12161d in free_memory /data/src/10.2/mysys/safemalloc.c:279
          #2 0x562f4b120c23 in sf_free /data/src/10.2/mysys/safemalloc.c:197
          #3 0x562f4b0eff0a in my_free /data/src/10.2/mysys/my_malloc.c:217
          #4 0x562f4b0d1580 in free_root /data/src/10.2/mysys/my_alloc.c:398
          #5 0x562f49b23676 in Prepared_statement::~Prepared_statement() /data/src/10.2/sql/sql_prepare.cc:3821
          #6 0x562f49b23789 in Prepared_statement::~Prepared_statement() /data/src/10.2/sql/sql_prepare.cc:3823
          #7 0x562f49b1e349 in mysql_sql_stmt_execute_immediate(THD*) /data/src/10.2/sql/sql_prepare.cc:2899
          #8 0x562f49ac5a1e in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:3489
          #9 0x562f49ae122e in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.2/sql/sql_parse.cc:7924
          #10 0x562f49abc405 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.2/sql/sql_parse.cc:1820
          #11 0x562f49ab94a9 in do_command(THD*) /data/src/10.2/sql/sql_parse.cc:1374
          #12 0x562f49df4e27 in do_handle_one_connection(CONNECT*) /data/src/10.2/sql/sql_connect.cc:1335
          #13 0x562f49df483c in handle_one_connection /data/src/10.2/sql/sql_connect.cc:1241
          #14 0x562f4a800637 in pfs_spawn_thread /data/src/10.2/storage/perfschema/pfs.cc:1862
          #15 0x7fd26049e493 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x7493)
       
      previously allocated by thread T6 here:
          #0 0x7fd26070873f in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x5473f)
          #1 0x562f4b120393 in sf_malloc /data/src/10.2/mysys/safemalloc.c:118
          #2 0x562f4b0ef642 in my_malloc /data/src/10.2/mysys/my_malloc.c:101
          #3 0x562f4b0cf448 in init_alloc_root /data/src/10.2/mysys/my_alloc.c:78
          #4 0x562f49d72bfe in init_sql_alloc(st_mem_root*, unsigned int, unsigned int, unsigned long) /data/src/10.2/sql/thr_malloc.cc:64
          #5 0x562f49b22b01 in Prepared_statement::Prepared_statement(THD*) /data/src/10.2/sql/sql_prepare.cc:3743
          #6 0x562f49b1e14b in mysql_sql_stmt_execute_immediate(THD*) /data/src/10.2/sql/sql_prepare.cc:2867
          #7 0x562f49ac5a1e in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:3489
          #8 0x7fd25e7bc2b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0)
       
      SUMMARY: AddressSanitizer: heap-use-after-free ??:0 __interceptor_strncasecmp
      Shadow bytes around the buggy address:
        0x0c567fffc8d0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c567fffc8e0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c567fffc8f0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c567fffc900: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c567fffc910: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      =>0x0c567fffc920:[fd]fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c567fffc930: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c567fffc940: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c567fffc950: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c567fffc960: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c567fffc970: 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
        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
        Contiguous container OOB:fc
        ASan internal:           fe
      ==11786==ABORTING
      ----------SERVER LOG END-------------
      

        Attachments

          Activity

            People

            • Assignee:
              holyfoot Alexey Botchkov
              Reporter:
              elenst Elena Stepanova
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: