Details
-
Bug
-
Status: Open (View Workflow)
-
Major
-
Resolution: Unresolved
-
13.3
-
None
-
None
Description
Problem
A stored procedure with a parameter whose default is a subquery over a table keeps that default after the table is dropped. Reading information_schema.PARAMETERS then prints the default, and the server reads freed memory in TABLE_LIST::print() (SIGSEGV; ASan: heap-use-after-free). The call chain is the one of MDEV-37489 (store_schema_params() -> get_param_default_value()), but the trigger and the crash site are different, and the testcase of MDEV-37489 does not crash on current main.
How to repeat
Fresh server, default settings:
CREATE TABLE t (a INT); |
CREATE PROCEDURE p(x INT DEFAULT (SELECT 1 FROM t)) BEGIN END; |
CALL p();
|
DROP TABLE t; |
SELECT * FROM information_schema.PARAMETERS; |
For each build I started a fresh server on an empty data directory three times (13.3.0 main, commit 392818112, --no-defaults, TCP) and ran the five statements once per run:
- Debug build with assertions: SIGSEGV (signal 11) in 3 of 3 runs.
- Optimized build (with coverage instrumentation, no DBUG assertions): signal 11 in 2 of 3 runs; one run survived.
- ASan/UBSan build: heap-use-after-free in 3 of 3 runs.
- Without the DROP TABLE t; statement the server does not crash (debug build, 2 runs).
- The testcase of
MDEV-37489(default func(), two failing CALL}}s, then {{SELECT * FROM information_schema.PARAMETERS) does not crash on this build (debug 3 of 3, ASan 2 of 2).
Actual result
ASan (the same address in all three runs):
ERROR: AddressSanitizer: heap-use-after-free on address 0x61900006c7a0
|
READ of size 8 at 0x61900006c7a0 thread T14
|
#0 TABLE::versioned() const sql/table.h:2080:12
|
#1 TABLE_LIST::print(THD*, unsigned long long, String*, enum_query_type) sql/sql_select.cc:33203:25
|
#2 print_table_array(THD*, unsigned long long, String*, TABLE_LIST**, TABLE_LIST**, enum_query_type)
|
#3 print_join(THD*, unsigned long long, String*, List<TABLE_LIST>*, enum_query_type) sql/sql_select.cc:33044:3
|
#4 st_select_lex::print(THD*, String*, enum_query_type) sql/sql_select.cc:33582:7
|
#5 subselect_single_select_engine::print(String*, enum_query_type) sql/item_subselect.cc:4750:15
|
#6 Item_subselect::print(String*, enum_query_type) sql/item_subselect.cc:1120:13
|
#7 Item::print_parenthesised(String*, enum_query_type, precedence) sql/item.cc:521:5
|
#8 Item::print_for_table_def(String*) sql/item.h:2109:5
|
#9 get_param_default_value(Item*, String*) sql/sql_show.cc:1949:9
|
#10 store_schema_params(THD*, TABLE*, TABLE*, st_lookup_field_values*, bool, char const*) sql/sql_show.cc:7433:11
|
The debug and the optimized build crash with signal 11. In my own runs I recorded only the signal; an earlier reduction run of the same statements showed TABLE::versioned() called from TABLE_LIST::print() at the top of the stack, as in the ASan trace.
Notes
- The tested source tree contains a small local change of the test harness in sql/sql_parse.cc (24 lines: calls to a coverage hook around dispatch_command() in do_command()). The calls are compiled into the debug and the optimized build and are not compiled into the ASan/UBSan build, which reports the use-after-free. The change does not touch stored routines, information_schema or the optimizer.
- The same feature (a parameter DEFAULT with a subquery over a table) is the subject of MDEV-42276 (an assertion in alloc_root() on a second call). I did not check whether the two share a root cause.
- I did not trace which allocation is freed, and I did not test other branches or releases.