Skip to content

Commit e90ed1c

Browse files
committed
Bug#29625461 DATA INJECTION THROUGH ANALYZE TABLE COMMAND
Problem ======= Audit API generates MYSQL_AUDIT_TABLE_ACCESS_READ for SQL commands that performs table read operation. This was not done for ANALYZE TABLE command. Analysis ======== Audit event generation explicitly specifies the set of sql commands, which generate MYSQL_AUDIT_TABLE_ACCESS_READ event. The set must be extended for ANALYZE TABLE too, since it performs table read operation. Fix === Generate MYSQL_AUDIT_TABLE_ACCESS_READ event for ANALYZE TABLE syntax. This allows for better audit logging as well for audit rule filtering including aborting on command. RB: 22879 Approved by: Georgi 'Joro' Kodinov <[email protected]> Approved by: Harin Vadodaria <[email protected]>
1 parent 83590ff commit e90ed1c

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

mysql-test/suite/audit_null/r/audit_plugin_2.result

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,23 @@ a
600600
SELECT @@null_audit_event_order_check;
601601
@@null_audit_event_order_check
602602
EVENT-ORDER-OK
603+
SET @@null_audit_event_order_check_exact = <expected_check_exact>;
604+
SET @@null_audit_event_order_check = 'MYSQL_AUDIT_COMMAND_START;command_id="<expected_command_id>";;'
605+
'MYSQL_AUDIT_PARSE_PREPARSE;;;'
606+
'MYSQL_AUDIT_PARSE_POSTPARSE;;;'
607+
'MYSQL_AUDIT_GENERAL_LOG;;;'
608+
'MYSQL_AUDIT_QUERY_START;sql_command_id="51";;'
609+
'MYSQL_AUDIT_TABLE_ACCESS_READ;db="super_test" table="test_table";;'
610+
'MYSQL_AUDIT_QUERY_STATUS_END;sql_command_id="51";;'
611+
'MYSQL_AUDIT_GENERAL_RESULT;;;'
612+
'MYSQL_AUDIT_GENERAL_STATUS;;;'
613+
'MYSQL_AUDIT_COMMAND_END;command_id="<expected_command_id>";';
614+
ANALYZE TABLE test_table;
615+
Table Op Msg_type Msg_text
616+
super_test.test_table analyze status OK
617+
SELECT @@null_audit_event_order_check;
618+
@@null_audit_event_order_check
619+
EVENT-ORDER-OK
603620
###########################
604621
## TABLE_ACCESS - INSERT ##
605622
###########################

mysql-test/suite/audit_null/t/audit_plugin_2.test

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,22 @@ eval SET @@null_audit_event_order_check = 'MYSQL_AUDIT_COMMAND_START;command_id=
619619
SELECT * FROM audit_temp_table;
620620
SELECT @@null_audit_event_order_check;
621621

622+
--replace_result $event_order_exact <expected_check_exact>
623+
eval SET @@null_audit_event_order_check_exact = $event_order_exact;
624+
--replace_regex /;command_id="[0-9]+"/;command_id="<expected_command_id>"/
625+
eval SET @@null_audit_event_order_check = 'MYSQL_AUDIT_COMMAND_START;command_id="$command_start_id";;'
626+
'MYSQL_AUDIT_PARSE_PREPARSE;;;'
627+
'MYSQL_AUDIT_PARSE_POSTPARSE;;;'
628+
'MYSQL_AUDIT_GENERAL_LOG;;;'
629+
'MYSQL_AUDIT_QUERY_START;sql_command_id="51";;'
630+
'MYSQL_AUDIT_TABLE_ACCESS_READ;db="super_test" table="test_table";;'
631+
'MYSQL_AUDIT_QUERY_STATUS_END;sql_command_id="51";;'
632+
'MYSQL_AUDIT_GENERAL_RESULT;;;'
633+
'MYSQL_AUDIT_GENERAL_STATUS;;;'
634+
'MYSQL_AUDIT_COMMAND_END;command_id="$command_end_id";';
635+
ANALYZE TABLE test_table;
636+
SELECT @@null_audit_event_order_check;
637+
622638
--echo ###########################
623639
--echo ## TABLE_ACCESS - INSERT ##
624640
--echo ###########################

sql/sql_audit.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,7 @@ int mysql_audit_table_access_notify(THD *thd, TABLE_LIST *table)
689689
break;
690690
case SQLCOM_SELECT:
691691
case SQLCOM_HA_READ:
692+
case SQLCOM_ANALYZE:
692693
set_table_access_subclass(&subclass, &subclass_name,
693694
AUDIT_EVENT(MYSQL_AUDIT_TABLE_ACCESS_READ));
694695
break;

0 commit comments

Comments
 (0)