Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Ping is a a program owned by root with the user id bit set.

$ ls -l `which ping`
-rwsr-xr-x 1 root root 35752 Nov  4  2011 /bin/ping

As I understand it, if a user runs the ping process, then the effective user id will change from the real user id (i.e. the user id of the person who launched the process) to the user id root. However when I try this and look at the output of ps to see if the ping process is running as the root user, I still get the real user id showing.

ps -e -o user,ruser,euser,cmd,args | grep ping
sashan   sashan   sashan   ping -i 10 -c 1000 www.goog ping -i 10 -c 1000 www.google.com
share|improve this question
add comment

1 Answer

up vote 9 down vote accepted

ping needs root so it can open a socket in raw mode. That's literally the first thing it does when it starts up:

icmp_sock = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
socket_errno = errno;

That's the only thing it needs root for, so like many programs, it immediately drops its privilege level back to your normal user account:

uid = getuid();
if (setuid(uid)) {
    perror("ping: setuid");
    exit(-1);
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.