| Summary: | sshd with ControlMaster does not close child STDERR on client exit | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Product: | Portable OpenSSH | Reporter: | Nelson Elhage <nelhage> | ||||||
| Component: | sshd | Assignee: | Damien Miller <djm> | ||||||
| Status: | CLOSED FIXED | ||||||||
| Severity: | minor | CC: | bugzilla, djm | ||||||
| Priority: | P5 | ||||||||
| Version: | 7.6p1 | ||||||||
| Hardware: | amd64 | ||||||||
| OS: | Linux | ||||||||
| Bug Depends on: | |||||||||
| Bug Blocks: | 2893 | ||||||||
| Attachments: |
|
||||||||
|
Description
Nelson Elhage
2018-05-02 09:40:48 AEST
I looked into this with Nelson a bit - it looks like this is the /* XXX */ in channel_pre_open in channel.c. That function appears to properly handle stdin and stdout, but stderr is only select()ed on if stdin and stdout are open, which seems wrong. I also don't see anything that ever closes stderr, other than the process exiting. This might be a client-side thing (client not sending a shutdown for stderr) but I'm not following the logic of nchan.c well enough to see who should be handling stderr. Are you really using 6.6p1? If so, please try to replicate this with the current version. There's four years of fixes since 6.6 was released. I first diagnosed this on Ubuntu Trusty, which is in fact 6.6p1. I was just able to reproduce on 7.2p1; I'll try to spin up an even newer version to test there in a bit. Reproduced on 7.6p1. Created attachment 3182 [details]
close efd when shutting down read/write
I *think* this is the correct solution, but I'm not 100% sure yet that it won't cause data loss around EOF.
Created attachment 3185 [details]
close read-mode efd when channel close received
That first patch was definitely wrong - it broke our current stderr handling tests.
This one is a bit more delicate: close the extended fd when it is in read mode (i.e. in sshd and attached to read a subprocess' stderr) and the channel receives a close message.
I've committed this fix and it should be in OpenSSH 7.9 - thanks! commit e0d6501e86734c48c8c503f81e1c0926e98c5c4c (HEAD -> master, origin/master, origin/HEAD) Author: djm@openbsd.org <djm@openbsd.org> Date: Thu Oct 4 07:47:35 2018 +0000 upstream: when the peer sends a channel-close message, make sure we close the local extended read fd (stderr) along with the regular read fd (stdout). Avoids weird stuck processed in multiplexing mode. Report and analysis by Nelson Elhage and Geoffrey Thomas in bz#2863 ok dtucker@ markus@ OpenBSD-Commit-ID: a48a2467fe938de4de69d2e7193d5fa701f12ae9 Close RESOLVED bugs with the release of openssh-8.0 |