Skip to content

Commit 8ed6479

Browse files
BUG#31553323: INFORMATION_SCHEMA.TABLES RETURNS INFORMATION ABOUT TABLES WITHOUT PERMISSIONS
ANALYSIS: ========= Issue here is, a user who doesn't have access to certain tables is able to obtain information about those tables through the Information_schema. The issue occurred because of missing table level privilege checks when accessing table information from Information schema tables. FIX: ==== Added a check to verify table level privileges for the user when accessing table information from Information_Schema tables. Change-Id: Ied11c765f860bdf84082559ed972ec20d91b6433
1 parent 28941bb commit 8ed6479

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

mysql-test/r/grant4.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ GRANT SHOW VIEW ON v2 to mysqltest_u1@localhost;
8585
GRANT SHOW VIEW, SELECT ON v3 to mysqltest_u1@localhost;
8686
use mysqltest_db1;
8787
** Connect as restricted user mysqltest_u1.
88-
** SELECT FROM INFORMATION_SCHEMA.STATISTICS will succeed because any privileges will do (authentication is enough).
88+
# The user does not have table level grants on table t5. Hence cannot get
89+
# information about it from INFORMATION_SCHEMA.STATISTICS
8990
SELECT * FROM INFORMATION_SCHEMA.STATISTICS WHERE table_name='t5';
9091
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME NON_UNIQUE INDEX_SCHEMA INDEX_NAME SEQ_IN_INDEX COLUMN_NAME COLLATION CARDINALITY SUB_PART PACKED NULLABLE INDEX_TYPE COMMENT INDEX_COMMENT
91-
def mysqltest_db1 t5 1 mysqltest_db1 i 1 s1 A NULL NULL NULL YES BTREE
9292
** SHOW INDEX FROM t5 will fail because we don't have any privileges on any column combination.
9393
SHOW INDEX FROM t5;
9494
ERROR 42000: SELECT command denied to user 'mysqltest_u1'@'localhost' for table 't5'

mysql-test/t/grant4.test

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,8 @@ GRANT SHOW VIEW, SELECT ON v3 to mysqltest_u1@localhost;
103103
connection con1;
104104
use mysqltest_db1;
105105
--echo ** Connect as restricted user mysqltest_u1.
106-
--echo ** SELECT FROM INFORMATION_SCHEMA.STATISTICS will succeed because any privileges will do (authentication is enough).
107-
#
108-
# this result is wrong. reported as bug#34104
109-
#
106+
--echo # The user does not have table level grants on table t5. Hence cannot get
107+
--echo # information about it from INFORMATION_SCHEMA.STATISTICS
110108
SELECT * FROM INFORMATION_SCHEMA.STATISTICS WHERE table_name='t5';
111109
#
112110
# Bug27145 EXTRA_ACL trouble

sql/sql_show.cc

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3415,7 +3415,28 @@ make_table_name_list(THD *thd, List<LEX_STRING> *table_names, LEX *lex,
34153415
}
34163416
}
34173417
else
3418-
{
3418+
{
3419+
#ifndef NO_EMBEDDED_ACCESS_CHECKS
3420+
if (!(thd->col_access & TABLE_ACLS))
3421+
{
3422+
TABLE_LIST table_list;
3423+
memset(&table_list, 0, sizeof(table_list));
3424+
3425+
/*
3426+
Database name and table name have already been converted to lowercase
3427+
if lower_case_table_names is > 0. We can safely use lookup_field_vals
3428+
here.
3429+
*/
3430+
table_list.db= db_name->str;
3431+
table_list.db_length= db_name->length;
3432+
table_list.table_name_length= lookup_field_vals->table_value.length;
3433+
table_list.table_name= lookup_field_vals->table_value.str;
3434+
table_list.grant.privilege=thd->col_access;
3435+
3436+
if (check_grant(thd, TABLE_ACLS, &table_list, TRUE, 1, TRUE))
3437+
return 2;
3438+
}
3439+
#endif
34193440
if (table_names->push_back(&lookup_field_vals->table_value))
34203441
return 1;
34213442
/*

0 commit comments

Comments
 (0)