diff options
author | 2014-04-20 17:51:27 +0800 | |
---|---|---|
committer | 2014-04-27 12:26:17 +0800 | |
commit | 8412c867a501e3a68e55fef6215e86d3ac9f617b (patch) | |
tree | 76e27c90b5fa75816692c1b493dc65734aec7993 /fishd.cpp | |
parent | 10642a34f17ae45bd93be3ae6021ee920d3da0c2 (diff) |
Check effective credentials of socket peers
Fix for CVE-2014-2905.
Code for getpeereid() on non-BSD systems imported from the PostgreSQL
project under a BSD-style license.
Diffstat (limited to 'fishd.cpp')
-rw-r--r-- | fishd.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -880,6 +880,8 @@ int main(int argc, char ** argv) int child_socket; struct sockaddr_un remote; socklen_t t; + uid_t sock_euid; + gid_t sock_egid; int max_fd; int update_count=0; @@ -1000,7 +1002,12 @@ int main(int argc, char ** argv) { debug(4, L"Connected with new child on fd %d", child_socket); - if (make_fd_nonblocking(child_socket) != 0) + if (((getpeereid(child_socket, &sock_euid, &sock_egid) != 0) || sock_euid != geteuid())) + { + debug(1, L"Wrong credentials for child on fd %d", child_socket); + close(child_socket); + } + else if (make_fd_nonblocking(child_socket) != 0) { wperror(L"fcntl"); close(child_socket); |