From b84886ba3e362f54b70aefcbe1aa10606309b7d7 Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Mon, 19 May 2008 15:05:07 +1000 Subject: - djm@cvs.openbsd.org 2008/05/08 12:02:23 [auth-options.c auth1.c channels.c channels.h clientloop.c gss-serv.c] [monitor.c monitor_wrap.c nchan.c servconf.c serverloop.c session.c] [ssh.c sshd.c] Implement a channel success/failure status confirmation callback mechanism. Each channel maintains a queue of callbacks, which will be drained in order (RFC4253 guarantees confirm messages are not reordered within an channel). Also includes a abandonment callback to clean up if a channel is closed without sending confirmation messages. This probably shouldn't happen in compliant implementations, but it could be abused to leak memory. ok markus@ (as part of a larger diff) --- nchan.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'nchan.c') diff --git a/nchan.c b/nchan.c index ad461f4af..0d0faddb3 100644 --- a/nchan.c +++ b/nchan.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nchan.c,v 1.57 2006/08/03 03:34:42 deraadt Exp $ */ +/* $OpenBSD: nchan.c,v 1.58 2008/05/08 12:02:23 djm Exp $ */ /* * Copyright (c) 1999, 2000, 2001, 2002 Markus Friedl. All rights reserved. * @@ -32,6 +32,7 @@ #include #include +#include "openbsd-compat/sys-queue.h" #include "ssh1.h" #include "ssh2.h" #include "buffer.h" -- cgit v1.2.3 From bab9bd4c20dac1d513fbf16d1214e0c0f9a1bf3b Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Mon, 19 May 2008 16:06:47 +1000 Subject: - markus@cvs.openbsd.org 2008/05/09 16:21:13 [channels.h clientloop.c nchan.c serverloop.c] unbreak ssh -2 localhost od /bin/ls | true ignoring SIGPIPE by adding a new channel message (EOW) that signals the peer that we're not interested in any data it might send. fixes bz #85; discussion, debugging and ok djm@ --- ChangeLog | 9 ++++++++- channels.h | 3 ++- clientloop.c | 5 ++++- nchan.c | 30 +++++++++++++++++++++++++++++- serverloop.c | 7 +++++-- 5 files changed, 48 insertions(+), 6 deletions(-) (limited to 'nchan.c') diff --git a/ChangeLog b/ChangeLog index fd75c3404..7d9b0f853 100644 --- a/ChangeLog +++ b/ChangeLog @@ -133,6 +133,13 @@ for channels with both in- and output closed, since the channel will go away before we call select(); report, lots of debugging help and ok djm@ + - markus@cvs.openbsd.org 2008/05/09 16:21:13 + [channels.h clientloop.c nchan.c serverloop.c] + unbreak + ssh -2 localhost od /bin/ls | true + ignoring SIGPIPE by adding a new channel message (EOW) that signals + the peer that we're not interested in any data it might send. + fixes bz #85; discussion, debugging and ok djm@ 20080403 - (djm) [openbsd-compat/bsd-poll.c] Include stdlib.h to avoid compile- @@ -3993,4 +4000,4 @@ OpenServer 6 and add osr5bigcrypt support so when someone migrates passwords between UnixWare and OpenServer they will still work. OK dtucker@ -$Id: ChangeLog,v 1.4929 2008/05/19 06:05:41 djm Exp $ +$Id: ChangeLog,v 1.4930 2008/05/19 06:06:47 djm Exp $ diff --git a/channels.h b/channels.h index d4ac24a51..ec2435df0 100644 --- a/channels.h +++ b/channels.h @@ -1,4 +1,4 @@ -/* $OpenBSD: channels.h,v 1.91 2008/05/09 04:55:56 djm Exp $ */ +/* $OpenBSD: channels.h,v 1.92 2008/05/09 16:21:13 markus Exp $ */ /* * Author: Tatu Ylonen @@ -267,6 +267,7 @@ void chan_mark_dead(Channel *); /* channel events */ void chan_rcvd_oclose(Channel *); +void chan_rcvd_eow(Channel *); /* SSH2-only */ void chan_read_failed(Channel *); void chan_ibuf_empty(Channel *); diff --git a/clientloop.c b/clientloop.c index c87aa5a0a..584afb76a 100644 --- a/clientloop.c +++ b/clientloop.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clientloop.c,v 1.192 2008/05/09 14:18:44 djm Exp $ */ +/* $OpenBSD: clientloop.c,v 1.193 2008/05/09 16:21:13 markus Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -1666,6 +1666,9 @@ client_input_channel_req(int type, u_int32_t seq, void *ctxt) error("client_input_channel_req: request for channel -1"); } else if ((c = channel_lookup(id)) == NULL) { error("client_input_channel_req: channel %d: unknown channel", id); + } else if (strcmp(rtype, "eow@openssh.com") == 0) { + packet_check_eom(); + chan_rcvd_eow(c); } else if (strcmp(rtype, "exit-status") == 0) { exitval = packet_get_int(); if (id == session_ident) { diff --git a/nchan.c b/nchan.c index 0d0faddb3..a4a456eab 100644 --- a/nchan.c +++ b/nchan.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nchan.c,v 1.58 2008/05/08 12:02:23 djm Exp $ */ +/* $OpenBSD: nchan.c,v 1.59 2008/05/09 16:21:13 markus Exp $ */ /* * Copyright (c) 1999, 2000, 2001, 2002 Markus Friedl. All rights reserved. * @@ -78,6 +78,7 @@ static void chan_send_ieof1(Channel *); static void chan_send_oclose1(Channel *); static void chan_send_close2(Channel *); static void chan_send_eof2(Channel *); +static void chan_send_eow2(Channel *); /* helper */ static void chan_shutdown_write(Channel *); @@ -306,6 +307,17 @@ chan_rcvd_close2(Channel *c) break; } } +void +chan_rcvd_eow(Channel *c) +{ + debug2("channel %d: rcvd eow", c->self); + switch (c->istate) { + case CHAN_INPUT_OPEN: + chan_shutdown_read(c); + chan_set_istate(c, CHAN_INPUT_CLOSED); + break; + } +} static void chan_rcvd_eof2(Channel *c) { @@ -322,6 +334,7 @@ chan_write_failed2(Channel *c) case CHAN_OUTPUT_OPEN: case CHAN_OUTPUT_WAIT_DRAIN: chan_shutdown_write(c); + chan_send_eow2(c); chan_set_ostate(c, CHAN_OUTPUT_CLOSED); break; default: @@ -364,6 +377,21 @@ chan_send_close2(Channel *c) c->flags |= CHAN_CLOSE_SENT; } } +static void +chan_send_eow2(Channel *c) +{ + debug2("channel %d: send eow", c->self); + if (c->ostate == CHAN_OUTPUT_CLOSED) { + error("channel %d: must not sent eow on closed output", + c->self); + return; + } + packet_start(SSH2_MSG_CHANNEL_REQUEST); + packet_put_int(c->remote_id); + packet_put_cstring("eow@openssh.com"); + packet_put_char(0); + packet_send(); +} /* shared */ diff --git a/serverloop.c b/serverloop.c index 2142f3809..6bc140f8b 100644 --- a/serverloop.c +++ b/serverloop.c @@ -1,4 +1,4 @@ -/* $OpenBSD: serverloop.c,v 1.150 2008/05/09 04:55:56 djm Exp $ */ +/* $OpenBSD: serverloop.c,v 1.151 2008/05/09 16:21:13 markus Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -1160,7 +1160,10 @@ server_input_channel_req(int type, u_int32_t seq, void *ctxt) if ((c = channel_lookup(id)) == NULL) packet_disconnect("server_input_channel_req: " "unknown channel %d", id); - if (c->type == SSH_CHANNEL_LARVAL || c->type == SSH_CHANNEL_OPEN) + if (!strcmp(rtype, "eow@openssh.com")) { + packet_check_eom(); + chan_rcvd_eow(c); + } else if (c->type == SSH_CHANNEL_LARVAL || c->type == SSH_CHANNEL_OPEN) success = session_input_channel_req(c, rtype); if (reply) { packet_start(success ? -- cgit v1.2.3 From 8748b965224cea8811d30c8fe9b5d2113d7e49de Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Wed, 2 Jul 2008 22:32:43 +1000 Subject: - djm@cvs.openbsd.org 2008/06/30 12:16:02 [nchan.c] only send eow@openssh.com notifications for session channels; ok! markus@ --- ChangeLog | 5 ++++- nchan.c | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'nchan.c') diff --git a/ChangeLog b/ChangeLog index 5ff155db1..b0781721f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,9 @@ [serverloop.c] only pass channel requests on session channels through to the session channel handler, avoiding spurious log messages; ok! markus@ + - djm@cvs.openbsd.org 2008/06/30 12:16:02 + [nchan.c] + only send eow@openssh.com notifications for session channels; ok! markus@ 20080630 - (djm) OpenBSD CVS Sync @@ -4490,4 +4493,4 @@ OpenServer 6 and add osr5bigcrypt support so when someone migrates passwords between UnixWare and OpenServer they will still work. OK dtucker@ -$Id: ChangeLog,v 1.5040 2008/07/02 12:32:14 dtucker Exp $ +$Id: ChangeLog,v 1.5041 2008/07/02 12:32:43 dtucker Exp $ diff --git a/nchan.c b/nchan.c index a4a456eab..e0ebf43f1 100644 --- a/nchan.c +++ b/nchan.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nchan.c,v 1.59 2008/05/09 16:21:13 markus Exp $ */ +/* $OpenBSD: nchan.c,v 1.60 2008/06/30 12:16:02 djm Exp $ */ /* * Copyright (c) 1999, 2000, 2001, 2002 Markus Friedl. All rights reserved. * @@ -334,7 +334,8 @@ chan_write_failed2(Channel *c) case CHAN_OUTPUT_OPEN: case CHAN_OUTPUT_WAIT_DRAIN: chan_shutdown_write(c); - chan_send_eow2(c); + if (strcmp(c->ctype, "session") == 0) + chan_send_eow2(c); chan_set_ostate(c, CHAN_OUTPUT_CLOSED); break; default: -- cgit v1.2.3