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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm wondering about the security of UNIX signals.

SIGKILL will kill the process. So, what happens when a non root user's process sends a signal to a root user's process? Does the process still carry out the signal handler?

I follow the accepted answer (gollum's), and I type man capabilites, and I find a lot of things about the Linux kernel. From man capabilities:

NAME

   capabilities - overview of Linux capabilities
DESCRIPTION

   For the purpose of performing permission checks, traditional UNIX
   implementations distinguish two categories of processes: privileged
   processes (whose effective user ID is 0, referred to as superuser or
   root), and unprivileged processes (whose effective UID is nonzero).
   Privileged processes bypass all kernel permission checks, while
   unprivileged processes are subject to full permission checking based
   on the process's credentials (usually: effective UID, effective GID,
   and supplementary group list).

   Starting with kernel 2.2, Linux divides the privileges traditionally
   associated with superuser into distinct units, known as capabilities,
   which can be independently enabled and disabled.  Capabilities are a
   per-thread attribute.
share|improve this question
4  
Other than SIGKILL, which is a special case and managed completely by the kernel, signals are merely a request. The receiving process can do anything they want with them. – chepner Jan 29 at 21:57
2  
@chepner Other than SIGKILL and SIGSTOP... – jlliagre Jan 30 at 14:44
1  
@chepner The receiving process has to actively decide it wants to handle the signal. If the receiving process hasn't done so, then a lot of signals will by default kill the process in exactly the same way SIGKILL would. Initially SIGINT, SIGKILL, and SIGTERM will have the exact same effect, the only difference is that the receiving process can change this default for some of them. – kasperd Jan 30 at 15:01
up vote 33 down vote accepted

On Linux it depends on the file capabilities.

Take the following simple mykill.c source:

#include <stdio.h>
#include <sys/types.h>
#include <signal.h>
#include <stdlib.h>

void exit_usage(const char *prog) {
        printf("usage: %s -<signal> <pid>\n", prog);
        exit(1);
}

int main(int argc, char **argv) {
        pid_t pid;
        int sig;

        if (argc != 3)
                exit_usage(argv[0]);

        sig = atoi(argv[1]);
        pid = atoi(argv[2]);

        if (sig >= 0 || pid < 2)
                exit_usage(argv[0]);

        if (kill(pid, -sig) == -1) {
                perror("failed");
                return 1;
        }
        printf("successfully sent signal %d to process %d\n", -sig, pid);

        return 0;
}

build it:

gcc -Wall mykill.c -o /tmp/mykill

Now as user root start a sleep process in background:

root@horny:/root# /bin/sleep 3600 &
[1] 16098

Now as normal user try to kill it:

demouser@horny:/home/demouser$ ps aux | grep sleep
root     16098  0.0  0.0  11652   696 pts/20   S    15:06   0:00 sleep 500

demouser@horny:/home/demouser$ /tmp/mykill -9 16098
failed: Operation not permitted

Now as root user change the /tmp/mykill caps:

root@horny:/root# setcap cap_kill+ep /tmp/mykill

And try again as normal user:

demouser@horny:/home/demouser$ /tmp/mykill -9 16098
successfully sent signal 9 to process 16098

Finally please delete /tmp/mykill for obvious reasons ;)

share|improve this answer
3  
Follow your clue, I type "man capabilities" and I find a lot of thing about linux kernel – lovespring Jan 29 at 14:41

Nothing:

strace kill -HUP 1
[...]
kill(1, SIGHUP)    = -1 EPERM (Operation not permitted)
[...]
share|improve this answer
1  
Is this kind of security done by os level or hard coded in user's signal handler ? – lovespring Jan 29 at 12:13
3  
@lovespring The kernel doesn't deliver the signal to the target process. The syscall is returned with an error and apart from that ignored. – Hauke Laging Jan 29 at 12:28
    
That is not true in general. It depends on the capabilities. – gollum Jan 29 at 14:21
1  
@psmears yes, but others have similar concepts (e.g. "privileges" on solaris). So the answer "Nothing" is definitely wrong. – gollum Jan 31 at 15:08
1  
@gollum: It's not exactly wrong (after all, it is the default behaviour on all Unix-family OSs, and the only one possible on many - including older Linux kernels for instance) but you're right that it's incomplete - but just mentioning "capabilities" without going into more detail about where they are suported is also incomplete in a question about general Unix :) – psmears Jan 31 at 23:05

kill(2) man page explains:

Linux Notes

Across different kernel versions, Linux has enforced different rules for the permissions required for an unprivileged process to send a signal to another process. In kernels 1.0 to 1.2.2, a signal could be sent if the effective user ID of the sender matched that of the receiver, or the real user ID of the sender matched that of the receiver. From kernel 1.2.3 until 1.3.77, a signal could be sent if the effective user ID of the sender matched either the real or effective user ID of the receiver. The current rules, which conform to POSIX.1-2001, were adopted in kernel 1.3.78.

share|improve this answer
    
1.3.78 is extremely ancient history, as 1.3. dates from 1995 or thereabouts. 1.3 was the development series leading up to 2.0 (in 1996) – vonbrand Jan 30 at 17:41

the signal would carry but the process owner belong to root. so, the other user don't have the right to terminate the process so you will receive permission error problem.

terminate process is only possible when you own the ownership(proper rights) of the process.

share|improve this answer

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.