-
Website
http://timetobleed.com -
Original page
http://timetobleed.com/5-things-you-dont-know-about-user-ids-that-will-destroy-you/ -
Subscribe
All Comments -
Community
-
Top Commenters
-
Ken Pratt
2 comments · 1 points
-
justin
3 comments · 5 points
-
Joe Damato (ice799)
46 comments · 1 points
-
Roderick van Domburg
1 comment · 1 points
-
Scott Wheeler
1 comment · 1 points
-
-
Popular Threads
-
What is a ruby object? (introducing Memprof.dump)
1 week ago · 8 comments
-
memprof: A Ruby level memory profiler
1 week ago · 9 comments
-
Hot patching inlined functions with x86_64 asm metaprogramming
1 week ago · 2 comments
-
What is a ruby object? (introducing Memprof.dump)
real user IDs in one fell swoop. This is how Mongrel does it:
def change_privilege(user, group)
begin
uid, gid = Process.euid, Process.egid
target_uid = Etc.getpwnam(user).uid if user
target_gid = Etc.getgrnam(group).gid if group
if uid != target_uid or gid != target_gid
log "Initiating groups for #{user.inspect}:#{group.inspect}."
Process.initgroups(user, target_gid)
log "Changing group to #{group.inspect}."
Process::GID.change_privilege(target_gid)
log "Changing user to #{user.inspect}."
Process::UID.change_privilege(target_uid)
end
rescue Errno::EPERM => e
log "Couldn't change user and group to #{user.inspect}:#{group.inspect}:
log "Mongrel failed to start."
exit 1
end
end
The 8-bytes-of-Ruby was particularly chilling.
http://linux.die.net/man/2/setuid
setuid() sets the effective user ID of the current process. If the effective UID of the caller is root, the real UID and saved set-user-ID are also set.
In that case, all 3 IDs are set to the ID passed in.
Sorry about the confusion, I'll see if I can make it a bit more clear.
If you don't understand how they work you shouldn't run anything as root. If you don't know how to safely drop privileges from UID 0 to some other userm then you don't know how to write secure code.
Anyone who thinks they can learn secure programming from the odd page here and there of code snippets is mistaken.
setfsuid(2) etc., credentials(7) and also capabilities(7) are useful manual pages for further exploration for Linux developers.
They also made the code that supposedly safely manipulates identity available here: http://code.google.com/p/change-process-identity/
What you said is true but irrelevant. People aren't writing insecure code intentionally, they're writing it because they don't know how these things work!
The solution isn't to rant and rave about idiot engineers, it's to design systems and libraries that are easy to understand and do the right thing, and make up the difference by educating people.
That's exactly what Joe is doing.