Restoring block mode on exiting
Dmitry Belyavskiy
dbelyavs at redhat.com
Sat Apr 24 01:11:14 AEST 2021
Dear David,
Thank you for your recommendations!
On Fri, Apr 23, 2021 at 4:47 AM David Newall <openssh at davidnewall.com>
wrote:
> Hi Dmitry,
>
> On 23/4/21 1:06 am, Dmitry Belyavskiy wrote:
> > OpenSSH incorrectly restores the standard mode (blocking mode) on
> standard
> > output upon exiting.
>
> I agree that SSH should *restore* the blocking mode. I've only spent a
> small
> amount of timelooking at it and I think SSH currently does not do that, and
> your patch also does not.
>
> Your patch sets blocking mode if SSH cleared it. I think it would be more
> correct to restore it tothe state that it was when SSH took over the file
> because we shouldn't assume.
>
> In channel_register_fds, don't record if we set non-blocking mode, record
> what mode it currentlyhas:
>
> c->nonblock = (get_nonblock(rfd) << 2) | (get_nonblock(wfd) << 1) |
> get_nonblock(efd);
>
> Restore in channel_close_fds:
>
> channel_close_fd(ssh, &c->sock, 0);
> if (rfd != sock) channel_close_fd(ssh, &c->rfd, c->nonblock & 4);
> if (wfd != sock) channel_close_fd(ssh, &c->wfd, c->nonblock & 2);
> if (efd != sock) channel_close_fd(ssh, &c->efd, c->nonblock & 1);
>
> In channel_close_fd:
>
> if (fd != -1) (nonblock?set_nonblock:unset_nonblock)(fd);
>
Could you please take a look at the updated version of the patch?
If I understand correctly, it provides the same blocking state after
closing the channel as it was before closing.
https://github.com/openssh/openssh-portable/pull/246
Many thanks!
--
Dmitry Belyavskiy
More information about the openssh-unix-dev
mailing list