View | Details | Raw Unified | Return to bug 1402 | Differences between
and this patch

Collapse All | Expand All

(-)openssh-5.8p1/audit-bsm.c.audit4 (+6 lines)
Lines 408-411 audit_kex_body(int ctos, char *enc, char Link Here
408
{
408
{
409
	/* not implemented */
409
	/* not implemented */
410
}
410
}
411
412
void
413
audit_session_key_free_body(int ctos, pid_t pid, uid_t uid)
414
{
415
	/* not implemented */
416
}
411
#endif /* BSM */
417
#endif /* BSM */
(-)openssh-5.8p1/audit.c.audit4 (+16 lines)
Lines 143-148 audit_kex(int ctos, char *enc, char *mac Link Here
143
	PRIVSEP(audit_kex_body(ctos, enc, mac, comp, getpid(), getuid()));
143
	PRIVSEP(audit_kex_body(ctos, enc, mac, comp, getpid(), getuid()));
144
}
144
}
145
145
146
void
147
audit_session_key_free(int ctos)
148
{
149
	PRIVSEP(audit_session_key_free_body(ctos, getpid(), getuid()));
150
}
151
146
# ifndef CUSTOM_SSH_AUDIT_EVENTS
152
# ifndef CUSTOM_SSH_AUDIT_EVENTS
147
/*
153
/*
148
 * Null implementations of audit functions.
154
 * Null implementations of audit functions.
Lines 274-278 audit_kex_body(int ctos, char *enc, char Link Here
274
		(unsigned)geteuid(), ctos, enc, mac, compress, (long)pid,
280
		(unsigned)geteuid(), ctos, enc, mac, compress, (long)pid,
275
	        (unsigned)uid);
281
	        (unsigned)uid);
276
}
282
}
283
284
/*
285
 * This will be called on succesfull session key discard
286
 */
287
void
288
audit_session_key_free_body(int ctos, pid_t pid, uid_t uid)
289
{
290
	debug("audit session key discard euid %u direction %d from pid %ld uid %u",
291
		(unsigned)geteuid(), ctos, (long)pid, (unsigned)uid);
292
}
277
# endif  /* !defined CUSTOM_SSH_AUDIT_EVENTS */
293
# endif  /* !defined CUSTOM_SSH_AUDIT_EVENTS */
278
#endif /* SSH_AUDIT_EVENTS */
294
#endif /* SSH_AUDIT_EVENTS */
(-)openssh-5.8p1/audit.h.audit4 (+2 lines)
Lines 62-66 void audit_unsupported(int); Link Here
62
void	audit_kex(int, char *, char *, char *);
62
void	audit_kex(int, char *, char *, char *);
63
void	audit_unsupported_body(int);
63
void	audit_unsupported_body(int);
64
void	audit_kex_body(int, char *, char *, char *, pid_t, uid_t);
64
void	audit_kex_body(int, char *, char *, char *, pid_t, uid_t);
65
void	audit_session_key_free(int ctos);
66
void	audit_session_key_free_body(int ctos, pid_t, uid_t);
65
67
66
#endif /* _SSH_AUDIT_H */
68
#endif /* _SSH_AUDIT_H */
(-)openssh-5.8p1/audit-linux.c.audit4 (-1 / +28 lines)
Lines 292-297 audit_unsupported_body(int what) Link Here
292
#endif
292
#endif
293
}
293
}
294
294
295
const static char *direction[] = { "from-server", "from-client", "both" };
296
295
void
297
void
296
audit_kex_body(int ctos, char *enc, char *mac, char *compress, pid_t pid,
298
audit_kex_body(int ctos, char *enc, char *mac, char *compress, pid_t pid,
297
	       uid_t uid)
299
	       uid_t uid)
