Bug 1317924

Summary: RFC: ncat failing with input/output error with ssl option
Product: Red Hat Enterprise Linux 7 Reporter: Paulo Andrade <pandrade>
Component: nmapAssignee: Pavel Zhukov <pzhukov>
Status: CLOSED ERRATA QA Contact: Jaroslav Aster <jaster>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.2CC: dmiller, jaster, ksrot, mhlavink, omoris, thozza
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: nmap-6.40-9.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-04-10 08:36:10 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1460249    
Bug Blocks: 1298243, 1420851, 1465887, 1465928    
Attachments:
Description Flags
localhost.key
none
localhost.pem none

Description Paulo Andrade 2016-03-15 14:10:57 UTC
User can consistently reproduce the problem, even if testing
a localhost connection.

  A test case, on an environment where the problem would happen
could be (I cannot reproduce the issue in my environment):

---8<---
# mkdir /tmp/test
# cd /tmp/test
# yes us | openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout localhost.key -out localhost.pem
# ncat  -l -p 5000  --ssl --ssl-key localhost.key --ssl-cert localhost.pem > /tmp/F;ls -l /tmp/F

<<< on a second terminal >>>

# tar --acls -C /boot -cvf - . | ncat --ssl -i 4  -4 --send-only --ssl-verify --ssl-trustfile /tmp/test/localhost.pem localhost 5000
---8<---

  The only workaround we found was to add --scpt to both ncat
commands, otherwise it would quickly fail with the message:

Ncat: Input/output error.

  I did several tests, but could not find a way to correct the
problem, until I found the "hint" about --sctp on a message, without
replies, at:

http://seclists.org/nmap-dev/2015/q4/58

and the workaround indeed corrected the problem.
The user says there is no firewall, and even validated testing
on localhost, and still got the problem. There are no logs, and
if running ncat on very verbose mode, the messages on the sending
side will look like:

---8<---
[...]
libnsock msevent_cancel(): msevent_cancel on event #92 (type TIMER)
libnsock msevent_delete(): msevent_delete (IOD #NULL) (EID #92)
libnsock msevent_new(): msevent_new (IOD #NULL) (EID #116)
libnsock nsock_timer_create(): Timer created - 4000ms from now.  EID 116
libnsock nsp_add_event(): NSE #116: Adding event
libnsock msevent_delete(): msevent_delete (IOD #2) (EID #98)
libnsock nsock_trace_handler_callback(): Callback: WRITE ERROR [Input/output error (5)] for EID 107 [111.22.3.444:5000]
Ncat: Input/output error.
---8>---

Comment 2 Michal Hlavinka 2016-03-15 14:33:30 UTC
reproducible

(In reply to Paulo Andrade from comment #0)
>   I did several tests, but could not find a way to correct the
> problem, until I found the "hint" about --sctp on a message, without
> replies, at:
> 
> http://seclists.org/nmap-dev/2015/q4/58

Unfortunately, nmap upstream does not really focus on ncat, it's more like see what our libraries can do. I've sent them patches for review a long time ago and it's very difficult to get any response from them.


----
for QE: reproducer needs also
-subj '/CN=localhost'
as openssl command, or ncat will fail with certificate verification error

Comment 3 Paulo Andrade 2016-03-15 14:45:56 UTC
Created attachment 1136642 [details]
localhost.key

sorry for the bad example creating certs, need to fill manually.
Just attaching ready ones for testing purposes.

Or, do not make the "yes us" pipe, and type:

us
us
us
us
localhost

Comment 4 Paulo Andrade 2016-03-15 14:46:20 UTC
Created attachment 1136643 [details]
localhost.pem

Comment 5 Paulo Andrade 2016-03-23 13:41:51 UTC
  Hi Michal,

  Can you attach the patches you said was sent to upstream
to the case report? Or where they not related to this issue?

  I asked the user to be 100% sure to reproduce the problem
on a localhost connection, and actually, it does not happen
in a localhost connection.

  I assumed it would fail on localhost connection, but after
user telling it works, I tested it better, and can also reproduce
the issue if connecting two hosts (and then, it works if using
--sctp).

Comment 6 Michal Hlavinka 2016-03-23 14:01:48 UTC
(In reply to Paulo Andrade from comment #5)
>   Can you attach the patches you said was sent to upstream
> to the case report? Or where they not related to this issue?
> 
They were not related to this issue. It was just to illustrate, that getting upstream response is close to impossible

for example https://github.com/nmap/nmap/issues/157 that is reported upstream with patch for a few years (first mailing list, than issue tracker) with no response

Comment 8 Daniel Miller 2017-03-19 02:32:42 UTC
I have just fixed this in Nmap upstream r36652. The problem is in the Ncat server, which was treating SSL_read identically to recv: the problem is that SSL_read can return -1 when all that is required is to try the call again. After adding code to check for this condition, the connection is maintained and transfer is successful. This will be included in the next release of Ncat/Nmap.

https://github.com/nmap/nmap/commit/ac8b866d73ca4df63c4b336253afd944d44d9c6a

Comment 20 errata-xmlrpc 2018-04-10 08:36:10 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2018:0661