Skip to content

Commit 6a893b8

Browse files
author
Arun Kuruvila
committed
Bug#29248047: 5.7 AUDIT PLUGIN DOES NOT LOG WHO UNINSTALLS
THE AUDIT PLUGIN UNLIKE 5.6 Description: Audit record for "UNINSTALL PLUGIN audit_log" is not logged in the audit log for mysql-5.7+. But in 5.6, this record is logged. Analysis: In 5.7, this issue got introduced by the fix for Bug#23236404. Before the fix, audit plugins are acquired on the first use and released after the execution of each query. As part of the fix, audit plugins are acquired on the first use and released when the connection ends. Before the fix, 'mysql_audit_release()' was done before 'do_command()' which will ensure that the plugin is released after execution of each query. This guaranteed "UNINSTALL PLUGIN audit_log" query to be recorded in the audit log since the 'plugin_deinitialize()' [as part of 'mysql_audit_release()' during plugin release] happens after the logging of the UNINSTALL PLUGIN audit record. But as part of the fix, 'mysql_audit_release()' is moved inside 'Sql_cmd_uninstall_plugin::execute()'. Due to this, audit log gets deinitialized as part of "plugin_deinitialize()" during the execution of 'Sql_cmd_uninstall_plugin::execute()'. As a result, when the execution reaches the point where the audit record for "UNINSTALL PLUGIN audit_log" is logged, it is unable to log the record since the plugin is already deinitialized. Fix: 'mysql_audit_release()' is removed for UNINSTALL PLUGIN command. This is to make sure that a thread that has started as being audited should not be forced into not being audited. RB#21815
1 parent 5c7e6f4 commit 6a893b8

10 files changed

Lines changed: 39 additions & 6 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#
2+
# SUMMARY
3+
# Ensure all the connections are disconnected including default connection.
4+
#
5+
# USAGE
6+
# This is needed to complete a plugin uninstall
7+
#
8+
# EXAMPLE
9+
# audit_log_bugs.test, query_cache.test
10+
#
11+
--source include/count_sessions.inc
12+
disconnect default;
13+
connect(default, localhost, root,,);
14+
--source include/wait_until_count_sessions.inc

‎mysql-test/suite/query_rewrite_plugins/include/reload.inc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ SELECT * FROM test.t2;
2626
DROP PROCEDURE query_rewrite.flush_rewrite_rules;
2727
DROP FUNCTION load_rewrite_rules;
2828
UNINSTALL PLUGIN rewriter;
29+
--source include/disconnect_connections.inc
2930

3031
--echo # Check that the table is still present and didn't get dropped.
3132
SELECT pattern, replacement FROM query_rewrite.rewrite_rules;

‎mysql-test/suite/query_rewrite_plugins/r/multiple.result‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ UNINSTALL PLUGIN rewrite_example;
4343
Warnings:
4444
Note 1105 Query 'UNINSTALL PLUGIN rewrite_example' rewritten to 'uninstall plugin rewrite_example' by a query rewrite plugin
4545
Warning 1620 Plugin is busy and will be uninstalled on shutdown
46+
Note 1105 Query 'SHOW WARNINGS' rewritten to 'show warnings' by a query rewrite plugin
47+
Warnings:
48+
Note 1105 Query 'DROP DATABASE IF EXISTS query_rewrite' rewritten to 'drop database if exists query_rewrite' by a query rewrite plugin
49+
Note 1105 Query 'SHOW WARNINGS' rewritten to 'show warnings' by a query rewrite plugin
4650
Warnings:
51+
Note 1105 Query 'DROP FUNCTION IF EXISTS load_rewrite_rules' rewritten to 'drop function if exists load_rewrite_rules' by a query rewrite plugin
52+
Note 1105 Query 'SHOW WARNINGS' rewritten to 'show warnings' by a query rewrite plugin
53+
Warnings:
54+
Note 1105 Query 'UNINSTALL PLUGIN rewriter' rewritten to 'uninstall plugin rewriter' by a query rewrite plugin
4755
Warning 1620 Plugin is busy and will be uninstalled on shutdown
56+
Note 1105 Query 'SHOW WARNINGS' rewritten to 'show warnings' by a query rewrite plugin
4857
# Query rewrite plugin was queued for uninstalling.

‎mysql-test/suite/query_rewrite_plugins/r/pre_parse_example.result‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ UNINSTALL PLUGIN rewrite_example;
3939
Warnings:
4040
Note 1105 Query 'UNINSTALL PLUGIN rewrite_example' rewritten to 'uninstall plugin rewrite_example' by a query rewrite plugin
4141
Warning 1620 Plugin is busy and will be uninstalled on shutdown
42+
Note 1105 Query 'SHOW WARNINGS' rewritten to 'show warnings' by a query rewrite plugin
4243
SELECT 'UPPERCASE';
4344
UPPERCASE
4445
UPPERCASE