Lines 299-305 audit_kex_body(int ctos, char *enc, char Link Here
299
#ifdef AUDIT_CRYPTO_SESSION
301
#ifdef AUDIT_CRYPTO_SESSION
300
	char buf[AUDIT_LOG_SIZE];
302
	char buf[AUDIT_LOG_SIZE];
301
	int audit_fd, audit_ok;
303
	int audit_fd, audit_ok;
302
	const static char *direction[] = { "from-server", "from-client", "both" };
303
	Cipher *cipher = cipher_by_name(enc);
304
	Cipher *cipher = cipher_by_name(enc);
304
305
305
	snprintf(buf, sizeof(buf), "op=start direction=%s cipher=%s ksize=%d spid=%jd suid=%jd rport=%d laddr=%s lport=%d ",
306
	snprintf(buf, sizeof(buf), "op=start direction=%s cipher=%s ksize=%d spid=%jd suid=%jd rport=%d laddr=%s lport=%d ",
Lines 323-326 audit_kex_body(int ctos, char *enc, char Link Here
323
#endif
324
#endif
324
}
325
}
325
326
327
void
328
audit_session_key_free_body(int ctos, pid_t pid, uid_t uid)
329
{
330
	char buf[AUDIT_LOG_SIZE];
331
	int audit_fd, audit_ok;
332
333
	snprintf(buf, sizeof(buf), "op=destroy kind=session fp=? direction=%s spid=%jd suid=%jd rport=%d laddr=%s lport=%d ",
334
		 direction[ctos], (intmax_t)pid, (intmax_t)uid,
335
		 get_remote_port(),
336
		 get_local_ipaddr(packet_get_connection_in()),
337
		 get_local_port());
338
	audit_fd = audit_open();
339
	if (audit_fd < 0) {
340
		if (errno != EINVAL && errno != EPROTONOSUPPORT &&
341
					 errno != EAFNOSUPPORT)
342
			error("cannot open audit");
343
		return;
344
	}
345
	audit_ok = audit_log_user_message(audit_fd, AUDIT_CRYPTO_KEY_USER,
346
			buf, NULL, get_remote_ipaddr(), NULL, 1);
347
	audit_close(audit_fd);
348
	/* do not abort if the error is EPERM and sshd is run as non root user */
349
	if ((audit_ok < 0) && ((audit_ok != -1) || (getuid() == 0)))
350
		error("cannot write into audit");
351
}
352
326
#endif /* USE_LINUX_AUDIT */
353
#endif /* USE_LINUX_AUDIT */
(-)openssh-5.8p1/auditstub.c.audit4 (+11 lines)
Lines 27-32 Link Here
27
 * Red Hat author: Jan F. Chadima <jchadima@redhat.com>
27
 * Red Hat author: Jan F. Chadima <jchadima@redhat.com>
28
 */
28
 */
29
29
30
#include <sys/types.h>
31
30
void
32
void
31
audit_unsupported(int n)
33
audit_unsupported(int n)
32
{
34
{
Lines 37-39 audit_kex(int ctos, char *enc, char *mac Link Here
37
{
39
{
38
}
40
}
39
41
42
void
43
audit_session_key_free(int ctos)
44
{
45
}
46
47
void
48
audit_session_key_free_body(int ctos, pid_t pid, uid_t uid)
49
{
50
}
(-)openssh-5.8p1/kex.c.audit4 (+31 lines)
Lines 624-626 dump_digest(char *msg, u_char *digest, i Link Here
624
	fprintf(stderr, "\n");
624
	fprintf(stderr, "\n");
625
}
625
}
626
#endif
626
#endif
627
628
static void
629
enc_destroy(Enc *enc)
630
{
631
	if (enc == NULL)
632
		return;
633
634
	if (enc->key) {
635
		memset(enc->key, 0, enc->key_len);
636
		xfree(enc->key);
637
	}
638
639
	if (enc->iv) {
640
		memset(enc->iv,  0, enc->block_size);
641
		xfree(enc->iv);
642
	}
643
644
	memset(enc, 0, sizeof(*enc));
645
}
646
647
void
648
newkeys_destroy(Newkeys *newkeys)
649
{
650
	if (newkeys == NULL)
651
		return;
652
653
	enc_destroy(&newkeys->enc);
654
	mac_destroy(&newkeys->mac);
655
	memset(&newkeys->comp, 0, sizeof(newkeys->comp));
656
}
657
(-)openssh-5.8p1/kex.h.audit4 (+2 lines)
Lines 156-161 void kexgex_server(Kex *); Link Here
156
void	 kexecdh_client(Kex *);
156
void	 kexecdh_client(Kex *);
157
void	 kexecdh_server(Kex *);
157
void	 kexecdh_server(Kex *);
158
158
159
void	newkeys_destroy(Newkeys *newkeys);
160
159
void
161
void
160
kex_dh_hash(char *, char *, char *, int, char *, int, u_char *, int,
162
kex_dh_hash(char *, char *, char *, int, char *, int, u_char *, int,
161
    BIGNUM *, BIGNUM *, BIGNUM *, u_char **, u_int *);
163
    BIGNUM *, BIGNUM *, BIGNUM *, u_char **, u_int *);
(-)openssh-5.8p1/mac.c.audit4 (+14 lines)
Lines 162-167 mac_clear(Mac *mac) Link Here
162
	mac->umac_ctx = NULL;
162
	mac->umac_ctx = NULL;
163
}
163
}
164
164
165
void
166
mac_destroy(Mac *mac)
167
{
168
	if (mac == NULL)
169
		return;
170
171
	if (mac->key) {
172
		memset(mac->key, 0, mac->key_len);
173
		xfree(mac->key);
174
	}
175
176
	memset(mac, 0, sizeof(*mac));
177
}
178
165
/* XXX copied from ciphers_valid */
179
/* XXX copied from ciphers_valid */
166
#define	MAC_SEP	","
180
#define	MAC_SEP	","
167
int
181
int
(-)openssh-5.8p1/mac.h.audit4 (+1 lines)
Lines 28-30 int mac_setup(Mac *, char *); Link Here
28
int	 mac_init(Mac *);
28
int	 mac_init(Mac *);
29
u_char	*mac_compute(Mac *, u_int32_t, u_char *, int);
29
u_char	*mac_compute(Mac *, u_int32_t, u_char *, int);
30
void	 mac_clear(Mac *);
30
void	 mac_clear(Mac *);
31
void	 mac_destroy(Mac *);
(-)openssh-5.8p1/monitor.c.audit4 (+35 lines)
Lines 181-186 int mm_answer_audit_command(int, Buffer Link Here
181
int mm_answer_audit_end_command(int, Buffer *);
181
int mm_answer_audit_end_command(int, Buffer *);
182
int mm_answer_audit_unsupported_body(int, Buffer *);
182
int mm_answer_audit_unsupported_body(int, Buffer *);
183
int mm_answer_audit_kex_body(int, Buffer *);
183
int mm_answer_audit_kex_body(int, Buffer *);
184
int mm_answer_audit_session_key_free_body(int, Buffer *);
184
#endif
185
#endif
185
186
186
static Authctxt *authctxt;
187
static Authctxt *authctxt;
Lines 231-236 struct mon_table mon_dispatch_proto20[] Link Here
231
    {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},
232
    {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},
232
    {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},
233
    {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},
233
    {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},
234
    {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},
235
    {MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MON_PERMIT, mm_answer_audit_session_key_free_body},
234
#endif
236
#endif
235
#ifdef BSD_AUTH
237
#ifdef BSD_AUTH
236
    {MONITOR_REQ_BSDAUTHQUERY, MON_ISAUTH, mm_answer_bsdauthquery},
238
    {MONITOR_REQ_BSDAUTHQUERY, MON_ISAUTH, mm_answer_bsdauthquery},
Lines 270-275 struct mon_table mon_dispatch_postauth20 Link Here
270
    {MONITOR_REQ_AUDIT_END_COMMAND, MON_PERMIT, mm_answer_audit_end_command},
272
    {MONITOR_REQ_AUDIT_END_COMMAND, MON_PERMIT, mm_answer_audit_end_command},
271
    {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},
273
    {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},
272
    {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},
274
    {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},
275
    {MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MON_PERMIT, mm_answer_audit_session_key_free_body},
273
#endif
276
#endif
274
    {0, 0, NULL}
277
    {0, 0, NULL}
275
};
278
};
Lines 303-308 struct mon_table mon_dispatch_proto15[] Link Here
303
    {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},
306
    {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event},
304
    {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},
307
    {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},
305
    {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},
308
    {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},
309
    {MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MON_PERMIT, mm_answer_audit_session_key_free_body},
306
#endif
310
#endif
307
    {0, 0, NULL}
311
    {0, 0, NULL}
308
};
312
};
Lines 317-322 struct mon_table mon_dispatch_postauth15 Link Here
317
    {MONITOR_REQ_AUDIT_END_COMMAND, MON_PERMIT, mm_answer_audit_end_command},
