Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDEV-32808 encrypt sql crash #2944

Draft
wants to merge 2 commits into
base: 10.4
Choose a base branch
from

Conversation

grooverdan
Copy link
Member

  • The Jira issue number for this PR is: MDEV-32808

Description

Using a SQL service from within an encryption plugin fails as there's no THD valid.

How can this PR be tested?

MTR included. Second commit attempting to eliminate memory leak:

Version: '10.4.33-MariaDB-log'  socket: '/home/dan/repos/build-mariadb-server-10.4-debug/mysql-test/var/tmp/mysqld.1.sock'  port: 16000  Source distribution
2023-12-19 18:16:45 9 [Note] InnoDB: Creating #1 encryption thread id 139867329214144 total threads 1.
2023-12-19 18:16:45 0 [Note] /home/dan/repos/build-mariadb-server-10.4-debug/sql/mysqld (initiated by: root[root] @ localhost [127.0.0.1]): Normal shutdown
2023-12-19 18:16:45 0 [Note] Event Scheduler: Purging the queue. 0 events
2023-12-19 18:16:45 0 [Note] InnoDB: FTS optimize thread exiting.
2023-12-19 18:16:46 0 [Note] InnoDB: Starting shutdown...
2023-12-19 18:16:46 0 [Note] InnoDB: Dumping buffer pool(s) to /home/dan/repos/build-mariadb-server-10.4-debug/mysql-test/var/mysqld.1/data/ib_buffer_pool
2023-12-19 18:16:46 0 [Note] InnoDB: Instance 0, restricted to 125 pages due to innodb_buf_pool_dump_pct=25
2023-12-19 18:16:46 0 [Note] InnoDB: Buffer pool(s) dump completed at 231219 18:16:46
2023-12-19 18:16:47 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2023-12-19 18:16:47 0 [Note] InnoDB: Shutdown completed; log sequence number 68197; transaction id 33
2023-12-19 18:16:47 0 [Note] /home/dan/repos/build-mariadb-server-10.4-debug/sql/mysqld: Shutdown complete

Warning: Memory not freed: 28352

=================================================================
==3247871==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 1280 byte(s) in 1 object(s) allocated from:
    #0 0x75f022 in malloc (/home/dan/repos/build-mariadb-server-10.4-debug/sql/mysqld+0x75f022) (BuildId: 33dbf266cfd6a1942a1a044db6d53b4abfba362e)
    #1 0x20aa238 in my_malloc /home/dan/repos/mariadb-server-10.4/mysys/my_malloc.c:101:10
    #2 0xa5ceed in plugin_initialize(st_mem_root*, st_plugin_int*, int*, char**, bool) /home/dan/repos/mariadb-server-10.4/sql/sql_plugin.cc:1482:10
    #3 0xa63e34 in finalize_install(THD*, TABLE*, st_mysql_const_lex_string const*, int*, char**) /home/dan/repos/mariadb-server-10.4/sql/sql_plugin.cc:2186:9

Direct leak of 616 byte(s) in 1 object(s) allocated from:
    #0 0x75f022 in malloc (/home/dan/repos/build-mariadb-server-10.4-debug/sql/mysqld+0x75f022) (BuildId: 33dbf266cfd6a1942a1a044db6d53b4abfba362e)
    #1 0x20aa238 in my_malloc /home/dan/repos/mariadb-server-10.4/mysys/my_malloc.c:101:10
    #2 0xd8a49d in MDL_map::find_or_insert(LF_PINS*, MDL_key const*) /home/dan/repos/mariadb-server-10.4/sql/mdl.cc:863:9
    #3 0xd900af in MDL_context::try_acquire_lock_impl(MDL_request*, MDL_ticket**) /home/dan/repos/mariadb-server-10.4/sql/mdl.cc:2138:25
    #4 0xd90b0f in MDL_context::acquire_lock(MDL_request*, double) /home/dan/repos/mariadb-server-10.4/sql/mdl.cc:2296:7
    #5 0xbbc6cc in try_acquire_high_prio_shared_mdl_lock(THD*, TABLE_LIST*, bool) /home/dan/repos/mariadb-server-10.4/sql/sql_show.cc:4927:29
    #6 0xbbc6cc in fill_schema_table_from_frm(THD*, st_mem_root*, TABLE*, st_schema_table*, st_mysql_const_lex_string*, st_mysql_const_lex_string*, Open_tables_backup*, bool) /home/dan/repos/mariadb-server-10.4/sql/sql_show.cc:5006:7
    #7 0xbbc6cc in get_all_tables(THD*, TABLE_LIST*, Item*) /home/dan/repos/mariadb-server-10.4/sql/sql_show.cc:5372:20
    #8 0xbd8ae4 in get_schema_tables_result(JOIN*, enum_schema_table_state) /home/dan/repos/mariadb-server-10.4/sql/sql_show.cc:9224:11
    #9 0xb17c2e in JOIN::exec_inner() /home/dan/repos/mariadb-server-10.4/sql/sql_select.cc:4582:7
    #10 0xab759a in JOIN::exec() /home/dan/repos/mariadb-server-10.4/sql/sql_select.cc:4407:3
    #11 0xab759a in mysql_select(THD*, 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*) /home/dan/repos/mariadb-server-10.4/sql/sql_select.cc:4846:9

