Red Hat Bugzilla – Bug 1436402
nc from nmap ncat crash if ipv6 disabled
Last modified: 2018-04-10 04:37:10 EDT
The crash always happen due to to nmap-6.40-allresolve.patch but can be made to crash without the patch by passing "-6" in the command line, so the patch is not really wrong, just exposes the issue. Steps to reproduce: 1. Boot with "ipv6.disable=1" as kernel parameter 2. Run "nc -6 localhost" Adding -6 just for it to not try ipv4 before. Expectd output would be the same as: $ nc -4 localhost Ncat: Connection refused. but what happens is: $ nc -6 localhost Socket troubles: Address family not supported by protocol nc: engine_select.c:353: get_evmask: Assertion `sd >= 0' failed. Aborted (core dumped) The fix probably should involve not adding to the event list in nsock/src/nsock_connect.c:nsp_add_event() if it failed to connect, or, nsock/src/engine_select.c:iterate_through_event_lists() check the event and not call process_event() if the (connect_event) event has event_done set, but would need to check too many states for that. Likely fix would be in pseudo patch: if (!nse->event_done) { assert(nse->iod->sd >= 0); socket_count_read_inc(nse->iod); socket_count_write_inc(nse->iod); update_events(nse->iod, nsp, EV_READ|EV_WRITE|EV_EXCEPT, EV_NONE); } + else if (nse->iod->sd < 0) { + /* do something else, update logs, etc */ + msevent_delete(nsp, nse); + /* do something else, update logs, etc */ + } + else iod_add_event(nse->iod, nse);
Hi Pavel, I'm not sure, is this output ok? I see the same output in the old/new version, abort without crash. # rpm -q nmap nmap-ncat-6.40-12.el7.x86_64 # ncat -6 localhost Socket troubles: Address family not supported by protocol ncat: engine_select.c:353: get_evmask: Assertion `sd >= 0' failed. Aborted # rpm -q nmap-ncat nmap-ncat-6.40-7.el7.x86_64 # ncat -6 localhost Socket troubles: Address family not supported by protocol ncat: engine_select.c:353: get_evmask: Assertion `sd >= 0' failed. Aborted
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