321
    {MONITOR_REQ_AUDIT_END_COMMAND, MON_PERMIT, mm_answer_audit_end_command},
318
    {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},
322
    {MONITOR_REQ_AUDIT_UNSUPPORTED, MON_PERMIT, mm_answer_audit_unsupported_body},
319
    {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},
323
    {MONITOR_REQ_AUDIT_KEX, MON_PERMIT, mm_answer_audit_kex_body},
324
    {MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MON_PERMIT, mm_answer_audit_session_key_free_body},
320
#endif
325
#endif
321
    {0, 0, NULL}
326
    {0, 0, NULL}
322
};
327
};
Lines 1812-1822 mm_get_keystate(struct monitor *pmonitor Link Here
1812
1817
1813
	blob = buffer_get_string(&m, &bloblen);
1818
	blob = buffer_get_string(&m, &bloblen);
1814
	current_keys[MODE_OUT] = mm_newkeys_from_blob(blob, bloblen);
1819
	current_keys[MODE_OUT] = mm_newkeys_from_blob(blob, bloblen);
1820
	memset(blob, 0, bloblen);
1815
	xfree(blob);
1821
	xfree(blob);
1816
1822
1817
	debug3("%s: Waiting for second key", __func__);
1823
	debug3("%s: Waiting for second key", __func__);
1818
	blob = buffer_get_string(&m, &bloblen);
1824
	blob = buffer_get_string(&m, &bloblen);
1819
	current_keys[MODE_IN] = mm_newkeys_from_blob(blob, bloblen);
1825
	current_keys[MODE_IN] = mm_newkeys_from_blob(blob, bloblen);
1826
	memset(blob, 0, bloblen);
1820
	xfree(blob);
1827
	xfree(blob);
1821
1828
1822
	/* Now get sequence numbers for the packets */
1829
	/* Now get sequence numbers for the packets */
Lines 1862-1867 mm_get_keystate(struct monitor *pmonitor Link Here
1862
	}
1869
	}