‎mysql-test/suite/query_rewrite_plugins/t/errors.test‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ SELECT search_error_log( '[Error]', "%Plugin Rewriter reported: 'Wrong%" );
4747
SHOW STATUS LIKE 'Rewriter_number_reloads';
4848

4949
--source suite/query_rewrite_plugins/include/uninstall_rewriter.inc
50+
--source include/disconnect_connections.inc
5051

5152
--echo # Create another table with insufficient number of columns.
5253
CREATE DATABASE query_rewrite;
@@ -65,6 +66,7 @@ SHOW STATUS LIKE 'Rewriter_reload_error';
6566
SHOW STATUS LIKE 'Rewriter_number_loaded_rules';
6667

6768
--source suite/query_rewrite_plugins/include/uninstall_rewriter.inc
69+
--source include/disconnect_connections.inc
6870

6971
--source suite/query_rewrite_plugins/include/install_rewriter.inc
7072

@@ -267,6 +269,8 @@ WHERE NAME = 'statements_digest';
267269
--echo # script. The library will not be unloaded so we can still call the UDF
268270
--echo # but it should return an error.
269271
UNINSTALL PLUGIN rewriter;
272+
--source include/disconnect_connections.inc
273+
270274
--error ER_CANT_INITIALIZE_UDF
271275
CALL query_rewrite.flush_rewrite_rules();
272276
--error ER_CANT_INITIALIZE_UDF

‎mysql-test/suite/query_rewrite_plugins/t/pre_parse_example.test‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ SELECT @c2p1;
2828
--enable_warnings
2929

3030
UNINSTALL PLUGIN rewrite_example;
31+
--source include/disconnect_connections.inc
3132

3233
SELECT 'UPPERCASE';

‎mysql-test/suite/query_rewrite_plugins/t/query_cache.test‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ SELECT * FROM test.t1;
9393
DELETE FROM query_rewrite.rewrite_rules;
9494

9595
--source suite/query_rewrite_plugins/include/uninstall_rewriter.inc
96+
--source include/disconnect_connections.inc
9697

9798
SELECT * FROM test.t1;
9899
SELECT * FROM test.t1;

‎mysql-test/suite/query_rewrite_plugins/t/transactions.test‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ SELECT "Rewrite me conn 2";
4747
SELECT xxx(pattern) FROM query_rewrite.rewrite_rules;
4848

4949
--source suite/query_rewrite_plugins/include/uninstall_rewriter.inc
50-
50+
--source include/disconnect_connections.inc
5151

5252
--echo #
5353
--echo # Now make sure that everything works as long we do as we're supposed
@@ -66,7 +66,7 @@ SELECT 'Rewrite me';
6666
SHOW STATUS LIKE 'Rewriter_%';
6767

6868
--source suite/query_rewrite_plugins/include/uninstall_rewriter.inc
69-
69+
--source include/disconnect_connections.inc
7070

7171
--echo #
7272
--echo # Now check that we don't fail even if @@autocommit is 0. In this case
@@ -102,7 +102,7 @@ SELECT 'Rewrite me';
102102
SHOW STATUS LIKE 'Rewriter_%';
103103

104104
--source suite/query_rewrite_plugins/include/uninstall_rewriter.inc
105-
105+
--source include/disconnect_connections.inc
106106

107107
--echo #
108108
--echo # Now let's make sure that everything works fine if we run with

‎mysql-test/t/version_token.test‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ SELECT version_tokens_show();
2222
--replace_regex /\.dll/.so/
2323
eval INSTALL PLUGIN version_tokens SONAME '$VERSION_TOKEN';
2424
UNINSTALL PLUGIN version_tokens;
25+
--source include/disconnect_connections.inc
26+
2527
--replace_regex /\.dll/.so/
2628
eval INSTALL PLUGIN version_tokens SONAME '$VERSION_TOKEN';
2729
UNINSTALL PLUGIN version_tokens;
30+
--source include/disconnect_connections.inc
2831

2932
--echo # Should not crash when unloading the so through removing the UDF
3033
drop function version_tokens_show;
@@ -284,6 +287,8 @@ connection default;
284287

285288
-- echo
286289
UNINSTALL PLUGIN version_tokens;
290+
--source include/disconnect_connections.inc
291+
287292
--disable_result_log
288293
--disable_query_log
289294
let $mysql_errno = 0;

‎sql/sql_plugin.cc‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4448,8 +4448,5 @@ bool Sql_cmd_uninstall_plugin::execute(THD *thd)
44484448
bool st= mysql_uninstall_plugin(thd, &m_comment);
44494449
if (!st)
44504450
my_ok(thd);
4451-
#ifndef EMBEDDED_LIBRARY
4452-
mysql_audit_release(thd);
4453-
#endif
44544451
return st;
44554452
}

0 commit comments

Comments
 (0)