Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 91796 - dev-db/mysql mysql_install_db insecure tmp file handling
Summary: dev-db/mysql mysql_install_db insecure tmp file handling
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Security
Classification: Unclassified
Component: Vulnerabilities (show other bugs)
Hardware: All Linux
: High enhancement
Assignee: Gentoo Security
URL:
Whiteboard: ~4 [noglsa] jaervosz
Keywords:
Depends on:
Blocks: 83011
  Show dependency tree
 
Reported: 2005-05-07 05:59 UTC by eromang
Modified: 2005-05-17 13:05 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
mysql_emktemp-4.1.11.patch (mysql_emktemp-4.1.11.patch,1.04 KB, patch)
2005-05-08 05:59 UTC, Francesco R. (RETIRED)
no flags Details | Diff
mysql-4.1.11-install_db_tmp.patch (pippo.patch,623 bytes, patch)
2005-05-09 00:43 UTC, Francesco R. (RETIRED)
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description eromang 2005-05-07 05:59:56 UTC
Hello,

Just take a look on mysql_install_db line 14

tmp_file=/tmp/mysql_install_db.$$

Then on :

 226     echo "use mysql;" > $tmp_file
 227     cat $tmp_file $fill_help_tables | eval "$mysqld_install_cmd_line"
 228     res=$?
 229     rm $tmp_file

It's possible to run a TOCTOU, or race condition, that permit to a malicious local user to inject SQL code into the mysql installation.

For exemple :  creating a user with ALL rights.

What you think about ?

Regards.

Reproducible: Always
Steps to Reproduce:
1.
2.
3.

Actual Results:  
tmp_file=/tmp/mysql_install_db.$$ don't use mktemp and umask

Expected Results:  
tmp_file=/tmp/mysql_install_db.$$ shoudl use mktemp and unmask
Comment 1 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2005-05-07 10:34:07 UTC
Auditors please advise.
Comment 2 Robert Paskowitz (RETIRED) gentoo-dev 2005-05-07 17:08:43 UTC
What version of mysql have you found this in? 

Latest available is 4.0.24 and I don't see it there, and the only one more recent is 4.1.8 which is ~arch and package.mask'd.
Comment 3 Romang 2005-05-08 02:56:16 UTC
Hello,

Yes, is 4.1.8 how is considered stable by mysql since q long time :)

Regards.
Comment 4 Francesco R. (RETIRED) gentoo-dev 2005-05-08 03:20:38 UTC
TOCTOU (time of check to time of use)

I've checked /usr/bin/mysql_install_db from mysql-5.0.4_beta probably it's the same for all the other versions.

The TOCTOU it's not possible because only the name of the tmp file is defined early.
>>>echo "use mysql;" > $tmp_file"<<< 
This line write/overwrite the temp file, immediately after the temp file is used to create the db's. ---> no time from "check" to "use"

please close as INVALID
Comment 5 Romang 2005-05-08 03:50:30 UTC
Hello,

it's still possible to inject SQL code in the temporary file how is not created securely.

This is maybe not a TOCTOU but a race condition.

Regards.


Comment 6 Tavis Ormandy (RETIRED) gentoo-dev 2005-05-08 04:02:46 UTC
Francesco: You're correct, this is not a TOCTOU bug, however it does appear to be an insecure tmp handling bug, pid's are easily guessed on most systems, and an attacker could use a linking attack to overwrite or create a file with the permissions of the user running the script, or if he controls the file there is a race condition where he can insert arbitrary mysql commands into the script prior to it being piped into mysql.

I've confirmed this in 4.1.8, does not seem to appear in 4.0.24.
Comment 7 Romang 2005-05-08 04:31:35 UTC
Hello,

I confirm the vulnerability in mysql 4.1.11 the last mysql release avaible from MySQL web site.

Regards.
Comment 8 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2005-05-08 05:26:01 UTC
Upstream informed. Mysql do you prefer to wait for an upstream fix or patch yourself?
Comment 9 Francesco R. (RETIRED) gentoo-dev 2005-05-08 05:59:32 UTC
Created attachment 58346 [details, diff]
mysql_emktemp-4.1.11.patch

Please try and comment the attached patch, it can be applied both at build time
(modifying the ebuild) or to an already installed /usr/bin/mysql_install_db.
Never tested.
Comment 10 Romang 2005-05-08 06:35:23 UTC
Hello,

I have patch the original file, work great.
The installation test like this mysql_install_db --datadir=/tmp/mysql  works, the right are good applied

Tomorrow i will test it on a running mysql server.

Regards.
Comment 11 Romang 2005-05-08 06:42:54 UTC
Hello again,

This files stay's in the /tmp

-rw-------   1 root    root           0 May  8 15:29 tmp.XXXX1v9b6p
-rw-------   1 root    root          11 May  8 15:29 tmp.XXXX6sbldZ
-rw-------   1 root    root           0 May  8 15:31 tmp.XXXXBI2pxY

tmp="${topdir}/tmp.${RANDOM}.${RANDOM}.${RANDOM}"

the first ${RANDOM} is not applied and the date are strange :)

Regards.


Comment 12 Francesco R. (RETIRED) gentoo-dev 2005-05-09 00:43:47 UTC
Created attachment 58452 [details, diff]
mysql-4.1.11-install_db_tmp.patch

This instead is the MySQL patch, expect a new version at bug 83011 before
tomorrow (with this one)
Comment 13 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2005-05-09 22:17:23 UTC
Answer from upstream:

http://mysql.bkbits.net:8080/mysql-4.1/cset@1.2250?nav=index.html|ChangeSet@-1d

The fix will be part of the upcoming 4.1.12 and 5.0.6 releases.
Comment 14 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2005-05-17 02:22:38 UTC
4.1.12 is in the tree now (hard-masked as previous 4.1 releases)
Comment 15 Romang 2005-05-17 03:16:33 UTC
Hi,

In the changelog :

scripts/mysql_install_db.sh
1.72 05/05/09 09:21:49 serg@sergbook.mylan +1 -4
don't use tmp file for such a triviality

Regards.
Comment 16 Romang 2005-05-17 04:08:19 UTC
Hello,

MySQL 5.0.x still vulnerable.

Published under :

http://www.zataz.net/adviso/mysql-05172005.txt

Regards.
Comment 17 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2005-05-17 07:14:56 UTC
Robin any ETA on when this can be unmasked as ~? 
 
Romang did you inform upstream, or should I inform them that MySQL 5 is still 
vulnerable?  
Comment 18 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2005-05-17 07:16:09 UTC
Robin, just saw your mail. 20th of May is planned unmask date. 
Comment 19 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2005-05-17 10:11:29 UTC
jaervosz: I think you mis-read the email.
4.0.24-r2 will go ~arch on 20 May.
4.1* has never been out of the hard-mask yet. This might happen in early June, 
depending how well the larger scale testing goes.
5.0* isn't even in the tree.
Comment 20 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2005-05-17 13:05:04 UTC
Thx for clearing that up Robin. Then we're ready to close.