1863
1870
1864
	buffer_free(&m);
1871
	buffer_free(&m);
1872
1873
#ifdef SSH_AUDIT_EVENTS
1874
	if (compat20) {
1875
		buffer_init(&m);
1876
		mm_request_receive_expect(pmonitor->m_sendfd,
1877
					  MONITOR_REQ_AUDIT_SESSION_KEY_FREE, &m);
1878
		mm_answer_audit_session_key_free_body(pmonitor->m_sendfd, &m);
1879
		buffer_free(&m);
1880
	}
1881
#endif
1865
}
1882
}
1866
1883
1867
1884
Lines 2303-2306 mm_answer_audit_kex_body(int sock, Buffe Link Here
2303
	return 0;
2320
	return 0;
2304
}
2321
}
2305
2322
2323
int
2324
mm_answer_audit_session_key_free_body(int sock, Buffer *m)
2325
{
2326
	int ctos;
2327
	pid_t pid;
2328
	uid_t uid;
2329
2330
	ctos = buffer_get_int(m);
2331
	pid = buffer_get_int64(m);
2332
	uid = buffer_get_int64(m);
2333
2334
	audit_session_key_free_body(ctos, pid, uid);
2335
2336
	buffer_clear(m);
2337
2338
	mm_request_send(sock, MONITOR_ANS_AUDIT_SESSION_KEY_FREE, m);
2339
	return 0;
2340
}
2306
#endif /* SSH_AUDIT_EVENTS */
2341
#endif /* SSH_AUDIT_EVENTS */
(-)openssh-5.8p1/monitor.h.audit4 (+1 lines)
Lines 69-74 enum monitor_reqtype { Link Here
69
	MONITOR_REQ_JPAKE_CHECK_CONFIRM, MONITOR_ANS_JPAKE_CHECK_CONFIRM,
69
	MONITOR_REQ_JPAKE_CHECK_CONFIRM, MONITOR_ANS_JPAKE_CHECK_CONFIRM,
70
	MONITOR_REQ_AUDIT_UNSUPPORTED, MONITOR_ANS_AUDIT_UNSUPPORTED,
70
	MONITOR_REQ_AUDIT_UNSUPPORTED, MONITOR_ANS_AUDIT_UNSUPPORTED,
71
	MONITOR_REQ_AUDIT_KEX, MONITOR_ANS_AUDIT_KEX,
71
	MONITOR_REQ_AUDIT_KEX, MONITOR_ANS_AUDIT_KEX,
72
	MONITOR_REQ_AUDIT_SESSION_KEY_FREE, MONITOR_ANS_AUDIT_SESSION_KEY_FREE,
72
};
73
};
73
74
74
struct mm_master;
75
struct mm_master;
(-)openssh-5.8p1/monitor_wrap.c.audit4 (+17 lines)
Lines 615-626 mm_send_keystate(struct monitor *monitor Link Here
615
		fatal("%s: conversion of newkeys failed", __func__);
615
		fatal("%s: conversion of newkeys failed", __func__);
616
616
617
	buffer_put_string(&m, blob, bloblen);
617
	buffer_put_string(&m, blob, bloblen);
618
	memset(blob, 0, bloblen);
618
	xfree(blob);
619
	xfree(blob);
619
620
620
	if (!mm_newkeys_to_blob(MODE_IN, &blob, &bloblen))
621
	if (!mm_newkeys_to_blob(MODE_IN, &blob, &bloblen))
621
		fatal("%s: conversion of newkeys failed", __func__);
622
		fatal("%s: conversion of newkeys failed", __func__);
622
623
623
	buffer_put_string(&m, blob, bloblen);
624
	buffer_put_string(&m, blob, bloblen);
625
	memset(blob, 0, bloblen);
624
	xfree(blob);
626
	xfree(blob);
625
627
626
	packet_get_state(MODE_OUT, &seqnr, &blocks, &packets, &bytes);
628
	packet_get_state(MODE_OUT, &seqnr, &blocks, &packets, &bytes);
Lines 1484-1487 mm_audit_kex_body(int ctos, char *cipher Link Here
1484
1486
1485
	buffer_free(&m);
1487
	buffer_free(&m);
1486
}
1488
}
1489
1490
void
1491
mm_audit_session_key_free_body(int ctos, pid_t pid, uid_t uid)
1492
{
1493
	Buffer m;
1494
1495
	buffer_init(&m);
1496
	buffer_put_int(&m, ctos);
1497
	buffer_put_int64(&m, pid);
1498
	buffer_put_int64(&m, uid);
1499
	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_SESSION_KEY_FREE, &m);
1500
	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUDIT_SESSION_KEY_FREE,
1501
				  &m);
1502
	buffer_free(&m);
1503
}
1487
#endif /* SSH_AUDIT_EVENTS */
1504
#endif /* SSH_AUDIT_EVENTS */
(-)openssh-5.8p1/monitor_wrap.h.audit4 (+1 lines)
Lines 78-83 int mm_audit_run_command(const char *); Link Here
78
void mm_audit_end_command(int, const char *);
78
void mm_audit_end_command(int, const char *);
79
void mm_audit_unsupported_body(int);
79
void mm_audit_unsupported_body(int);
80
void mm_audit_kex_body(int, char *, char *, char *, pid_t, uid_t);
80
void mm_audit_kex_body(int, char *, char *, char *, pid_t, uid_t);
81
void mm_audit_session_key_free_body(int, pid_t, uid_t);
81
#endif
82
#endif
82
83
83
struct Session;
84
struct Session;
(-)openssh-5.8p1/packet.c.audit4 (-29 / +87 lines)
Lines 60-65 Link Here
60
#include <signal.h>
60
#include <signal.h>
61
61
62
#include "xmalloc.h"
62
#include "xmalloc.h"
63
#include "audit.h"
63
#include "buffer.h"
64
#include "buffer.h"
64
#include "packet.h"
65
#include "packet.h"
65
#include "crc32.h"
66
#include "crc32.h"
Lines 472-477 packet_get_connection_out(void) Link Here
472
	return active_state->connection_out;
473
	return active_state->connection_out;
