#3 1.04 hangs with openssh 5.6

pending
nobody
None
5
2011-08-06
2010-11-25
Anonymous
No

Hangs for me using openssh 5.6
Seems to be to do with openssh 5.6 handling the motd differently.

Fix for me seems to be:

diff main.c.old main.c.new
40a41
> #include <time.h>
310a312,313
> int numread;
> fd_set rfds;
312c315,320
< int numread=read(fd, buffer, sizeof(buffer) );
---
> struct timeval t= {2,00000};
>
> FD_ZERO(&rfds);
> FD_SET(fd,&rfds);
> select(fd, &rfds, NULL, NULL, &t);
> numread=read(fd,buffer,sizeof(buffer));

Discussion

  • aunxx
    aunxx
    2010-11-25

    Hi.

    The above only works because it adds a 2 second pause.

    A simpler fix is to change line 314 to

    if( numread<0 && errno!=5 ) {

     
  • aunxx
    aunxx
    2010-11-26

    ... But that causes the cpu to run high. :(

     
  • aunxx
    aunxx
    2010-11-29

    Could do with more work, but is a working patch which doesn't max the CPU and doesn't depend on a fixed pause.

    --- main.c.old 2010-11-25 10:32:17.000000000 +0000
    +++ main.c 2010-11-29 12:38:35.000000000 +0000
    @@ -308,10 +308,15 @@
    // This is not a problem, as ssh exists immediately in such a case
    char buffer[40];
    int ret=0;
    + static int passaccepted=0;

    int numread=read(fd, buffer, sizeof(buffer) );

    - if( numread<0 ) {
    + if (passaccepted > 0) {
    + return -1;
    + }
    +
    + if( numread<0 && errno !=5 ) {
    // Comment no. 3.1416
    // Select is doing a horrid job of waking us up at the right time - it wakes up with "read ready" when the slave
    // end of the pty is closed. This result in an IO error when we perform a read. In the general case, this does
    @@ -329,6 +334,7 @@
    write_pass( fd );
    state1=0;
    prevmatch=1;
    + passaccepted=1;
    } else {
    // Wrong password - terminate with proper error code
    ret=RETURN_INCORRECT_PASSWORD;

     
  • All of the suggestions above either do not solve the problem, consume 100% CPU, or put an arbitrary wait.

    The problem was that the work-around to the kernel bug of the master PTY getting EIO if no slave PTY is actively open stopped working in OpenSSH version 5.6. That version started closing all unknown open file descriptors, destroying our work around, and, unfortunately, also the detection of program exit status.

    SVN revision 49 has a correct fix to this bug. I'll issue a new release soon.

    Shachar

     
    • summary: 1.04 fails with openssh 5.6 --> 1.04 hangs with openssh 5.6
    • status: open --> pending
     
  • Also, in the future, please send patches in unified diff format.