diff options
author | Colin Watson <cjwatson@debian.org> | 2014-02-10 00:18:28 +0000 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2014-02-10 00:18:28 +0000 |
commit | 9a975a9faed7c4f334e8c8490db3e77e102f2b21 (patch) | |
tree | 764a885ec9a963f6a8b15de6e1765f16b9ac4738 /sshd.c | |
parent | ee196dab7c5f97f0b80c8099343a375bead92010 (diff) | |
parent | cdb6c90811caa5df2df856be9b0b16db020fe31d (diff) |
Import openssh_6.5p1.orig.tar.gz
Diffstat (limited to 'sshd.c')
-rw-r--r-- | sshd.c | 56 |
1 files changed, 37 insertions, 19 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: sshd.c,v 1.404 2013/07/19 07:37:48 markus Exp $ */ | 1 | /* $OpenBSD: sshd.c,v 1.414 2014/01/09 23:26:48 djm 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 |
@@ -315,6 +315,7 @@ static void | |||
315 | sighup_restart(void) | 315 | sighup_restart(void) |
316 | { | 316 | { |
317 | logit("Received SIGHUP; restarting."); | 317 | logit("Received SIGHUP; restarting."); |
318 | platform_pre_restart(); | ||
318 | close_listen_socks(); | 319 | close_listen_socks(); |
319 | close_startup_pipes(); | 320 | close_startup_pipes(); |
320 | alarm(0); /* alarm timer persists across exec */ | 321 | alarm(0); /* alarm timer persists across exec */ |
@@ -371,7 +372,7 @@ grace_alarm_handler(int sig) | |||
371 | */ | 372 | */ |
372 | if (getpgid(0) == getpid()) { | 373 | if (getpgid(0) == getpid()) { |
373 | signal(SIGTERM, SIG_IGN); | 374 | signal(SIGTERM, SIG_IGN); |
374 | killpg(0, SIGTERM); | 375 | kill(0, SIGTERM); |
375 | } | 376 | } |
376 | 377 | ||
377 | /* Log error and exit. */ | 378 | /* Log error and exit. */ |
@@ -397,7 +398,6 @@ generate_ephemeral_server_key(void) | |||
397 | verbose("RSA key generation complete."); | 398 | verbose("RSA key generation complete."); |
398 | 399 | ||
399 | arc4random_buf(sensitive_data.ssh1_cookie, SSH_SESSION_KEY_LENGTH); | 400 | arc4random_buf(sensitive_data.ssh1_cookie, SSH_SESSION_KEY_LENGTH); |
400 | arc4random_stir(); | ||
401 | } | 401 | } |
402 | 402 | ||
403 | /*ARGSUSED*/ | 403 | /*ARGSUSED*/ |
@@ -480,10 +480,11 @@ sshd_exchange_identification(int sock_in, int sock_out) | |||
480 | &remote_major, &remote_minor, remote_version) != 3) { | 480 | &remote_major, &remote_minor, remote_version) != 3) { |
481 | s = "Protocol mismatch.\n"; | 481 | s = "Protocol mismatch.\n"; |
482 | (void) atomicio(vwrite, sock_out, s, strlen(s)); | 482 | (void) atomicio(vwrite, sock_out, s, strlen(s)); |
483 | logit("Bad protocol version identification '%.100s' " | ||
484 | "from %s port %d", client_version_string, | ||
485 | get_remote_ipaddr(), get_remote_port()); | ||
483 | close(sock_in); | 486 | close(sock_in); |
484 | close(sock_out); | 487 | close(sock_out); |
485 | logit("Bad protocol version identification '%.100s' from %s", | ||
486 | client_version_string, get_remote_ipaddr()); | ||
487 | cleanup_exit(255); | 488 | cleanup_exit(255); |
488 | } | 489 | } |
489 | debug("Client protocol version %d.%d; client software version %.100s", | 490 | debug("Client protocol version %d.%d; client software version %.100s", |
@@ -491,17 +492,24 @@ sshd_exchange_identification(int sock_in, int sock_out) | |||
491 | 492 | ||
492 | compat_datafellows(remote_version); | 493 | compat_datafellows(remote_version); |
493 | 494 | ||
494 | if (datafellows & SSH_BUG_PROBE) { | 495 | if ((datafellows & SSH_BUG_PROBE) != 0) { |
495 | logit("probed from %s with %s. Don't panic.", | 496 | logit("probed from %s with %s. Don't panic.", |
496 | get_remote_ipaddr(), client_version_string); | 497 | get_remote_ipaddr(), client_version_string); |
497 | cleanup_exit(255); | 498 | cleanup_exit(255); |
498 | } | 499 | } |
499 | 500 | if ((datafellows & SSH_BUG_SCANNER) != 0) { | |
500 | if (datafellows & SSH_BUG_SCANNER) { | ||
501 | logit("scanned from %s with %s. Don't panic.", | 501 | logit("scanned from %s with %s. Don't panic.", |
502 | get_remote_ipaddr(), client_version_string); | 502 | get_remote_ipaddr(), client_version_string); |
503 | cleanup_exit(255); | 503 | cleanup_exit(255); |
504 | } | 504 | } |
505 | if ((datafellows & SSH_BUG_RSASIGMD5) != 0) { | ||
506 | logit("Client version \"%.100s\" uses unsafe RSA signature " | ||
507 | "scheme; disabling use of RSA keys", remote_version); | ||
508 | } | ||
509 | if ((datafellows & SSH_BUG_DERIVEKEY) != 0) { | ||
510 | fatal("Client version \"%.100s\" uses unsafe key agreement; " | ||
511 | "refusing connection", remote_version); | ||
512 | } | ||
505 | 513 | ||
506 | mismatch = 0; | 514 | mismatch = 0; |
507 | switch (remote_major) { | 515 | switch (remote_major) { |
@@ -613,6 +621,7 @@ privsep_preauth_child(void) | |||
613 | arc4random_stir(); | 621 | arc4random_stir(); |
614 | arc4random_buf(rnd, sizeof(rnd)); | 622 | arc4random_buf(rnd, sizeof(rnd)); |
615 | RAND_seed(rnd, sizeof(rnd)); | 623 | RAND_seed(rnd, sizeof(rnd)); |
624 | bzero(rnd, sizeof(rnd)); | ||
616 | 625 | ||
617 | /* Demote the private keys to public keys. */ | 626 | /* Demote the private keys to public keys. */ |
618 | demote_sensitive_data(); | 627 | demote_sensitive_data(); |
@@ -651,7 +660,7 @@ privsep_preauth(Authctxt *authctxt) | |||
651 | pmonitor->m_pkex = &xxx_kex; | 660 | pmonitor->m_pkex = &xxx_kex; |
652 | 661 | ||
653 | if (use_privsep == PRIVSEP_ON) | 662 | if (use_privsep == PRIVSEP_ON) |
654 | box = ssh_sandbox_init(); | 663 | box = ssh_sandbox_init(pmonitor); |
655 | pid = fork(); | 664 | pid = fork(); |
656 | if (pid == -1) { | 665 | if (pid == -1) { |
657 | fatal("fork of unprivileged child failed"); | 666 | fatal("fork of unprivileged child failed"); |
@@ -747,6 +756,7 @@ privsep_postauth(Authctxt *authctxt) | |||
747 | arc4random_stir(); | 756 | arc4random_stir(); |
748 | arc4random_buf(rnd, sizeof(rnd)); | 757 | arc4random_buf(rnd, sizeof(rnd)); |
749 | RAND_seed(rnd, sizeof(rnd)); | 758 | RAND_seed(rnd, sizeof(rnd)); |
759 | bzero(rnd, sizeof(rnd)); | ||
750 | 760 | ||
751 | /* Drop privileges */ | 761 | /* Drop privileges */ |
752 | do_setusercontext(authctxt->pw); | 762 | do_setusercontext(authctxt->pw); |
@@ -782,6 +792,7 @@ list_hostkey_types(void) | |||
782 | case KEY_RSA: | 792 | case KEY_RSA: |
783 | case KEY_DSA: | 793 | case KEY_DSA: |
784 | case KEY_ECDSA: | 794 | case KEY_ECDSA: |
795 | case KEY_ED25519: | ||
785 | if (buffer_len(&b) > 0) | 796 | if (buffer_len(&b) > 0) |
786 | buffer_append(&b, ",", 1); | 797 | buffer_append(&b, ",", 1); |
787 | p = key_ssh_name(key); | 798 | p = key_ssh_name(key); |
@@ -798,6 +809,7 @@ list_hostkey_types(void) | |||
798 | case KEY_RSA_CERT: | 809 | case KEY_RSA_CERT: |
799 | case KEY_DSA_CERT: | 810 | case KEY_DSA_CERT: |
800 | case KEY_ECDSA_CERT: | 811 | case KEY_ECDSA_CERT: |
812 | case KEY_ED25519_CERT: | ||
801 | if (buffer_len(&b) > 0) | 813 | if (buffer_len(&b) > 0) |
802 | buffer_append(&b, ",", 1); | 814 | buffer_append(&b, ",", 1); |
803 | p = key_ssh_name(key); | 815 | p = key_ssh_name(key); |
@@ -825,6 +837,7 @@ get_hostkey_by_type(int type, int need_private) | |||
825 | case KEY_RSA_CERT: | 837 | case KEY_RSA_CERT: |
826 | case KEY_DSA_CERT: | 838 | case KEY_DSA_CERT: |
827 | case KEY_ECDSA_CERT: | 839 | case KEY_ECDSA_CERT: |
840 | case KEY_ED25519_CERT: | ||
828 | key = sensitive_data.host_certificates[i]; | 841 | key = sensitive_data.host_certificates[i]; |
829 | break; | 842 | break; |
830 | default: | 843 | default: |
@@ -1139,6 +1152,7 @@ server_accept_loop(int *sock_in, int *sock_out, int *newsock, int *config_s) | |||
1139 | struct sockaddr_storage from; | 1152 | struct sockaddr_storage from; |
1140 | socklen_t fromlen; | 1153 | socklen_t fromlen; |
1141 | pid_t pid; | 1154 | pid_t pid; |
1155 | u_char rnd[256]; | ||
1142 | 1156 | ||
1143 | /* setup fd set for accept */ | 1157 | /* setup fd set for accept */ |
1144 | fdset = NULL; | 1158 | fdset = NULL; |
@@ -1339,6 +1353,9 @@ server_accept_loop(int *sock_in, int *sock_out, int *newsock, int *config_s) | |||
1339 | * from that of the child | 1353 | * from that of the child |
1340 | */ | 1354 | */ |
1341 | arc4random_stir(); | 1355 | arc4random_stir(); |
1356 | arc4random_buf(rnd, sizeof(rnd)); | ||
1357 | RAND_seed(rnd, sizeof(rnd)); | ||
1358 | bzero(rnd, sizeof(rnd)); | ||
1342 | } | 1359 | } |
1343 | 1360 | ||
1344 | /* child process check (or debug mode) */ | 1361 | /* child process check (or debug mode) */ |
@@ -1693,6 +1710,7 @@ main(int ac, char **av) | |||
1693 | case KEY_RSA: | 1710 | case KEY_RSA: |
1694 | case KEY_DSA: | 1711 | case KEY_DSA: |
1695 | case KEY_ECDSA: | 1712 | case KEY_ECDSA: |
1713 | case KEY_ED25519: | ||
1696 | sensitive_data.have_ssh2_key = 1; | 1714 | sensitive_data.have_ssh2_key = 1; |
1697 | break; | 1715 | break; |
1698 | } | 1716 | } |
@@ -1859,9 +1877,6 @@ main(int ac, char **av) | |||
1859 | /* Reinitialize the log (because of the fork above). */ | 1877 | /* Reinitialize the log (because of the fork above). */ |
1860 | log_init(__progname, options.log_level, options.log_facility, log_stderr); | 1878 | log_init(__progname, options.log_level, options.log_facility, log_stderr); |
1861 | 1879 | ||
1862 | /* Initialize the random number generator. */ | ||
1863 | arc4random_stir(); | ||
1864 | |||
1865 | /* Chdir to the root directory so that the current disk can be | 1880 | /* Chdir to the root directory so that the current disk can be |
1866 | unmounted if desired. */ | 1881 | unmounted if desired. */ |
1867 | if (chdir("/") == -1) | 1882 | if (chdir("/") == -1) |
@@ -1933,13 +1948,14 @@ main(int ac, char **av) | |||
1933 | dup2(STDIN_FILENO, STDOUT_FILENO); | 1948 | dup2(STDIN_FILENO, STDOUT_FILENO); |
1934 | if (startup_pipe == -1) | 1949 | if (startup_pipe == -1) |
1935 | close(REEXEC_STARTUP_PIPE_FD); | 1950 | close(REEXEC_STARTUP_PIPE_FD); |
1936 | else | 1951 | else if (startup_pipe != REEXEC_STARTUP_PIPE_FD) { |
1937 | dup2(startup_pipe, REEXEC_STARTUP_PIPE_FD); | 1952 | dup2(startup_pipe, REEXEC_STARTUP_PIPE_FD); |
1953 | close(startup_pipe); | ||
1954 | startup_pipe = REEXEC_STARTUP_PIPE_FD; | ||
1955 | } | ||
1938 | 1956 | ||
1939 | dup2(config_s[1], REEXEC_CONFIG_PASS_FD); | 1957 | dup2(config_s[1], REEXEC_CONFIG_PASS_FD); |
1940 | close(config_s[1]); | 1958 | close(config_s[1]); |
1941 | if (startup_pipe != -1) | ||
1942 | close(startup_pipe); | ||
1943 | 1959 | ||
1944 | execv(rexec_argv[0], rexec_argv); | 1960 | execv(rexec_argv[0], rexec_argv); |
1945 | 1961 | ||
@@ -1950,8 +1966,6 @@ main(int ac, char **av) | |||
1950 | options.log_facility, log_stderr); | 1966 | options.log_facility, log_stderr); |
1951 | 1967 | ||
1952 | /* Clean up fds */ | 1968 | /* Clean up fds */ |
1953 | startup_pipe = REEXEC_STARTUP_PIPE_FD; | ||
1954 | close(config_s[1]); | ||
1955 | close(REEXEC_CONFIG_PASS_FD); | 1969 | close(REEXEC_CONFIG_PASS_FD); |
1956 | newsock = sock_out = sock_in = dup(STDIN_FILENO); | 1970 | newsock = sock_out = sock_in = dup(STDIN_FILENO); |
1957 | if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) { | 1971 | if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) { |
@@ -2033,7 +2047,9 @@ main(int ac, char **av) | |||
2033 | #endif /* LIBWRAP */ | 2047 | #endif /* LIBWRAP */ |
2034 | 2048 | ||
2035 | /* Log the connection. */ | 2049 | /* Log the connection. */ |
2036 | verbose("Connection from %.500s port %d", remote_ip, remote_port); | 2050 | verbose("Connection from %s port %d on %s port %d", |
2051 | remote_ip, remote_port, | ||
2052 | get_local_ipaddr(sock_in), get_local_port()); | ||
2037 | 2053 | ||
2038 | /* | 2054 | /* |
2039 | * We don't want to listen forever unless the other side | 2055 | * We don't want to listen forever unless the other side |
@@ -2437,7 +2453,8 @@ do_ssh2_kex(void) | |||
2437 | packet_set_rekey_limits((u_int32_t)options.rekey_limit, | 2453 | packet_set_rekey_limits((u_int32_t)options.rekey_limit, |
2438 | (time_t)options.rekey_interval); | 2454 | (time_t)options.rekey_interval); |
2439 | 2455 | ||
2440 | myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = list_hostkey_types(); | 2456 | myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = compat_pkalg_proposal( |
2457 | list_hostkey_types()); | ||
2441 | 2458 | ||
2442 | /* start key exchange */ | 2459 | /* start key exchange */ |
2443 | kex = kex_setup(myproposal); | 2460 | kex = kex_setup(myproposal); |
@@ -2446,6 +2463,7 @@ do_ssh2_kex(void) | |||
2446 | kex->kex[KEX_DH_GEX_SHA1] = kexgex_server; | 2463 | kex->kex[KEX_DH_GEX_SHA1] = kexgex_server; |
2447 | kex->kex[KEX_DH_GEX_SHA256] = kexgex_server; | 2464 | kex->kex[KEX_DH_GEX_SHA256] = kexgex_server; |
2448 | kex->kex[KEX_ECDH_SHA2] = kexecdh_server; | 2465 | kex->kex[KEX_ECDH_SHA2] = kexecdh_server; |
2466 | kex->kex[KEX_C25519_SHA256] = kexc25519_server; | ||
2449 | kex->server = 1; | 2467 | kex->server = 1; |
2450 | kex->client_version_string=client_version_string; | 2468 | kex->client_version_string=client_version_string; |
2451 | kex->server_version_string=server_version_string; | 2469 | kex->server_version_string=server_version_string; |