[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OpenSSH: cause of random kex_exchange_identification errors?



On 2022-02-02 09:44, Vincent Lefevre wrote:
In the source, this corresponds to function kex_exchange_identification
in kex.c:

     len = atomicio(read, ssh_packet_get_connection_in(ssh),
         &c, 1);
     if (len != 1 && errno == EPIPE) {
             error_f("Connection closed by remote host");
             r = SSH_ERR_CONN_CLOSED;
             goto out;
     } else if (len != 1) {
             oerrno = errno;
             error_f("read: %.100s", strerror(errno));
             r = SSH_ERR_SYSTEM_ERROR;
             goto out;
     }

so either with EPIPE or with ECONNRESET, and this apparently occurs
before the exchange of banners.

If you look at the source of atomicio you will see that in this case it will do a read() of 1 byte on the file descriptor used for communicating with the other side.

atomicio will set errno to EPIPE if 0 bytes are returned on any of the reads it does

and it returns the number of bytes read, which will be 0 or 1 in this case.

So the failure modes are 0 bytes read and read didn't return an error (EPIPE), or 0 bytes read and read did return an error (read returns -1 and sets errno to something other than EPIPE).

But I think basically this means that read on the socket fails, or basically can't read from the network.

Bijan


Reply to: