Skip to content

Commit 2c44919

Browse files
committed
Bug #50276: Security flaw in INFORMATION_SCHEMA.TABLES
check_access() returning false for a database does not guarantee that the access is granted to it. This wrong condition in filling the INFORMATION_SCHEMA tables causes extra tables to be returned to the user even if he has no rights to see them. Fixed by correcting the condition.
1 parent 4cfda7f commit 2c44919

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

mysql-test/r/information_schema.result

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,4 +1725,26 @@ SELECT 'OK' AS TEST_RESULT FROM INFORMATION_SCHEMA.PROCESSLIST WHERE time < 0;
17251725
TEST_RESULT
17261726
OK
17271727
SET TIMESTAMP=DEFAULT;
1728+
#
1729+
# Bug #50276: Security flaw in INFORMATION_SCHEMA.TABLES
1730+
#
1731+
CREATE DATABASE db1;
1732+
USE db1;
1733+
CREATE TABLE t1 (id INT);
1734+
CREATE USER nonpriv;
1735+
USE test;
1736+
# connected as nonpriv
1737+
# Should return 0
1738+
SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='t1';
1739+
COUNT(*)
1740+
0
1741+
USE INFORMATION_SCHEMA;
1742+
# Should return 0
1743+
SELECT COUNT(*) FROM TABLES WHERE TABLE_NAME='t1';
1744+
COUNT(*)
1745+
0
1746+
# connected as root
1747+
DROP USER nonpriv;
1748+
DROP TABLE db1.t1;
1749+
DROP DATABASE db1;
17281750
End of 5.1 tests.

mysql-test/t/information_schema.test

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,33 @@ SET TIMESTAMP=@@TIMESTAMP + 10000000;
14191419
SELECT 'OK' AS TEST_RESULT FROM INFORMATION_SCHEMA.PROCESSLIST WHERE time < 0;
14201420
SET TIMESTAMP=DEFAULT;
14211421

1422+
1423+
--echo #
1424+
--echo # Bug #50276: Security flaw in INFORMATION_SCHEMA.TABLES
1425+
--echo #
1426+
CREATE DATABASE db1;
1427+
USE db1;
1428+
CREATE TABLE t1 (id INT);
1429+
CREATE USER nonpriv;
1430+
USE test;
1431+
1432+
connect (nonpriv_con, localhost, nonpriv,,);
1433+
connection nonpriv_con;
1434+
--echo # connected as nonpriv
1435+
--echo # Should return 0
1436+
SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='t1';
1437+
USE INFORMATION_SCHEMA;
1438+
--echo # Should return 0
1439+
SELECT COUNT(*) FROM TABLES WHERE TABLE_NAME='t1';
1440+
1441+
connection default;
1442+
--echo # connected as root
1443+
disconnect nonpriv_con;
1444+
DROP USER nonpriv;
1445+
DROP TABLE db1.t1;
1446+
DROP DATABASE db1;
1447+
1448+
14221449
--echo End of 5.1 tests.
14231450

14241451
# Wait till all disconnects are completed

sql/sql_show.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3367,11 +3367,11 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
33673367
while ((db_name= it++))
33683368
{
33693369
#ifndef NO_EMBEDDED_ACCESS_CHECKS
3370-
if (!check_access(thd,SELECT_ACL, db_name->str,
3371-
&thd->col_access, 0, 1, with_i_schema) ||
3370+
if (!(check_access(thd,SELECT_ACL, db_name->str,
3371+
&thd->col_access, 0, 1, with_i_schema) ||
3372+
(!thd->col_access && check_grant_db(thd, db_name->str))) ||
33723373
sctx->master_access & (DB_ACLS | SHOW_DB_ACL) ||
3373-
acl_get(sctx->host, sctx->ip, sctx->priv_user, db_name->str, 0) ||
3374-
!check_grant_db(thd, db_name->str))
3374+
acl_get(sctx->host, sctx->ip, sctx->priv_user, db_name->str, 0))
33753375
#endif
33763376
{
33773377
thd->no_warnings_for_error= 1;

0 commit comments

Comments
 (0)