forked from openssh/openssh-portable
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upstream: Remove support for running ssh(1) setuid and fatal if
attempted. Do not link uidwap.c into ssh any more. Neuters UsePrivilegedPort, which will be marked as deprecated shortly. ok markus@ djm@ OpenBSD-Commit-ID: c4ba5bf9c096f57a6ed15b713a1d7e9e2e373c42
- Loading branch information
Showing
11 changed files
with
22 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* $OpenBSD: readconf.c,v 1.292 2018/07/04 13:49:31 djm Exp $ */ | ||
/* $OpenBSD: readconf.c,v 1.293 2018/07/18 11:34:04 dtucker Exp $ */ | ||
/* | ||
* Author: Tatu Ylonen <[email protected]> | ||
* Copyright (c) 1995 Tatu Ylonen <[email protected]>, Espoo, Finland | ||
|
@@ -498,9 +498,6 @@ execute_in_shell(const char *cmd) | |
if ((pid = fork()) == 0) { | ||
char *argv[4]; | ||
|
||
/* Child. Permanently give up superuser privileges. */ | ||
permanently_drop_suid(original_real_uid); | ||
|
||
/* Redirect child stdin and stdout. Leave stderr */ | ||
if (dup2(devnull, STDIN_FILENO) == -1) | ||
fatal("dup2: %s", strerror(errno)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* $OpenBSD: ssh.c,v 1.486 2018/07/16 22:25:01 dtucker Exp $ */ | ||
/* $OpenBSD: ssh.c,v 1.487 2018/07/18 11:34:04 dtucker Exp $ */ | ||
/* | ||
* Author: Tatu Ylonen <[email protected]> | ||
* Copyright (c) 1995 Tatu Ylonen <[email protected]>, Espoo, Finland | ||
|
@@ -104,7 +104,6 @@ | |
#include "sshpty.h" | ||
#include "match.h" | ||
#include "msg.h" | ||
#include "uidswap.h" | ||
#include "version.h" | ||
#include "ssherr.h" | ||
#include "myproposal.h" | ||
|
@@ -628,24 +627,6 @@ main(int ac, char **av) | |
original_real_uid = getuid(); | ||
original_effective_uid = geteuid(); | ||
|
||
/* | ||
* Use uid-swapping to give up root privileges for the duration of | ||
* option processing. We will re-instantiate the rights when we are | ||
* ready to create the privileged port, and will permanently drop | ||
* them when the port has been created (actually, when the connection | ||
* has been made, as we may need to create the port several times). | ||
*/ | ||
PRIV_END; | ||
|
||
#ifdef HAVE_SETRLIMIT | ||
/* If we are installed setuid root be careful to not drop core. */ | ||
if (original_real_uid != original_effective_uid) { | ||
struct rlimit rlim; | ||
rlim.rlim_cur = rlim.rlim_max = 0; | ||
if (setrlimit(RLIMIT_CORE, &rlim) < 0) | ||
fatal("setrlimit failed: %.100s", strerror(errno)); | ||
} | ||
#endif | ||
/* Get user data. */ | ||
pw = getpwuid(original_real_uid); | ||
if (!pw) { | ||
|
@@ -1448,22 +1429,8 @@ main(int ac, char **av) | |
L_PUBKEY(_PATH_HOST_XMSS_KEY_FILE, 9); | ||
} | ||
} | ||
/* | ||
* Get rid of any extra privileges that we may have. We will no | ||
* longer need them. Also, extra privileges could make it very hard | ||
* to read identity files and other non-world-readable files from the | ||
* user's home directory if it happens to be on a NFS volume where | ||
* root is mapped to nobody. | ||
*/ | ||
if (original_effective_uid == 0) { | ||
PRIV_START; | ||
permanently_set_uid(pw); | ||
} | ||
|
||
/* | ||
* Now that we are back to our own permissions, create ~/.ssh | ||
* directory if it doesn't already exist. | ||
*/ | ||
/* Create ~/.ssh * directory if it doesn't already exist. */ | ||
if (config == NULL) { | ||
r = snprintf(buf, sizeof buf, "%s%s%s", pw->pw_dir, | ||
strcmp(pw->pw_dir, "/") ? "/" : "", _PATH_SSH_USER_DIR); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* $OpenBSD: sshconnect.c,v 1.300 2018/07/11 18:53:29 markus Exp $ */ | ||
/* $OpenBSD: sshconnect.c,v 1.301 2018/07/18 11:34:04 dtucker Exp $ */ | ||
/* | ||
* Author: Tatu Ylonen <[email protected]> | ||
* Copyright (c) 1995 Tatu Ylonen <[email protected]>, Espoo, Finland | ||
|
@@ -53,7 +53,6 @@ | |
#include "ssh.h" | ||
#include "sshbuf.h" | ||
#include "packet.h" | ||
#include "uidswap.h" | ||
#include "compat.h" | ||
#include "sshkey.h" | ||
#include "sshconnect.h" | ||
|
@@ -130,9 +129,6 @@ ssh_proxy_fdpass_connect(struct ssh *ssh, const char *host, u_short port, | |
if ((pid = fork()) == 0) { | ||
char *argv[10]; | ||
|
||
/* Child. Permanently give up superuser privileges. */ | ||
permanently_drop_suid(original_real_uid); | ||
|
||
close(sp[1]); | ||
/* Redirect stdin and stdout. */ | ||
if (sp[0] != 0) { | ||
|
@@ -212,9 +208,6 @@ ssh_proxy_connect(struct ssh *ssh, const char *host, u_short port, | |
if ((pid = fork()) == 0) { | ||
char *argv[10]; | ||
|
||
/* Child. Permanently give up superuser privileges. */ | ||
permanently_drop_suid(original_real_uid); | ||
|
||
/* Redirect stdin and stdout. */ | ||
close(pin[1]); | ||
if (pin[0] != 0) { | ||
|
@@ -342,7 +335,7 @@ check_ifaddrs(const char *ifname, int af, const struct ifaddrs *ifaddrs, | |
static int | ||
ssh_create_socket(int privileged, struct addrinfo *ai) | ||
{ | ||
int sock, r, oerrno; | ||
int sock, r; | ||
struct sockaddr_storage bindaddr; | ||
socklen_t bindaddrlen = 0; | ||
struct addrinfo hints, *res = NULL; | ||
|
@@ -409,22 +402,7 @@ ssh_create_socket(int privileged, struct addrinfo *ai) | |
ssh_gai_strerror(r)); | ||
goto fail; | ||
} | ||
/* | ||
* If we are running as root and want to connect to a privileged | ||
* port, bind our own socket to a privileged port. | ||
*/ | ||
if (privileged) { | ||
PRIV_START; | ||
r = bindresvport_sa(sock, | ||
bindaddrlen == 0 ? NULL : (struct sockaddr *)&bindaddr); | ||
oerrno = errno; | ||
PRIV_END; | ||
if (r < 0) { | ||
error("bindresvport_sa %s: %s", ntop, | ||
strerror(oerrno)); | ||
goto fail; | ||
} | ||
} else if (bind(sock, (struct sockaddr *)&bindaddr, bindaddrlen) != 0) { | ||
if (bind(sock, (struct sockaddr *)&bindaddr, bindaddrlen) != 0) { | ||
error("bind %s: %s", ntop, strerror(errno)); | ||
goto fail; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* $OpenBSD: uidswap.c,v 1.40 2018/06/15 07:01:11 djm Exp $ */ | ||
/* $OpenBSD: uidswap.c,v 1.41 2018/07/18 11:34:04 dtucker Exp $ */ | ||
/* | ||
* Author: Tatu Ylonen <[email protected]> | ||
* Copyright (c) 1995 Tatu Ylonen <[email protected]>, Espoo, Finland | ||
|
@@ -135,37 +135,6 @@ temporarily_use_uid(struct passwd *pw) | |
strerror(errno)); | ||
} | ||
|
||
void | ||
permanently_drop_suid(uid_t uid) | ||
{ | ||
#ifndef NO_UID_RESTORATION_TEST | ||
uid_t old_uid = getuid(); | ||
#endif | ||
|
||
debug("permanently_drop_suid: %u", (u_int)uid); | ||
if (setresuid(uid, uid, uid) < 0) | ||
fatal("setresuid %u: %.100s", (u_int)uid, strerror(errno)); | ||
|
||
#ifndef NO_UID_RESTORATION_TEST | ||
/* | ||
* Try restoration of UID if changed (test clearing of saved uid). | ||
* | ||
* Note that we don't do this on Cygwin, or on Solaris-based platforms | ||
* where fine-grained privileges are available (the user might be | ||
* deliberately allowed the right to setuid back to root). | ||
*/ | ||
if (old_uid != uid && | ||
(setuid(old_uid) != -1 || seteuid(old_uid) != -1)) | ||
fatal("%s: was able to restore old [e]uid", __func__); | ||
#endif | ||
|
||
/* Verify UID drop was successful */ | ||
if (getuid() != uid || geteuid() != uid) { | ||
fatal("%s: euid incorrect uid:%u euid:%u (should be %u)", | ||
__func__, (u_int)getuid(), (u_int)geteuid(), (u_int)uid); | ||
} | ||
} | ||
|
||
/* | ||
* Restores to the original (privileged) uid. | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* $OpenBSD: uidswap.h,v 1.13 2006/08/03 03:34:42 deraadt Exp $ */ | ||
/* $OpenBSD: uidswap.h,v 1.14 2018/07/18 11:34:05 dtucker Exp $ */ | ||
|
||
/* | ||
* Author: Tatu Ylonen <[email protected]> | ||
|
@@ -15,4 +15,3 @@ | |
void temporarily_use_uid(struct passwd *); | ||
void restore_uid(void); | ||
void permanently_set_uid(struct passwd *); | ||
void permanently_drop_suid(uid_t); |