diff options
author | djm@openbsd.org <djm@openbsd.org> | 2021-05-19 01:24:05 +0000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2021-05-19 11:52:14 +1000 |
commit | 7be4ac813662f68e89f23c50de058a49aa32f7e4 (patch) | |
tree | 7040d1e4601e2a0545e20614e96d8d818eccbf35 /channels.h | |
parent | c4902e1a653c67fea850ec99c7537f358904c0af (diff) |
upstream: restore blocking status on stdio fds before close
ssh(1) needs to set file descriptors to non-blocking mode to operate
but it was not restoring the original state on exit. This could cause
problems with fds shared with other programs via the shell, e.g.
> $ cat > test.sh << _EOF
> #!/bin/sh
> {
> ssh -Fnone -oLogLevel=verbose ::1 hostname
> cat /usr/share/dict/words
> } | sleep 10
> _EOF
> $ ./test.sh
> Authenticated to ::1 ([::1]:22).
> Transferred: sent 2352, received 2928 bytes, in 0.1 seconds
> Bytes per second: sent 44338.9, received 55197.4
> cat: stdout: Resource temporarily unavailable
This restores the blocking status for fds 0,1,2 (stdio) before ssh(1)
abandons/closes them.
This was reported as bz3280 and GHPR246; ok dtucker@
OpenBSD-Commit-ID: 8cc67346f05aa85a598bddf2383fcfcc3aae61ce
Diffstat (limited to 'channels.h')
-rw-r--r-- | channels.h | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -1,4 +1,4 @@ -/* $OpenBSD: channels.h,v 1.137 2021/04/03 06:18:40 djm Exp $ */ +/* $OpenBSD: channels.h,v 1.138 2021/05/19 01:24:05 djm Exp $ */ /* * Author: Tatu Ylonen <ylo@cs.hut.fi> @@ -63,6 +63,16 @@ #define CHANNEL_CANCEL_PORT_STATIC -1 +/* nonblocking flags for channel_new */ +#define CHANNEL_NONBLOCK_LEAVE 0 /* don't modify non-blocking state */ +#define CHANNEL_NONBLOCK_SET 1 /* set non-blocking state */ +#define CHANNEL_NONBLOCK_STDIO 2 /* set non-blocking and restore on close */ + +/* c->restore_block mask flags */ +#define CHANNEL_RESTORE_RFD 0x01 +#define CHANNEL_RESTORE_WFD 0x02 +#define CHANNEL_RESTORE_EFD 0x04 + /* TCP forwarding */ #define FORWARD_DENY 0 #define FORWARD_REMOTE (1) @@ -139,6 +149,7 @@ struct Channel { * to a matching pre-select handler. * this way post-select handlers are not * accidentally called if a FD gets reused */ + int restore_block; /* fd mask to restore blocking status */ struct sshbuf *input; /* data read from socket, to be sent over * encrypted connection */ struct sshbuf *output; /* data received over encrypted connection for @@ -266,7 +277,7 @@ void channel_register_filter(struct ssh *, int, channel_infilter_fn *, void channel_register_status_confirm(struct ssh *, int, channel_confirm_cb *, channel_confirm_abandon_cb *, void *); void channel_cancel_cleanup(struct ssh *, int); -int channel_close_fd(struct ssh *, int *); +int channel_close_fd(struct ssh *, Channel *, int *); void channel_send_window_changes(struct ssh *); /* mux proxy support */ @@ -313,7 +324,7 @@ Channel *channel_connect_to_port(struct ssh *, const char *, u_short, char *, char *, int *, const char **); Channel *channel_connect_to_path(struct ssh *, const char *, char *, char *); Channel *channel_connect_stdio_fwd(struct ssh *, const char*, - u_short, int, int); + u_short, int, int, int); Channel *channel_connect_by_listen_address(struct ssh *, const char *, u_short, char *, char *); Channel *channel_connect_by_listen_path(struct ssh *, const char *, |