summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2010-01-08 17:07:22 +1100
committerDarren Tucker <dtucker@zip.com.au>2010-01-08 17:07:22 +1100
commit6e7fe1c01b8a69099ffc42e653cc478509e84781 (patch)
treed6636498087a2b9b4fd4651edd4e0f07788e51e1
parentf788a91624601857c586a4dd97c66083946e7781 (diff)
- dtucker@cvs.openbsd.org 2009/11/10 04:30:45
[sshconnect2.c channels.c sshconnect.c] Set close-on-exec on various descriptors so they don't get leaked to child processes. bz #1643, patch from jchadima at redhat, ok deraadt.
-rw-r--r--ChangeLog4
-rw-r--r--channels.c10
-rw-r--r--sshconnect.c8
-rw-r--r--sshconnect2.c5
4 files changed, 22 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 604b5d773..a2cee09d5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -47,6 +47,10 @@
47 [sshd_config.5] 47 [sshd_config.5]
48 clarify that StrictModes does not apply to ChrootDirectory. Permissions 48 clarify that StrictModes does not apply to ChrootDirectory. Permissions
49 and ownership are always checked when chrooting. bz#1532 49 and ownership are always checked when chrooting. bz#1532
50 - dtucker@cvs.openbsd.org 2009/11/10 04:30:45
51 [sshconnect2.c channels.c sshconnect.c]
52 Set close-on-exec on various descriptors so they don't get leaked to
53 child processes. bz #1643, patch from jchadima at redhat, ok deraadt.
50 54
5120091226 5520091226
52 - (tim) [contrib/cygwin/Makefile] Install ssh-copy-id and ssh-copy-id.1 56 - (tim) [contrib/cygwin/Makefile] Install ssh-copy-id and ssh-copy-id.1
diff --git a/channels.c b/channels.c
index 884c14c99..eb0c61d8b 100644
--- a/channels.c
+++ b/channels.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: channels.c,v 1.297 2009/10/28 16:38:18 reyk Exp $ */ 1/* $OpenBSD: channels.c,v 1.298 2009/11/10 04:30:44 dtucker Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -53,6 +53,7 @@
53#include <arpa/inet.h> 53#include <arpa/inet.h>
54 54
55#include <errno.h> 55#include <errno.h>
56#include <fcntl.h>
56#include <netdb.h> 57#include <netdb.h>
57#include <stdio.h> 58#include <stdio.h>
58#include <stdlib.h> 59#include <stdlib.h>
@@ -231,7 +232,12 @@ channel_register_fds(Channel *c, int rfd, int wfd, int efd,
231 channel_max_fd = MAX(channel_max_fd, wfd); 232 channel_max_fd = MAX(channel_max_fd, wfd);
232 channel_max_fd = MAX(channel_max_fd, efd); 233 channel_max_fd = MAX(channel_max_fd, efd);
233 234
234 /* XXX set close-on-exec -markus */ 235 if (rfd != -1)
236 fcntl(rfd, F_SETFD, FD_CLOEXEC);
237 if (wfd != -1 && wfd != rfd)
238 fcntl(wfd, F_SETFD, FD_CLOEXEC);
239 if (efd != -1 && efd != rfd && efd != wfd)
240 fcntl(efd, F_SETFD, FD_CLOEXEC);
235 241
236 c->rfd = rfd; 242 c->rfd = rfd;
237 c->wfd = wfd; 243 c->wfd = wfd;
diff --git a/sshconnect.c b/sshconnect.c
index a09026e65..3c8308ffb 100644
--- a/sshconnect.c
+++ b/sshconnect.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshconnect.c,v 1.215 2009/10/28 16:38:18 reyk Exp $ */ 1/* $OpenBSD: sshconnect.c,v 1.216 2009/11/10 04:30:45 dtucker Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -28,6 +28,7 @@
28 28
29#include <ctype.h> 29#include <ctype.h>
30#include <errno.h> 30#include <errno.h>
31#include <fcntl.h>
31#include <netdb.h> 32#include <netdb.h>
32#ifdef HAVE_PATHS_H 33#ifdef HAVE_PATHS_H
33#include <paths.h> 34#include <paths.h>
@@ -192,8 +193,11 @@ ssh_create_socket(int privileged, struct addrinfo *ai)
192 } 193 }
193 sock = socket_rdomain(ai->ai_family, ai->ai_socktype, ai->ai_protocol, 194 sock = socket_rdomain(ai->ai_family, ai->ai_socktype, ai->ai_protocol,
194 options.rdomain); 195 options.rdomain);
195 if (sock < 0) 196 if (sock < 0) {
196 error("socket: %.100s", strerror(errno)); 197 error("socket: %.100s", strerror(errno));
198 return -1;
199 }
200 fcntl(sock, F_SETFD, FD_CLOEXEC);
197 201
198 /* Bind the socket to an alternative local IP address */ 202 /* Bind the socket to an alternative local IP address */
199 if (options.bind_address == NULL) 203 if (options.bind_address == NULL)
diff --git a/sshconnect2.c b/sshconnect2.c
index 937bb773d..299d4f4e3 100644
--- a/sshconnect2.c
+++ b/sshconnect2.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshconnect2.c,v 1.173 2009/10/24 11:13:54 andreas Exp $ */ 1/* $OpenBSD: sshconnect2.c,v 1.174 2009/11/10 04:30:45 dtucker Exp $ */
2/* 2/*
3 * Copyright (c) 2000 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000 Markus Friedl. All rights reserved.
4 * Copyright (c) 2008 Damien Miller. All rights reserved. 4 * Copyright (c) 2008 Damien Miller. All rights reserved.
@@ -32,6 +32,7 @@
32#include <sys/stat.h> 32#include <sys/stat.h>
33 33
34#include <errno.h> 34#include <errno.h>
35#include <fcntl.h>
35#include <netdb.h> 36#include <netdb.h>
36#include <pwd.h> 37#include <pwd.h>
37#include <signal.h> 38#include <signal.h>
@@ -1527,6 +1528,8 @@ ssh_keysign(Key *key, u_char **sigp, u_int *lenp,
1527 return -1; 1528 return -1;
1528 } 1529 }
1529 if (pid == 0) { 1530 if (pid == 0) {
1531 /* keep the socket on exec */
1532 fcntl(packet_get_connection_in(), F_SETFD, 0);
1530 permanently_drop_suid(getuid()); 1533 permanently_drop_suid(getuid());
1531 close(from[0]); 1534 close(from[0]);
1532 if (dup2(from[1], STDOUT_FILENO) < 0) 1535 if (dup2(from[1], STDOUT_FILENO) < 0)