13

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
20

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);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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