zardus / preeny

Some helpful preload libraries for pwning stuff.
BSD 2-Clause "Simplified" License
1.56k stars 171 forks source link

call to exit() in desock.c::accept() #63

Open suyashmahar opened 4 years ago

suyashmahar commented 4 years ago

When trying to use redis with desock I ran into an issue where redis would exit right after it receives any input in STDIN, using gdb I found out that this is due to the exit(0) call in desock.c::accept(). Now, when I comment out line 216 and 217 everything works as expected.

I see that this was added with this commit, any reason why redis behaves this way?

zardus commented 4 years ago

I think it's to handle the following case:

while (1)
{
    int fd = accept();
    int pid = fork();
    if (pid) { close(fd); wait(pid); }
    else { handle_request(fd); }
}

If we desock the program, we probably want to only handle one request (at least, this has been my use-case so far), hence the exit on the second accept.

I'm all for having that controlled by an environment variable, though!

reberhardt7 commented 4 years ago

That use case makes a lot of sense. However, I imagine a lot of people (myself included) are using this on servers that offload the request to a thread pool or use nonblocking I/O to accept a large number of concurrent connections. I'm using desock on nginx, and it exits before the first request can be serviced.

Should this be the default behavior? Wouldn't it be better to have an optional env var to enable this on applications that only service one request at a time?

hillu commented 4 years ago

My commit dd96c133f6651380e6204f01c70d36d51af7e73a which has been merged moves the exit call from accept to close/shutdown, so this should fix the issue.