Bug #64522 Effective UID issue

Submitted: 2 Mar 2012 11:28 Modified: 6 Mar 2012 18:29
Reporter: Sebastien Termeau Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.1.61, 5.5.21, 5.6.5 OS:Linux (RHEL 6.2 64 bit)
Assigned to: CPU Architecture:Any
Tags: 5.5.21

[2 Mar 2012 11:28] Sebastien Termeau
Description:
Mysql does not use the effective UID but the real uid.

How to repeat:
login to a server as user_a
sudo su - user_b
  > mysql
  >> ERROR 1045 (28000): Access denied for user 'user_a'@'localhost' (using password: NO)

strace shows the call to geteuid return the correct uid but then mysql checks the content of /proc/self/loginuid which contains the uid of user_a

Here is the end of the strace.
The uid of user_a is 42584 and the uid of user_b is 201
#################
geteuid()                               = 201
open("/proc/self/loginuid", O_RDONLY)   = 4
read(4, "42584", 12)                    = 5
close(4)                                = 0
socket(PF_FILE, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 4
connect(4, {sa_family=AF_FILE, path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory)
close(4)                                = 0
socket(PF_FILE, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 4
connect(4, {sa_family=AF_FILE, path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory)
close(4)                                = 0
open("/etc/passwd", O_RDONLY|O_CLOEXEC) = 4
fstat(4, {st_mode=S_IFREG|0644, st_size=1823, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f98f3b73000
read(4, "root:x:0:0:root:/root:/bin/bash\n"..., 4096) = 1823
close(4)                                = 0
munmap(0x7f98f3b73000, 4096)            = 0
write(3, "(\0\0\1\205\246\3\0\0\0\0\1\10\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 44) = 44
read(3, "I\0\0\2\377\25\4#28000Access denied for u"..., 16384) = 77
shutdown(3, 2 /* send and receive */)   = 0
close(3)                                = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 4), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f98f3b73000
write(2, "ERROR 1045 (28000): ", 20ERROR 1045 (28000): )    = 20
write(2, "Access denied for user 'user_a'@"..., 64Access denied for user 'user_a'@'localhost' (using password: NO)) = 64
write(2, "\n", 1
)                       = 1
write(1, "\7", 1)                       = 1
exit_group(1)                           = ?
[6 Mar 2012 16:16] Sveta Smirnova
Thank you for the report.

I can not repeat described behavior:

[sveta@delly mysql-test]$ ../client/mysql -S  /home/sveta/src/mysql-trunk/mysql-test/var/tmp/mysqld.1.sock 
ERROR 1045 (28000): Access denied for user 'sveta'@'localhost' (using password: NO)
[sveta@delly mysql-test]$ su
Password: 
[root@delly mysql-test]# ../client/mysql -S  /home/sveta/src/mysql-trunk/mysql-test/var/tmp/mysqld.1.sock 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.5-m8-debug-log Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> \q
Bye
[root@delly mysql-test]# cat /proc/self/loginuid
500[root@delly mysql-test]# exit
exit
[sveta@delly mysql-test]$ su - root
Password: 
[root@delly ~]# ../client/mysql -S  /home/sveta/src/mysql-trunk/mysql-test/var/tmp/mysqld.1.sock 
-bash: ../client/mysql: No such file or directory
[root@delly ~]# /home/sveta/src/mysql-trunk/mysql-test/../client/mysql -S  /home/sveta/src/mysql-trunk/mysql-test/var/tmp/mysqld.1.sock 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.5-m8-debug-log Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> \q
Bye

Could you post similar session from your environment?
[6 Mar 2012 18:17] Sebastien Termeau
Hi,

I wasn't able to reproduce this when login as root neither.
Could you please try to login as a user with a uid different than 0?
[6 Mar 2012 18:29] Sveta Smirnova
Thank you for the feedback.

Verified as described:

[sveta@delly mysql-test]$ su - foobar
Password: 
su: warning: cannot change directory to /home/foobar: No such file or directory
-bash-4.1$ home/sveta/src/mysql-5.5/mysql-test/var/tmp/mysqld.1.sock^C
-bash-4.1$ ../client/mysql -h127.0.0.1 -P13000
ERROR 1045 (28000): Access denied for user 'sveta'@'localhost' (using password: NO)
[9 Nov 2012 1:20] Richlv -
maybe this bit is useful. at least in my environment mysql only does this if .my.cnf file is present (only with [client] and password=aa directives)

so "su - user" with .my.cnf - uses original (wrong) user. without - uses the correct one.
[21 Aug 2013 14:40] Prabhu Shankar
Is this bug fixed?
[22 Dec 2014 18:16] Colin Kuskie
I'm having similar issues.

I remotely log into a server using opensuse 13.1/mysql  Ver 14.14 Distrib 5.6.12 on 64-bit.

I use sudo to become root
Then I use su to become another user.

If I try to connect to mysql without specifying a user on the command-line client, then it fails with this response:

ERROR 1045 (28000): Access denied for user 'colin'@'localhost' (using password: NO)

This is exactly the behavior described by the original poster.
[22 Mar 2016 5:45] Calvin Sun
Fix of bug#64622

Attachment: bug64522.patch (application/octet-stream, text), 756 bytes.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.061 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.