Indirect leak of 25992 byte(s) in 2 object(s) allocated from:
    #0 0x75f022 in malloc (/home/dan/repos/build-mariadb-server-10.4-debug/sql/mysqld+0x75f022) (BuildId: 33dbf266cfd6a1942a1a044db6d53b4abfba362e)
    #1 0x20aa238 in my_malloc /home/dan/repos/mariadb-server-10.4/mysys/my_malloc.c:101:10
    #2 0x7f358e002a15  (<unknown module>)
    #3 0xa5ceed in plugin_initialize(st_mem_root*, st_plugin_int*, int*, char**, bool) /home/dan/repos/mariadb-server-10.4/sql/sql_plugin.cc:1482:10
    #4 0xa63e34 in finalize_install(THD*, TABLE*, st_mysql_const_lex_string const*, int*, char**) /home/dan/repos/mariadb-server-10.4/sql/sql_plugin.cc:2186:9

Indirect leak of 8280 byte(s) in 28 object(s) allocated from:
    #0 0x75f022 in malloc (/home/dan/repos/build-mariadb-server-10.4-debug/sql/mysqld+0x75f022) (BuildId: 33dbf266cfd6a1942a1a044db6d53b4abfba362e)
    #1 0x20aa238 in my_malloc /home/dan/repos/mariadb-server-10.4/mysys/my_malloc.c:101:10

Indirect leak of 1456 byte(s) in 1 object(s) allocated from:
    #0 0x79ccc1 in operator new(unsigned long) (/home/dan/repos/build-mariadb-server-10.4-debug/sql/mysqld+0x79ccc1) (BuildId: 33dbf266cfd6a1942a1a044db6d53b4abfba362e)
    #1 0xa8fac0 in mysql_real_connect_local /home/dan/repos/mariadb-server-10.4/sql/sql_prepare.cc:6230:6
    #2 0x7f358e002a15  (<unknown module>)
    #3 0xa5ceed in plugin_initialize(st_mem_root*, st_plugin_int*, int*, char**, bool) /home/dan/repos/mariadb-server-10.4/sql/sql_plugin.cc:1482:10
    #4 0xa63e34 in finalize_install(THD*, TABLE*, st_mysql_const_lex_string const*, int*, char**) /home/dan/repos/mariadb-server-10.4/sql/sql_plugin.cc:2186:9

Indirect leak of 616 byte(s) in 1 object(s) allocated from:
    #0 0x75f022 in malloc (/home/dan/repos/build-mariadb-server-10.4-debug/sql/mysqld+0x75f022) (BuildId: 33dbf266cfd6a1942a1a044db6d53b4abfba362e)
    #1 0x20aa238 in my_malloc /home/dan/repos/mariadb-server-10.4/mysys/my_malloc.c:101:10
    #2 0xd8a49d in MDL_map::find_or_insert(LF_PINS*, MDL_key const*) /home/dan/repos/mariadb-server-10.4/sql/mdl.cc:863:9
    #3 0xd900af in MDL_context::try_acquire_lock_impl(MDL_request*, MDL_ticket**) /home/dan/repos/mariadb-server-10.4/sql/mdl.cc:2138:25
    #4 0xd90b0f in MDL_context::acquire_lock(MDL_request*, double) /home/dan/repos/mariadb-server-10.4/sql/mdl.cc:2296:7
    #5 0xbbc6cc in try_acquire_high_prio_shared_mdl_lock(THD*, TABLE_LIST*, bool) /home/dan/repos/mariadb-server-10.4/sql/sql_show.cc:4927:29
    #6 0xbbc6cc in fill_schema_table_from_frm(THD*, st_mem_root*, TABLE*, st_schema_table*, st_mysql_const_lex_string*, st_mysql_const_lex_string*, Open_tables_backup*, bool) /home/dan/repos/mariadb-server-10.4/sql/sql_show.cc:5006:7
    #7 0xbbc6cc in get_all_tables(THD*, TABLE_LIST*, Item*) /home/dan/repos/mariadb-server-10.4/sql/sql_show.cc:5372:20
    #8 0xbd8ae4 in get_schema_tables_result(JOIN*, enum_schema_table_state) /home/dan/repos/mariadb-server-10.4/sql/sql_show.cc:9224:11
    #9 0xb17c2e in JOIN::exec_inner() /home/dan/repos/mariadb-server-10.4/sql/sql_select.cc:4582:7
    #10 0xab759a in JOIN::exec() /home/dan/repos/mariadb-server-10.4/sql/sql_select.cc:4407:3
    #11 0xab759a in mysql_select(THD*, 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*) /home/dan/repos/mariadb-server-10.4/sql/sql_select.cc:4846:9

Indirect leak of 104 byte(s) in 1 object(s) allocated from:
    #0 0x75f022 in malloc (/home/dan/repos/build-mariadb-server-10.4-debug/sql/mysqld+0x75f022) (BuildId: 33dbf266cfd6a1942a1a044db6d53b4abfba362e)
    #1 0x20aa238 in my_malloc /home/dan/repos/mariadb-server-10.4/mysys/my_malloc.c:101:10
    #2 0x926965 in THD::init() /home/dan/repos/mariadb-server-10.4/sql/sql_class.cc:1214:3
    #3 0x9251ba in THD::THD(unsigned long long, bool) /home/dan/repos/mariadb-server-10.4/sql/sql_class.cc:809:3

SUMMARY: AddressSanitizer: 38344 byte(s) leaked in 35 allocation(s).

Basing the PR against the correct MariaDB version

  • This is a new feature and the PR is based against the latest MariaDB development branch.
  • This is a bug fix and the PR is based against the earliest maintained branch in which the bug can be reproduced.

PR quality check

  • I checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.
  • For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.

tgross35 and others added 2 commits December 19, 2023 10:18
… segfaults

There is an assumption in the way the SQL service initializes threads
that assumes a thread already exists. For a key management plugin
this isn't the case. As such we perform the initializations on
fil_crypt_thread() so all the SQL layer functionality doesn't
segfault on the lack of a THD.

Create a THD option for the innodb crypt thread.

Co-author: Daniel Black <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants