useradd/groupadd existence check races
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Shadow |
New
|
Undecided
|
Unassigned | ||
shadow (Debian) |
New
|
Undecided
|
Unassigned | ||
shadow (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
useradd has a race between checking if a username is already in use and updating the pw database:
getpwnam check <http://
open_files lock on line 2127 of same
groupadd has a race between checking if a groupname is already in use and updating the gr database:
getgrnam check <http://
open_files lock on line 609 of same
This race is exhibited when multiple processes attempt to use the error return code of useradd/groupadd to indicate whether they have successfully created a unique user for themselves. If the race occurs, the uid/gid of the database entry may change out from under the first successful process as the second process finds an unused uid/gid and then updates the database using the same key (but the new uid/gid).
I believe this bug exists since at least shadow 4.1.4.2 in both Ubuntu and Debian distributions. I don't believe this bug is a security vulnerability except in contexts where attackers may have control over user/group creation by applications assuming that the database locks ensure non-collision.
Obligatory:
1)# lsb_release -rd
Description: Ubuntu 10.04 LTS
Release: 10.04
2)# apt-cache policy passwd
passwd:
Installed: 1:4.1.4.
Candidate: 1:4.1.4.
Version table:
*** 1:4.1.4.
500 http://
500 http://
100 /var/lib/
1:
500 http://
3) groupadd/useradd should either consistently let the operator overwrite existing groups/users or should consistently produce a name collision error
4) groupadd/useradd sometimes exit due to name collisions and sometimes overwrite existing groups/users