[MDEV-20842] Crash using versioning plugin functions after plugin was removed from server Created: 2019-10-16  Updated: 2021-05-03  Resolved: 2021-04-27

Status: Closed
Project: MariaDB Server
Component/s: Plugins, Tests, Versioned Tables
Affects Version/s: 10.3, 10.4, 10.5, 10.6
Fix Version/s: 10.3.29, 10.4.19, 10.5.10

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Aleksey Midenkov
Resolution: Fixed Votes: 0
Labels: trx-versioning

Issue Links:
Blocks
is blocked by MDEV-20837 Add MariaDB_FUNCTION_PLUGIN Closed
Relates
relates to MDEV-16226 TRX_ID-based System Versioning refact... Stalled

 Description   

Reproduce

install plugin test_versioning soname 'test_versioning.so';
uninstall plugin test_versioning;
--error ER_SP_DOES_NOT_EXIST
select trt_begin_ts(0);

Result

Server crash.

Possible fix (10.5 or later only)

Wrap SQL functions defined in plugin/versioning/versioning.cc into MariaDB_FUNCTION_PLUGIN

The plugin implemented in plugin/versioning/versioning.cc defines a number of SQL functions:

static Native_func_registry func_array[] =
{
  { { C_STRING_WITH_LEN("TRT_BEGIN_TS") }, BUILDER(Create_func_trt<TR_table::FLD_BEGIN_TS>)},
  { { C_STRING_WITH_LEN("TRT_COMMIT_ID") }, BUILDER(Create_func_trt<TR_table::FLD_COMMIT_ID>)},
  { { C_STRING_WITH_LEN("TRT_COMMIT_TS") }, BUILDER(Create_func_trt<TR_table::FLD_COMMIT_TS>)},
  { { C_STRING_WITH_LEN("TRT_ISO_LEVEL") }, BUILDER(Create_func_trt<TR_table::FLD_ISO_LEVEL>)},
  { { C_STRING_WITH_LEN("TRT_TRX_ID") }, BUILDER(Create_func_trt<TR_table::FLD_TRX_ID>)},
  { { C_STRING_WITH_LEN("TRT_TRX_SEES") }, BUILDER(Create_func_trt_trx_sees<Item_func_trt_trx_sees>)},
  { { C_STRING_WITH_LEN("TRT_TRX_SEES_EQ") }, BUILDER(Create_func_trt_trx_sees<Item_func_trt_trx_sees_eq>)},
  { {0, 0}, NULL}
};

At initialization time it adds these SQL functions into the global SQL function hash native_functions_hash by calling item_create_append():

static int versioning_plugin_init(void *p __attribute__ ((unused)))
{
  DBUG_ENTER("versioning_plugin_init");
  // No need in locking since we so far single-threaded
  int res= item_create_append(func_array);
  if (res)
  {
    my_message(ER_PLUGIN_IS_NOT_LOADED, "Can't append function array" , MYF(0));
    DBUG_RETURN(res);
  }
 
  DBUG_RETURN(0);
}

At de-initialization time it does not remove these functions from the global hash native_functions_hash. So if we de-install the plugin and try to use the mentioned SQL functions, the server will crash.

Under terms of this task we'll turn these SQL functions into MariaDB_FUNCTION_PLUGIN, so they are not added to the global hash native_functions_hash.



 Comments   
Comment by Ralf Gebhardt [ 2020-02-06 ]

Moved to 10.6 after discussing with bar

Comment by Aleksey Midenkov [ 2021-04-24 ]

Since test_versioning plugin is testing-only and probably will be deprecated after MDEV-16226 there is no need to refactor it via MariaDB_FUNCTION_PLUGIN. Also that would not fix versions prior 10.5.

Comment by Oleksandr Byelkin [ 2021-04-26 ]

OK to push

Comment by Julien Fritsch [ 2021-05-03 ]

Removing the remaining effort since this issue is closed.

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