All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/1] *** Fix kill(-1,s) returning 0 on 0 kills ***
@ 2022-11-22 16:12 Petr Skocik
  2022-11-22 16:12 ` [PATCH 1/1] Fix kill(-1,s) returning 0 on 0 kills Petr Skocik
  2022-11-22 17:15 ` [PATCH 0/1] *** Fix kill(-1,s) returning 0 on 0 kills *** Kees Cook
  0 siblings, 2 replies; 23+ messages in thread
From: Petr Skocik @ 2022-11-22 16:12 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: Oleg Nesterov, Kees Cook, Thomas Gleixner, Peter Zijlstra,
	Marco Elver, linux-kernel, Petr Skocik

Hi. I've never sent a kernel patch before but this one seemed trivial,
so I thought I'd give it a shot.

My issue: kill(-1,s) on Linux doesn't return -ESCHR when it has nothing
to kill.

The code sample below demonstrates the problem, which gets fixed by the
patch:

    #define _GNU_SOURCE
    #include <assert.h>
    #include <errno.h>
    #include <signal.h>
    #include <stdio.h>
    #include <sys/wait.h>
    #include <unistd.h>
    #define VICTIM_UID 4200 //check these are safe to use on your system!
    #define UNUSED_UID 4300
    int main(){
        uid_t r,e,s;
        if(geteuid()) return 1; //requires root privileges

        //pipe to let the parent know when the child has changed ids
        int fds[2]; if(0>pipe(fds)) return 1;
        pid_t pid;
        if(0>(pid=fork())) return 1;
        else if(0==pid){
            setreuid(VICTIM_UID,VICTIM_UID);
            getresuid(&r,&e,&s); printf("child: %u %u %u\n", r,e,s);
            close(fds[0]); close(fds[1]); //let the parent continue
            for(;;) pause();
        }
        close(fds[1]);
        read(fds[0],&(char){0},1); //wait for uid change in the child

        #if 1
        setreuid(VICTIM_UID,(uid_t)-1); seteuid(VICTIM_UID);
        #else
        setresuid(UNUSED_UID,VICTIM_UID,0);
        #endif
        getresuid(&r,&e,&s); printf("parent: %u %u %u\n", r,e,s); //4200 4200 0

        int err = kill(-1,-111); (void)err; //test -EINVAL
        assert(err < 0 &&  errno == EINVAL);

        int rc = kill(-1,SIGTERM); //test 0
        if(rc>=0) wait(0);
        int rc2 = kill(-1,SIGTERM); //test -ESCHR
        printf("1st kill ok==%d; 2nd kill ESRCH==%d\n", rc==0, rc2<0&& errno==ESRCH);
    }

Thank you for considering the patch.

Best regards,
Petr S.


Petr Skocik (1):
  Fix kill(-1,s) returning 0 on 0 kills

 kernel/signal.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2023-08-17 15:50 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-22 16:12 [PATCH 0/1] *** Fix kill(-1,s) returning 0 on 0 kills *** Petr Skocik
2022-11-22 16:12 ` [PATCH 1/1] Fix kill(-1,s) returning 0 on 0 kills Petr Skocik
2022-11-23 10:30   ` Oleg Nesterov
2022-11-23 11:20     ` Oleg Nesterov
2022-11-23 11:27     ` Petr Skocik
2022-11-23 11:56       ` Oleg Nesterov
2022-11-22 17:15 ` [PATCH 0/1] *** Fix kill(-1,s) returning 0 on 0 kills *** Kees Cook
2022-11-22 23:01   ` Petr Skocik
2023-08-09 12:27   ` Petr Skocik
2023-08-10 16:16     ` Eric W. Biederman
2023-08-10 21:30       ` Petr Skocik
2023-08-11 21:25         ` Eric W. Biederman
2023-08-11 22:16           ` [PATCH] signal: Fix the error return of kill -1 Eric W. Biederman
2023-08-14 14:06             ` Oleg Nesterov
2023-08-14 15:43               ` Oleg Nesterov
2023-08-15 14:47                 ` David Laight
2023-08-15 15:11                   ` Oleg Nesterov
2023-08-16 20:32                     ` Eric W. Biederman
2023-08-16 21:06                       ` Oleg Nesterov
2023-08-17  2:33                         ` Eric W. Biederman
2023-08-17  4:37                           ` Eric W. Biederman
2023-08-17 15:47                             ` [PATCH] __kill_pgrp_info: simplify the calculation of return value Oleg Nesterov
2023-08-11 23:37           ` [PATCH 0/1] *** Fix kill(-1,s) returning 0 on 0 kills *** Petr Skocik

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.