1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
|
--- openssh-7_2_P2-hpn-14.10.diff.orig 2016-09-01 10:34:05.905112131 -0700
+++ openssh-7_2_P2-hpn-14.10.diff 2016-09-08 11:35:18.015979358 -0700
@@ -156,145 +156,6 @@
compat.o crc32.o deattack.o fatal.o hostfile.o \
log.o match.o md-sha256.o moduli.o nchan.o packet.o opacket.o \
readpass.o rsa.o ttymodes.o xmalloc.o addrmatch.o \
-diff --git a/auth2.c b/auth2.c
-index 7177962..4af53f0 100644
---- a/auth2.c
-+++ b/auth2.c
-@@ -50,6 +50,7 @@
- #include "dispatch.h"
- #include "pathnames.h"
- #include "buffer.h"
-+#include "canohost.h"
-
- #ifdef GSSAPI
- #include "ssh-gss.h"
-@@ -73,6 +74,8 @@ extern Authmethod method_hostbased;
- extern Authmethod method_gssapi;
- #endif
-
-+static int log_flag = 0;
-+
- Authmethod *authmethods[] = {
- &method_none,
- &method_pubkey,
-@@ -224,6 +227,11 @@ input_userauth_request(int type, u_int32_t seq, void *ctxt)
- service = packet_get_cstring(NULL);
- method = packet_get_cstring(NULL);
- debug("userauth-request for user %s service %s method %s", user, service, method);
-+ if (!log_flag) {
-+ logit("SSH: Server;Ltype: Authname;Remote: %s-%d;Name: %s",
-+ get_remote_ipaddr(), get_remote_port(), user);
-+ log_flag = 1;
-+ }
- debug("attempt %d failures %d", authctxt->attempt, authctxt->failures);
-
- if ((style = strchr(user, ':')) != NULL)
-diff --git a/canohost.c b/canohost.c
-index 223964e..db35f73 100644
---- a/canohost.c
-+++ b/canohost.c
-@@ -338,13 +338,13 @@ clear_cached_addr(void)
- */
-
- const char *
--get_remote_ipaddr(void)
-+ssh_get_remote_ipaddr(struct ssh *ssh)
- {
- /* Check whether we have cached the ipaddr. */
- if (canonical_host_ip == NULL) {
-- if (packet_connection_is_on_socket()) {
-+ if (ssh_packet_connection_is_on_socket(ssh)) {
- canonical_host_ip =
-- get_peer_ipaddr(packet_get_connection_in());
-+ get_peer_ipaddr(ssh_packet_get_connection_in(ssh));
- if (canonical_host_ip == NULL)
- cleanup_exit(255);
- } else {
-@@ -356,6 +356,12 @@ get_remote_ipaddr(void)
- }
-
- const char *
-+get_remote_ipaddr(void)
-+{
-+ return ssh_get_remote_ipaddr(active_state);
-+}
-+
-+const char *
- get_remote_name_or_ip(u_int utmp_len, int use_dns)
- {
- static const char *remote = "";
-@@ -410,17 +416,17 @@ get_sock_port(int sock, int local)
- /* Returns remote/local port number for the current connection. */
-
- static int
--get_port(int local)
-+get_port(struct ssh *ssh, int local)
- {
- /*
- * If the connection is not a socket, return 65535. This is
- * intentionally chosen to be an unprivileged port number.
- */
-- if (!packet_connection_is_on_socket())
-+ if (!ssh_packet_connection_is_on_socket(ssh))
- return 65535;
-
- /* Get socket and return the port number. */
-- return get_sock_port(packet_get_connection_in(), local);
-+ return get_sock_port(ssh_packet_get_connection_in(ssh), local);
- }
-
- int
-@@ -430,17 +436,23 @@ get_peer_port(int sock)
- }
-
- int
--get_remote_port(void)
-+ssh_get_remote_port(struct ssh *ssh)
- {
- /* Cache to avoid getpeername() on a dead connection */
- if (cached_port == -1)
-- cached_port = get_port(0);
-+ cached_port = get_port(ssh, 0);
-
- return cached_port;
- }
-
- int
-+get_remote_port(void)
-+{
-+ return ssh_get_remote_port(active_state);
-+}
-+
-+int
- get_local_port(void)
- {
-- return get_port(1);
-+ return get_port(active_state, 1);
- }
-diff --git a/canohost.h b/canohost.h
-index 4c8636f..4d60b27 100644
---- a/canohost.h
-+++ b/canohost.h
-@@ -12,8 +12,11 @@
- * called by a name other than "ssh" or "Secure Shell".
- */
-
-+struct ssh;
-+
- const char *get_canonical_hostname(int);
- const char *get_remote_ipaddr(void);
-+const char *ssh_get_remote_ipaddr(struct ssh *);
- const char *get_remote_name_or_ip(u_int, int);
-
- char *get_peer_ipaddr(int);
-@@ -22,6 +25,7 @@ char *get_local_ipaddr(int);
- char *get_local_name(int);
-
- int get_remote_port(void);
-+int ssh_get_remote_port(struct ssh *);
- int get_local_port(void);
- int get_sock_port(int, int);
- void clear_cached_addr(void);
diff --git a/channels.c b/channels.c
index c9d2015..13b30a1 100644
--- a/channels.c
@@ -519,7 +380,7 @@
index 0000000..fdc9b2f
--- /dev/null
+++ b/cipher-ctr-mt.c
-@@ -0,0 +1,533 @@
+@@ -0,0 +1,585 @@
+/*
+ * OpenSSH Multi-threaded AES-CTR Cipher
+ *
@@ -649,7 +510,7 @@
+ u_char keys[KQLEN][AES_BLOCK_SIZE];
+ u_char ctr[AES_BLOCK_SIZE];
+ u_char pad0[CACHELINE_LEN];
-+ volatile int qstate;
++ int qstate;
+ pthread_mutex_t lock;
+ pthread_cond_t cond;
+ u_char pad1[CACHELINE_LEN];
@@ -663,6 +524,9 @@
+ STATS_STRUCT(stats);
+ u_char aes_counter[AES_BLOCK_SIZE];
+ pthread_t tid[CIPHER_THREADS];
++ pthread_rwlock_t tid_lock;
++ pthread_rwlock_t stop_lock;
++ int exit_flag;
+ int state;
+ int qidx;
+ int ridx;
@@ -709,6 +573,19 @@
+ pthread_mutex_unlock((pthread_mutex_t *)x);
+}
+
++static void
++thread_loop_check_exit(struct ssh_aes_ctr_ctx *c)
++{
++ int exit_flag;
++
++ pthread_rwlock_rdlock(&c->stop_lock);
++ exit_flag = c->exit_flag;
++ pthread_rwlock_unlock(&c->stop_lock);
++
++ if (exit_flag == TRUE)
++ pthread_exit(NULL);
++}
++
+/*
+ * The life of a pregen thread:
+ * Find empty keystream queues and fill them using their counter.
@@ -723,6 +600,7 @@
+ struct kq *q;
+ int i;
+ int qidx;
++ pthread_t first_tid;
+
+ /* Threads stats on cancellation */
+ STATS_INIT(stats);
@@ -733,11 +611,15 @@
+ /* Thread local copy of AES key */
+ memcpy(&key, &c->aes_ctx, sizeof(key));
+
++ pthread_rwlock_rdlock(&c->tid_lock);
++ first_tid = c->tid[0];
++ pthread_rwlock_unlock(&c->tid_lock);
++
+ /*
+ * Handle the special case of startup, one thread must fill
+ * the first KQ then mark it as draining. Lock held throughout.
+ */
-+ if (pthread_equal(pthread_self(), c->tid[0])) {
++ if (pthread_equal(pthread_self(), first_tid)) {
+ q = &c->q[0];
+ pthread_mutex_lock(&q->lock);
+ if (q->qstate == KQINIT) {
@@ -764,8 +646,8 @@
+ * others will move on to fill, skip, or wait on the next queue.
+ */
+ for (qidx = 1;; qidx = (qidx + 1) % NUMKQ) {
-+ /* Check if I was cancelled, also checked in cond_wait */
-+ pthread_testcancel();
++ /* Check if we should exit */
++ thread_loop_check_exit(c);
+
+ /* Lock queue and block if its draining */
+ q = &c->q[qidx];
@@ -773,6 +655,7 @@
+ pthread_cleanup_push(thread_loop_cleanup, &q->lock);
+ while (q->qstate == KQDRAINING || q->qstate == KQINIT) {
+ STATS_WAIT(stats);
++ thread_loop_check_exit(c);
+ pthread_cond_wait(&q->cond, &q->lock);
+ }
+ pthread_cleanup_pop(0);
@@ -790,6 +673,7 @@
+ * can see that it's being filled.
+ */
+ q->qstate = KQFILLING;
++ pthread_cond_broadcast(&q->cond);
+ pthread_mutex_unlock(&q->lock);
+ for (i = 0; i < KQLEN; i++) {
+ AES_encrypt(q->ctr, q->keys[i], &key);
@@ -801,7 +685,7 @@
+ ssh_ctr_add(q->ctr, KQLEN * (NUMKQ - 1), AES_BLOCK_SIZE);
+ q->qstate = KQFULL;
+ STATS_FILL(stats);
-+ pthread_cond_signal(&q->cond);
++ pthread_cond_broadcast(&q->cond);
+ pthread_mutex_unlock(&q->lock);
+ }
+
@@ -893,6 +777,7 @@
+ pthread_cond_wait(&q->cond, &q->lock);
+ }
+ q->qstate = KQDRAINING;
++ pthread_cond_broadcast(&q->cond);
+ pthread_mutex_unlock(&q->lock);
+
+ /* Mark consumed queue empty and signal producers */
@@ -919,6 +804,9 @@
+
+ if ((c = EVP_CIPHER_CTX_get_app_data(ctx)) == NULL) {
+ c = xmalloc(sizeof(*c));
++ pthread_rwlock_init(&c->tid_lock, NULL);
++ pthread_rwlock_init(&c->stop_lock, NULL);
++ c->exit_flag = FALSE;
+
+ c->state = HAVE_NONE;
+ for (i = 0; i < NUMKQ; i++) {
@@ -931,11 +819,19 @@
+ }
+
+ if (c->state == (HAVE_KEY | HAVE_IV)) {
-+ /* Cancel pregen threads */
-+ for (i = 0; i < CIPHER_THREADS; i++)
-+ pthread_cancel(c->tid[i]);
++ /* tell the pregen threads to exit */
++ pthread_rwlock_wrlock(&c->stop_lock);
++ c->exit_flag = TRUE;
++ pthread_rwlock_unlock(&c->stop_lock);
++
++ for (i = 0; i < NUMKQ; i++) {
++ pthread_mutex_lock(&c->q[i].lock);
++ pthread_cond_broadcast(&c->q[i].cond);
++ pthread_mutex_unlock(&c->q[i].lock);
++ }
+ for (i = 0; i < CIPHER_THREADS; i++)
+ pthread_join(c->tid[i], NULL);
++
+ /* Start over getting key & iv */
+ c->state = HAVE_NONE;
+ }
@@ -966,10 +862,12 @@
+ /* Start threads */
+ for (i = 0; i < CIPHER_THREADS; i++) {
+ debug("spawned a thread");
++ pthread_rwlock_wrlock(&c->tid_lock);
+ pthread_create(&c->tid[i], NULL, thread_loop, c);
++ pthread_rwlock_unlock(&c->tid_lock);
+ }
+ pthread_mutex_lock(&c->q[0].lock);
-+ while (c->q[0].qstate != KQDRAINING)
++ while (c->q[0].qstate == KQINIT)
+ pthread_cond_wait(&c->q[0].cond, &c->q[0].lock);
+ pthread_mutex_unlock(&c->q[0].lock);
+ }
@@ -985,9 +883,15 @@
+ struct ssh_aes_ctr_ctx *c;
+ int i;
+ c = EVP_CIPHER_CTX_get_app_data(ctx);
-+ /* destroy threads */
-+ for (i = 0; i < CIPHER_THREADS; i++) {
-+ pthread_cancel(c->tid[i]);
++ /* notify threads that they should exit */
++ pthread_rwlock_wrlock(&c->stop_lock);
++ c->exit_flag = TRUE;
++ pthread_rwlock_unlock(&c->stop_lock);
++
++ for (i = 0; i < NUMKQ; i++) {
++ pthread_mutex_lock(&c->q[i].lock);
++ pthread_cond_broadcast(&c->q[i].cond);
++ pthread_mutex_unlock(&c->q[i].lock);
+ }
+ for (i = 0; i < CIPHER_THREADS; i++) {
+ pthread_join(c->tid[i], NULL);
@@ -1003,7 +907,9 @@
+ /* reconstruct threads */
+ for (i = 0; i < CIPHER_THREADS; i++) {
+ debug("spawned a thread");
++ pthread_rwlock_wrlock(&c->tid_lock);
+ pthread_create(&c->tid[i], NULL, thread_loop, c);
++ pthread_rwlock_unlock(&c->tid_lock);
+ }
+}
+
@@ -1018,9 +924,16 @@
+ debug("main thread: %u drains, %u waits", c->stats.drains,
+ c->stats.waits);
+#endif
-+ /* Cancel pregen threads */
-+ for (i = 0; i < CIPHER_THREADS; i++)
-+ pthread_cancel(c->tid[i]);
++ /* tell the pregen threads to exit */
++ pthread_rwlock_wrlock(&c->stop_lock);
++ c->exit_flag = TRUE;
++ pthread_rwlock_unlock(&c->stop_lock);
++
++ for (i = 0; i < NUMKQ; i++) {
++ pthread_mutex_lock(&c->q[i].lock);
++ pthread_cond_broadcast(&c->q[i].cond);
++ pthread_mutex_unlock(&c->q[i].lock);
++ }
+ for (i = 0; i < CIPHER_THREADS; i++)
+ pthread_join(c->tid[i], NULL);
+
@@ -1270,7 +1183,7 @@
#include "ssherr.h"
#include "sshbuf.h"
-+#include "canohost.h"
++#include "packet.h"
#include "digest.h"
#if OPENSSL_VERSION_NUMBER >= 0x00907000L
@@ -1312,8 +1225,8 @@
+ */
+ if (ctos && !log_flag) {
+ logit("SSH: Server;Ltype: Kex;Remote: %s-%d;Enc: %s;MAC: %s;Comp: %s",
-+ ssh_get_remote_ipaddr(ssh),
-+ ssh_get_remote_port(ssh),
++ ssh_remote_ipaddr(ssh),
++ ssh_remote_port(ssh),
+ newkeys->enc.name,
+ authlen == 0 ? newkeys->mac.name : "<implicit>",
+ newkeys->comp.name);
@@ -1430,7 +1343,7 @@
+ rekey_requested = 0;
+ return 1;
+ }
-+
++
/* Time-based rekeying */
if (state->rekey_interval != 0 &&
state->rekey_time + state->rekey_interval <= monotime())
@@ -1490,7 +1403,7 @@
transferred = *counter - (cur_pos ? cur_pos : start_pos);
cur_pos = *counter;
- now = monotime();
+ now = monotime_double();
bytes_left = end_pos - cur_pos;
+ delta_pos = cur_pos - last_pos;
@@ -1564,8 +1477,8 @@
{ "canonicaldomains", oCanonicalDomains },
{ "canonicalizefallbacklocal", oCanonicalizeFallbackLocal },
@@ -282,6 +287,11 @@ static struct {
- { "pubkeyacceptedkeytypes", oPubkeyAcceptedKeyTypes },
{ "ignoreunknown", oIgnoreUnknown },
+ { "proxyjump", oProxyJump },
+ { "tcprcvbufpoll", oTcpRcvBufPoll },
+ { "tcprcvbuf", oTcpRcvBuf },
@@ -1736,8 +1649,8 @@
off_t size, statbytes;
unsigned long long ull;
int setimes, targisdir, wrerrno = 0;
-- char ch, *cp, *np, *targ, *why, *vect[1], buf[2048];
-+ char ch, *cp, *np, *targ, *why, *vect[1], buf[16384];
+- char ch, *cp, *np, *targ, *why, *vect[1], buf[2048], visbuf[2048];
++ char ch, *cp, *np, *targ, *why, *vect[1], buf[16384], visbuf[16384];
struct timeval tv[2];
#define atime tv[0]
@@ -1956,32 +1869,6 @@
}
/*
-@@ -820,11 +836,13 @@ void
- server_loop2(Authctxt *authctxt)
- {
- fd_set *readset = NULL, *writeset = NULL;
-+ double start_time, total_time;
- int max_fd;
- u_int nalloc = 0;
- u_int64_t rekey_timeout_ms = 0;
-
- debug("Entering interactive session for SSH2.");
-+ start_time = get_current_time();
-
- mysignal(SIGCHLD, sigchld_handler);
- child_terminated = 0;
-@@ -883,6 +901,11 @@ server_loop2(Authctxt *authctxt)
-
- /* free remaining sessions, e.g. remove wtmp entries */
- session_destroy_all(NULL);
-+ total_time = get_current_time() - start_time;
-+ logit("SSH: Server;LType: Throughput;Remote: %s-%d;IN: %lu;OUT: %lu;Duration: %.1f;tPut_in: %.1f;tPut_out: %.1f",
-+ get_remote_ipaddr(), get_remote_port(),
-+ stdin_bytes, fdout_bytes, total_time, stdin_bytes / total_time,
-+ fdout_bytes / total_time);
- }
-
- static int
@@ -1041,8 +1064,12 @@ server_request_tun(void)
sock = tun_open(tun, mode);
if (sock < 0)
@@ -2372,10 +2259,10 @@
debug("Client protocol version %d.%d; client software version %.100s",
remote_major, remote_minor, remote_version);
+ logit("SSH: Server;Ltype: Version;Remote: %s-%d;Protocol: %d.%d;Client: %.100s",
-+ get_remote_ipaddr(), get_remote_port(),
++ ssh_remote_ipaddr(ssh), ssh_remote_port(ssh),
+ remote_major, remote_minor, remote_version);
- active_state->compat = compat_datafellows(remote_version);
+ ssh->compat = compat_datafellows(remote_version);
@@ -1160,6 +1163,8 @@ server_listen(void)
int ret, listen_sock, on = 1;
@@ -2413,7 +2300,7 @@
if (options.challenge_response_authentication)
options.kbd_interactive_authentication = 1;
@@ -2151,6 +2168,9 @@ main(int ac, char **av)
- remote_ip, remote_port, laddr, get_local_port());
+ remote_ip, remote_port, laddr, ssh_local_port(ssh));
free(laddr);
+ /* set the HPN options for the child */
@@ -2486,11 +2373,10 @@
index eb4e948..3692722 100644
--- a/version.h
+++ b/version.h
-@@ -3,4 +3,6 @@
- #define SSH_VERSION "OpenSSH_7.2"
+@@ -3,4 +3,5 @@
+ #define SSH_VERSION "OpenSSH_7.3"
- #define SSH_PORTABLE "p2"
+ #define SSH_PORTABLE "p1"
-#define SSH_RELEASE SSH_VERSION SSH_PORTABLE
+#define SSH_HPN "-hpn14v11"
+#define SSH_RELEASE SSH_VERSION SSH_PORTABLE SSH_HPN
-+
|