473
}
474
}
474
475
476
static int
477
packet_state_has_keys (const struct session_state *state)
478
{
479
	return state != NULL &&
480
		(state->newkeys[MODE_IN] != NULL || state->newkeys[MODE_OUT] != NULL);
481
}
482
475
/* Closes the connection and clears and frees internal data structures. */
483
/* Closes the connection and clears and frees internal data structures. */
476
484
477
void
485
void
Lines 480-492 packet_close(void) Link Here
480
	if (!active_state->initialized)
488
	if (!active_state->initialized)
481
		return;
489
		return;
482
	active_state->initialized = 0;
490
	active_state->initialized = 0;
483
	if (active_state->connection_in == active_state->connection_out) {
484
		shutdown(active_state->connection_out, SHUT_RDWR);
485
		close(active_state->connection_out);
486
	} else {
487
		close(active_state->connection_in);
488
		close(active_state->connection_out);
489
	}
490
	buffer_free(&active_state->input);
491
	buffer_free(&active_state->input);
491
	buffer_free(&active_state->output);
492
	buffer_free(&active_state->output);
492
	buffer_free(&active_state->outgoing_packet);
493
	buffer_free(&active_state->outgoing_packet);
Lines 495-502 packet_close(void) Link Here
495
		buffer_free(&active_state->compression_buffer);
496
		buffer_free(&active_state->compression_buffer);
496
		buffer_compress_uninit();
497
		buffer_compress_uninit();
497
	}
498
	}
498
	cipher_cleanup(&active_state->send_context);
499
	if (packet_state_has_keys(active_state)) {
499
	cipher_cleanup(&active_state->receive_context);
500
		cipher_cleanup(&active_state->send_context);
501
		cipher_cleanup(&active_state->receive_context);
502
		audit_session_key_free(2);
503
	}
504
	if (active_state->connection_in == active_state->connection_out) {
505
		shutdown(active_state->connection_out, SHUT_RDWR);
506
		close(active_state->connection_out);
507
	} else {
508
		close(active_state->connection_in);
509
		close(active_state->connection_out);
510
	}
500
}
511
}
501
512
502
/* Sets remote side protocol flags. */
513
/* Sets remote side protocol flags. */
Lines 731-736 packet_send1(void) Link Here
731
	 */
742
	 */
732
}
743
}
733
744
745
static void
746
newkeys_destroy_and_free(Newkeys *newkeys)
747
{
748
	if (newkeys == NULL)
749
		return;
750
751
	xfree(newkeys->enc.name);
752
753
	mac_clear(&newkeys->mac);
754
	xfree(newkeys->mac.name);
755
756
	xfree(newkeys->comp.name);
757
758
	newkeys_destroy(newkeys);
759
	xfree(newkeys);
760
}
761
734
void
762
void
735
set_newkeys(int mode)
763
set_newkeys(int mode)
736
{
764
{
Lines 756-773 set_newkeys(int mode) Link Here
756
	}
784
	}
757
	if (active_state->newkeys[mode] != NULL) {
785
	if (active_state->newkeys[mode] != NULL) {
758
		debug("set_newkeys: rekeying");
786
		debug("set_newkeys: rekeying");
787
		audit_session_key_free(mode);
759
		cipher_cleanup(cc);
788
		cipher_cleanup(cc);
760
		enc  = &active_state->newkeys[mode]->enc;
789
		newkeys_destroy_and_free(active_state->newkeys[mode]);
761
		mac  = &active_state->newkeys[mode]->mac;
762
		comp = &active_state->newkeys[mode]->comp;
763
		mac_clear(mac);
764
		xfree(enc->name);
765
		xfree(enc->iv);
766
		xfree(enc->key);
767
		xfree(mac->name);
768
		xfree(mac->key);
769
		xfree(comp->name);
770
		xfree(active_state->newkeys[mode]);
771
	}
790
	}
772
	active_state->newkeys[mode] = kex_get_newkeys(mode);
791
	active_state->newkeys[mode] = kex_get_newkeys(mode);
773
	if (active_state->newkeys[mode] == NULL)
792
	if (active_state->newkeys[mode] == NULL)
Lines 1912-1917 packet_get_newkeys(int mode) Link Here
1912
	return (void *)active_state->newkeys[mode];
1931
	return (void *)active_state->newkeys[mode];
