Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
False packet loss when using shared libpcap from Ubuntu 14.04 #34
Comments
bonsaiviking
added
Nmap
bug
labels
Jan 1, 2015
dmiller-nmap
commented
Jan 12, 2015
|
Confirmed on Ubuntu 14.04 on VirtualBox with NAT adapter. Dynamic-linked with system libpcap sends about 2x as many packets and takes 4 times as long. |
dmiller-nmap
commented
Jan 12, 2015
|
Regarding the 2x as many packets: A dropped probe results in an increased number of retries. Since most ports are closed, this means most ports will get an extra retry. I'm seeing anywhere between 1 and 3 extra retries for the system-libpcap, which if the default is 1 retry, means between 1.5 and 2.5 times as many packets sent. Still no clue as to why it's happening, though. |
dmiller-nmap
commented
Jan 13, 2015
|
Ok, I'm not sure why packets are being dropped: maybe that's a bug on our end. But I do see a solid reproducible difference between the two libpcaps in terms of time taken to get one packet. Command to reproduce: Within readip_pcap, we call pcap_select (from libnetutil) to wait for a pcap fd to be available for reading. With our included libpcap, select returns almost immediately, since a packet is available on the pcap fd. With the system libpcap, it waits the entire timeout (1 second for the first packet at least) before returning. The receive time on the packet is the same, so there's no difference in how fast the packet is processed; the select call is the only thing delaying things. I don't know if this is related, but just above the pcap_select call in readip_pcap, we try to do a non-blocking read by doing pcap_setnonblock followed by pcap_next. But the man page for pcap_setnonblock says that pcap_next "will not work in non-blocking mode." It looks like we should be able to eliminate that whole code block, but I don't think it will affect this issue. |
pushed a commit
to berdario/dotfiles
that referenced
this issue
Apr 11, 2015
dmiller-nmap
commented
Apr 27, 2015
|
Ok, I've got good news and bad news, but I'm not sure which is which. First, the difference between our included libpcap 1.5.3 and the system one is the result of a bug in our version. We introduced a configure option to turn off packet ring capture support for some 2.6 kernels that can't produce a good 32-bit binary. This is implemented as a preprocessor macro, Second, I believe the problem is related to this libpcap issue: the-tcpdump-group/libpcap#335. Note: related, but not identical. The "fix" for that issue is already in libpcap 1.5.3, so we have it. There's a couple related changes to the Linux kernel this year that address the deficiency (one linked from this one: torvalds/linux@41a50d6) |
dmiller-nmap
added this to the
Release codename Auxesis milestone
Apr 29, 2015
pushed a commit
that referenced
this issue
May 1, 2015
dmiller-nmap
commented
May 21, 2015
|
A few final notes on this issue:
--- a/tcpip.cc
+++ b/tcpip.cc
@@ -1710,6 +1710,9 @@ char *readip_pcap(pcap_t *pd, unsigned int *len, long to_usec,
if (p == NULL) {
/* Nonblocking pcap_next didn't get anything. */
+ if (to_usec < 200000 && pcap_select(pd, to_usec) > 0)
+ p = (char *) pcap_next(pd, &head);
+ else
if (pcap_select(pd, to_usec) == 0)
timedout = 1;
else
Given that we have these workarounds, and the bug is demonstrated to be in the Linux kernel code, not in Nmap or libpcap, I am removing the release milestone. I will leave the bug open until either several major distros backport the kernel fix or we find a suitable workaround. |
dmiller-nmap
removed this from the
Release codename Auxesis milestone
May 21, 2015
dmiller-nmap
referenced this issue
Jun 13, 2015
Closed
High latency localhost scanning (Nmap 6.49BETA1) #153
nnposter
commented
Jul 7, 2015
|
FWIW I have experimented with downgrading to TPACKET_V2, instead of disabling the packet ring. The downgrade does rectify the issue but in my light testing I have not noticed any material performance advantages. Here is the corresponding patch if anybody cares for it.
|
pushed a commit
that referenced
this issue
Sep 15, 2015
p-l-
referenced this issue
in cea-sec/ivre
Sep 22, 2015
Merged
Docker/client: update Bro version + get "official" Nmap dev version #157
pr0letariat
commented
Nov 23, 2015
|
Is this fixed in Nmap 7? |
added a commit
to qha/nmap
that referenced
this issue
Dec 16, 2015
mpontillo
commented
Sep 14, 2016
•
|
Cross-posting here from the related Launchpad issue. Inspired by the flow-disruptor workaround, I did a proof-of-concept nmap workaround as follows:
Obviously, this is nowhere near production-ready code, but I wanted to convince myself that the This caused the scan of a single host (using an Ubuntu 16.04 "Xenial" host running kernel 4.4.0) to go from taking ~45 seconds to ~5 seconds. For the record, the test case I used was: |
dmiller-nmap
commented
Sep 14, 2016
|
@pontillo Thanks for notifying us! I'd like to play around with immediate mode a bit more to see how it could best work for us, but for now I'd settle for reproducing the original bug on a >3.19 kernel or at least fully describing and isolating it. Can you provide the output of |
mpontillo
commented
Sep 15, 2016
•
|
Sure; below are some additional details. First, here is my
I tested with both the current version of The version packaged with Ubuntu (which, after running
With that version, I first saw the symptom: long scan times, and messages like the following printed to the console:
I saw the same issue in the
The output from this version was normal, such as:
|
nnposter commentedDec 31, 2014
Nmap compiled on Ubuntu 14.04 with the shared instance of libpcap is reporting lost packets, which in turn significantly impacts performance and quality of results. However, simultaneously running Wireshark on the same host does see them. The same issue is not experienced when compiled with the included instance of libpcap.
Details are available at http://seclists.org/nmap-dev/2014/q2/538
Possibly related:
http://seclists.org/nmap-dev/2014/q2/548
http://seclists.org/nmap-dev/2014/q2/341