Bug 1899824
| Summary: | netcat (nc) listener fails with "Bad file descriptor" after a connection is made | ||
|---|---|---|---|
| Product: | Red Hat Enterprise Linux 8 | Reporter: | Pavel Zhukov <pzhukov> |
| Component: | nmap | Assignee: | Martin Osvald 🛹 <mosvald> |
| Status: | CLOSED ERRATA | QA Contact: | František Hrdina <fhrdina> |
| Severity: | high | Docs Contact: | |
| Priority: | high | ||
| Version: | 8.2 | CC: | aajith, fhrdina, jbainbri, jorton, ndavids |
| Target Milestone: | rc | Keywords: | AutoVerified, TestCaseNeeded, Triaged |
| Target Release: | 8.0 | Flags: | pm-rhel:
mirror+
|
| Hardware: | All | ||
| OS: | Linux | ||
| Whiteboard: | |||
| Fixed In Version: | nmap-7.70-7.el8 | Doc Type: | If docs needed, set a value |
| Doc Text: | Story Points: | --- | |
| Clone Of: | Environment: | ||
| Last Closed: | 2022-11-08 09:38:42 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: | |||
|
Description
Pavel Zhukov
2020-11-20 06:11:21 UTC
(In reply to Pavel Zhukov from comment #0) > > I am pretty sure that the problem is that with IPv6 disabled the socket call > to create the AFINET6 socket fails and the variable holding the FD for the > socket is set to -1. This is not checked when the listening sockets are > closed after the connection so the close fails and nc aborts. That's not root cause of the issue. The issue is in resolve() [1] and underlying getaddrinfo() call which returns AF_INET6 as a family even if IPv6 is disabled. Besides of that ncat_listen_stream() has a bug with listen_socket[] array length calculation if wrong (-1) FD is the very last in the list. [1] https://github.com/nmap/nmap/blob/master/ncat/ncat_main.c#L1061 The fix is in git: https://pkgs.devel.redhat.com/cgit/rpms/nmap/commit/?h=rhel-8.7.0&id=7b1f1cb7adf9c169364500410a416aa0bee68131 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 (nmap bug fix and enhancement update), 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-2022:7553 There's a problem with the fix. If AI_ADDRCONFIG is used, it doesn't listen on loopback by default. So nc -l no longer shows any services listening on loopback address. (In reply to Arun Ajith S from comment #20) > There's a problem with the fix. > If AI_ADDRCONFIG is used, it doesn't listen on loopback by default. > So nc -l no longer shows any services listening on loopback address. Hi Arun, please, could you share the steps to reproduce and the current and the expected output? Thanks! Hi Martin, My comment above is not entirely accurate. Let me describe what I can repro. We have some tests running in a network isolated environment which just has loopback interface. We run `nc -ltnp <PORT>` in the test to simulate a server and our unit under test talks to the server. In el9 environment, we're seeing that `nc` fails. This is how you can repro ``` > sudo unshare -n bash # ip link show 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 # rpm -qf `which nc` nmap-ncat-7.91-12.el9.x86_64 # nc -ntlp 686 Ncat: Failed to resolve default IPv4 address: Name or service not known. QUITTING. ``` Now if you run this in the el7 environment without the `AI_ADDRCONFIG` patch ``` > sudo unshare -n bash # ip link show 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 # rpm -qf `which nc` nmap-ncat-2:6.40-19.el7.x86_64 # nc -ntlp 686 ^Z [1]+ Stopped nc -ntlp 686 # ss -lnpt State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 10 *:686 *:* users:(("nc",pid=39676,fd=4)) LISTEN 0 10 [::]:686 [::]:* users:(("nc",pid=39676,fd=3)) ``` From https://man7.org/linux/man-pages/man3/getaddrinfo.3.html ``` If hints.ai_flags includes the AI_ADDRCONFIG flag, then IPv4 addresses are returned in the list pointed to by res only if the local system has at least one IPv4 address configured, and IPv6 addresses are returned only if the local system has at least one IPv6 address configured. The loopback address is not considered for this case as valid as a configured address. ``` So it doesn't consider `lo` as a valid interface on which it can listen. Usually servers just set `AI_PASSIVE` in the flags and pass `node` as `NULL`. |