1913
}
1932
}
1914
1933
1934
static void
1935
packet_destroy_state(struct session_state *state)
1936
{
1937
	if (state == NULL)
1938
		return;
1939
1940
	cipher_cleanup(&state->receive_context);
1941
	cipher_cleanup(&state->send_context);
1942
1943
	buffer_free(&state->input);
1944
	buffer_free(&state->output);
1945
	buffer_free(&state->outgoing_packet);
1946
	buffer_free(&state->incoming_packet);
1947
	buffer_free(&state->compression_buffer);
1948
	newkeys_destroy_and_free(state->newkeys[MODE_IN]);
1949
	state->newkeys[MODE_IN] = NULL;
1950
	newkeys_destroy_and_free(state->newkeys[MODE_OUT]);
1951
	state->newkeys[MODE_OUT] = NULL;
1952
	mac_destroy(state->packet_discard_mac);
1953
//	TAILQ_HEAD(, packet) outgoing;
1954
//	memset(state, 0, sizeof(state));
1955
}
1956
1957
void
1958
packet_destroy_all(int audit_it, int privsep)
1959
{
1960
	if (audit_it)
1961
		audit_it = packet_state_has_keys (active_state) ||
1962
			packet_state_has_keys (backup_state);
1963
	packet_destroy_state(active_state);
1964
	packet_destroy_state(backup_state);
1965
	if (audit_it) {
1966
#ifdef SSH_AUDIT_EVENTS
1967
		if (privsep)
1968
			audit_session_key_free(2);
1969
		else
1970
			audit_session_key_free_body(2, getpid(), getuid());
1971
#endif
1972
	}
1973
}
1974
1915
/*
1975
/*
1916
 * Save the state for the real connection, and use a separate state when
1976
 * Save the state for the real connection, and use a separate state when
1917
 * resuming a suspended connection.
1977
 * resuming a suspended connection.
Lines 1919-1936 packet_get_newkeys(int mode) Link Here
1919
void
1979
void
1920
packet_backup_state(void)
1980
packet_backup_state(void)
1921
{
1981
{
1922
	struct session_state *tmp;
1923
1924
	close(active_state->connection_in);
1982
	close(active_state->connection_in);
1925
	active_state->connection_in = -1;
1983
	active_state->connection_in = -1;
1926
	close(active_state->connection_out);
1984
	close(active_state->connection_out);
1927
	active_state->connection_out = -1;
1985
	active_state->connection_out = -1;
1928
	if (backup_state)
1929
		tmp = backup_state;
1930
	else
1931
		tmp = alloc_session_state();
1932
	backup_state = active_state;
1986
	backup_state = active_state;
1933
	active_state = tmp;
1987
	active_state = alloc_session_state();
1934
}
1988
}
1935
1989
1936
/*
1990
/*
Lines 1947-1955 packet_restore_state(void) Link Here
1947
	backup_state = active_state;
2001
	backup_state = active_state;
1948
	active_state = tmp;
2002
	active_state = tmp;
1949
	active_state->connection_in = backup_state->connection_in;
2003
	active_state->connection_in = backup_state->connection_in;
1950
	backup_state->connection_in = -1;
1951
	active_state->connection_out = backup_state->connection_out;
2004
	active_state->connection_out = backup_state->connection_out;
1952
	backup_state->connection_out = -1;
1953
	len = buffer_len(&backup_state->input);
2005
	len = buffer_len(&backup_state->input);
1954
	if (len > 0) {
2006
	if (len > 0) {
1955
		buf = buffer_ptr(&backup_state->input);
2007
		buf = buffer_ptr(&backup_state->input);
Lines 1957-1960 packet_restore_state(void) Link Here
1957
		buffer_clear(&backup_state->input);
2009
		buffer_clear(&backup_state->input);
1958
		add_recv_bytes(len);
2010
		add_recv_bytes(len);
1959
	}
2011
	}
2012
	backup_state->connection_in = -1;
2013
	backup_state->connection_out = -1;
2014
	packet_destroy_state(backup_state);
2015
	xfree(backup_state);
2016
	backup_state = NULL;
1960
}
2017
}
2018
(-)openssh-5.8p1/packet.h.audit4 (+1 lines)
Lines 125-128 void packet_restore_state(void); Link Here
125
void	*packet_get_input(void);
125
void	*packet_get_input(void);
126
void	*packet_get_output(void);
126
void	*packet_get_output(void);
127
127
128
void	 packet_destroy_all(int, int);
128
#endif				/* PACKET_H */
129
#endif				/* PACKET_H */
(-)openssh-5.8p1/session.c.audit4 (+3 lines)
Lines 1627-1632 do_child(Session *s, const char *command Link Here
1627
1627
1628
	/* remove hostkey from the child's memory */
1628
	/* remove hostkey from the child's memory */
1629
	destroy_sensitive_data();
1629
	destroy_sensitive_data();
1630
	/* Don't audit this - both us and the parent would be talking to the
1631
	   monitor over a single socket, with no synchronization. */
1632
	packet_destroy_all(0, 1);
1630
1633
1631
	/* Force a password change */
1634
	/* Force a password change */
1632
	if (s->authctxt->force_pwchange) {
1635
	if (s->authctxt->force_pwchange) {
(-)openssh-5.8p1/sshd.c.audit4 (+10 lines)
Lines 663-668 privsep_preauth(Authctxt *authctxt) Link Here
663
	return (0);
663
	return (0);
664
}
664
}
665
665
666
extern Newkeys *current_keys[];
667
666
static void
668
static void
667
privsep_postauth(Authctxt *authctxt)
669
privsep_postauth(Authctxt *authctxt)
668
{
670
{
Lines 688-693 privsep_postauth(Authctxt *authctxt) Link Here
688
		verbose("User child is on pid %ld", (long)pmonitor->m_pid);
690
		verbose("User child is on pid %ld", (long)pmonitor->m_pid);
689
		close(pmonitor->m_recvfd);
691
		close(pmonitor->m_recvfd);
690
		buffer_clear(&loginmsg);
692
		buffer_clear(&loginmsg);
693
 		newkeys_destroy(current_keys[MODE_OUT]);
694
		newkeys_destroy(current_keys[MODE_IN]);
695
		audit_session_key_free_body(2, getpid(), getuid());
696
		packet_destroy_all(0, 0);
691
		monitor_child_postauth(pmonitor);
697
		monitor_child_postauth(pmonitor);
692
698
693
		/* NEVERREACHED */
699
		/* NEVERREACHED */
Lines 1974-1979 main(int ac, char **av) Link Here
1974
	 */
1980
	 */
1975
	if (use_privsep) {
1981
	if (use_privsep) {
1976
		mm_send_keystate(pmonitor);
1982
		mm_send_keystate(pmonitor);
1983
		packet_destroy_all(1, 1);
1977
		exit(0);
1984
		exit(0);
1978
	}
1985
	}
1979
1986
Lines 2026-2031 main(int ac, char **av) Link Here
2026
	do_authenticated(authctxt);
2033
	do_authenticated(authctxt);
2027
2034
2028
	/* The connection has been terminated. */
2035
	/* The connection has been terminated. */
2036
	packet_destroy_all(1, 1);
2037
2029
	packet_get_state(MODE_IN, NULL, NULL, NULL, &ibytes);
2038
	packet_get_state(MODE_IN, NULL, NULL, NULL, &ibytes);
2030
	packet_get_state(MODE_OUT, NULL, NULL, NULL, &obytes);
2039
	packet_get_state(MODE_OUT, NULL, NULL, NULL, &obytes);
2031
	verbose("Transferred: sent %llu, received %llu bytes",
2040
	verbose("Transferred: sent %llu, received %llu bytes",
Lines 2345-2350 cleanup_exit(int i) Link Here
2345
{
2354
{
2346
	if (the_authctxt)
2355
	if (the_authctxt)
2347
		do_cleanup(the_authctxt);
2356
		do_cleanup(the_authctxt);
2357
	packet_destroy_all(1, is_privsep_child);
2348
#ifdef SSH_AUDIT_EVENTS
2358
#ifdef SSH_AUDIT_EVENTS
2349
	/* done after do_cleanup so it can cancel the PAM auth 'thread' */
2359
	/* done after do_cleanup so it can cancel the PAM auth 'thread' */
2350
	if ((the_authctxt == NULL || !the_authctxt->authenticated) &&
2360
	if ((the_authctxt == NULL || !the_authctxt->authenticated) &&

Return to bug 1402