New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible regression in select() behaviour between 1.9.0 and 1.9.1 #860
Comments
A quick look at the code seems to indicate that you're setting the timeout to 0:
To quote the pcap(3PCAP) man page:
So, if a program is not using non-blocking mode and I suspect that, if the program is using non-blocking mode and Commit 2b16559 was:
That change fixed a bug wherein setting the timeout to 0 did not cause the documented behavior to occur. I can't find the email/GitHub issue/whatever where the problem was reported, but I do remember it having been reported. I.e., somebody was expecting a zero timeout to cause packets not to be delivered until the buffer fills up, or some such behavior, just as happens on, for example, *BSD and macOS, with BPF as the capture mechanism. On systems with BPF, arp-scan turns immediate mode on by directly doing an ioctl to do so; in immediate mode, the timeout is irrelevant, and packets are delivered immediately. (And, at least on macOS, even if I So what arp-scan should do is, if
|
Fix a problem where ctdb_killtcp (almost always) fails to capture packets with --enable-pcap and libpcap ≥ 1.9.1. The problem is due to a gradual change in libpcap semantics when using pcap_get_selectable_fd(3PCAP) to get a file descriptor and then using that file descriptor in non-blocking mode. pcap_set_immediate_mode(3PCAP) says: pcap_set_immediate_mode() sets whether immediate mode should be set on a capture handle when the handle is activated. In immediate mode, packets are always delivered as soon as they arrive, with no buffering. and On Linux, with previous releases of libpcap, capture devices are always in immediate mode; however, in 1.5.0 and later, they are, by default, not in immediate mode, so if pcap_set_immediate_mode() is available, it should be used. However, it wasn't until libpcap commit 2ade7676101366983bd4f86bc039ffd25da8c126 (before libpcap 1.9.1) that it became a requirement to use pcap_set_immediate_mode(), even with a timeout of 0. More explanation in this libpcap issue comment: the-tcpdump-group/libpcap#860 (comment) Do a configure check for pcap_set_immediate_mode() even though it has existed for 10 years. It is easy enough. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15451 Signed-off-by: Martin Schwenke <mschwenke@ddn.com> Reviewed-by: Amitay Isaacs <amitay@gmail.com> Autobuild-User(master): Amitay Isaacs <amitay@samba.org> Autobuild-Date(master): Tue Aug 15 10:53:52 UTC 2023 on atb-devel-224
Fix a problem where ctdb_killtcp (almost always) fails to capture packets with --enable-pcap and libpcap ≥ 1.9.1. The problem is due to a gradual change in libpcap semantics when using pcap_get_selectable_fd(3PCAP) to get a file descriptor and then using that file descriptor in non-blocking mode. pcap_set_immediate_mode(3PCAP) says: pcap_set_immediate_mode() sets whether immediate mode should be set on a capture handle when the handle is activated. In immediate mode, packets are always delivered as soon as they arrive, with no buffering. and On Linux, with previous releases of libpcap, capture devices are always in immediate mode; however, in 1.5.0 and later, they are, by default, not in immediate mode, so if pcap_set_immediate_mode() is available, it should be used. However, it wasn't until libpcap commit 2ade7676101366983bd4f86bc039ffd25da8c126 (before libpcap 1.9.1) that it became a requirement to use pcap_set_immediate_mode(), even with a timeout of 0. More explanation in this libpcap issue comment: the-tcpdump-group/libpcap#860 (comment) Do a configure check for pcap_set_immediate_mode() even though it has existed for 10 years. It is easy enough. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15451 Signed-off-by: Martin Schwenke <mschwenke@ddn.com> Reviewed-by: Amitay Isaacs <amitay@gmail.com> Autobuild-User(master): Amitay Isaacs <amitay@samba.org> Autobuild-Date(master): Tue Aug 15 10:53:52 UTC 2023 on atb-devel-224 (cherry picked from commit dc7b48c) Autobuild-User(v4-17-test): Jule Anger <janger@samba.org> Autobuild-Date(v4-17-test): Tue Aug 29 10:29:56 UTC 2023 on sn-devel-184
Fix a problem where ctdb_killtcp (almost always) fails to capture packets with --enable-pcap and libpcap ≥ 1.9.1. The problem is due to a gradual change in libpcap semantics when using pcap_get_selectable_fd(3PCAP) to get a file descriptor and then using that file descriptor in non-blocking mode. pcap_set_immediate_mode(3PCAP) says: pcap_set_immediate_mode() sets whether immediate mode should be set on a capture handle when the handle is activated. In immediate mode, packets are always delivered as soon as they arrive, with no buffering. and On Linux, with previous releases of libpcap, capture devices are always in immediate mode; however, in 1.5.0 and later, they are, by default, not in immediate mode, so if pcap_set_immediate_mode() is available, it should be used. However, it wasn't until libpcap commit 2ade7676101366983bd4f86bc039ffd25da8c126 (before libpcap 1.9.1) that it became a requirement to use pcap_set_immediate_mode(), even with a timeout of 0. More explanation in this libpcap issue comment: the-tcpdump-group/libpcap#860 (comment) Do a configure check for pcap_set_immediate_mode() even though it has existed for 10 years. It is easy enough. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15451 Signed-off-by: Martin Schwenke <mschwenke@ddn.com> Reviewed-by: Amitay Isaacs <amitay@gmail.com> Autobuild-User(master): Amitay Isaacs <amitay@samba.org> Autobuild-Date(master): Tue Aug 15 10:53:52 UTC 2023 on atb-devel-224 (cherry picked from commit dc7b48c) Autobuild-User(v4-18-test): Jule Anger <janger@samba.org> Autobuild-Date(v4-18-test): Tue Aug 29 12:27:35 UTC 2023 on atb-devel-224
Fix a problem where ctdb_killtcp (almost always) fails to capture packets with --enable-pcap and libpcap ≥ 1.9.1. The problem is due to a gradual change in libpcap semantics when using pcap_get_selectable_fd(3PCAP) to get a file descriptor and then using that file descriptor in non-blocking mode. pcap_set_immediate_mode(3PCAP) says: pcap_set_immediate_mode() sets whether immediate mode should be set on a capture handle when the handle is activated. In immediate mode, packets are always delivered as soon as they arrive, with no buffering. and On Linux, with previous releases of libpcap, capture devices are always in immediate mode; however, in 1.5.0 and later, they are, by default, not in immediate mode, so if pcap_set_immediate_mode() is available, it should be used. However, it wasn't until libpcap commit 2ade7676101366983bd4f86bc039ffd25da8c126 (before libpcap 1.9.1) that it became a requirement to use pcap_set_immediate_mode(), even with a timeout of 0. More explanation in this libpcap issue comment: the-tcpdump-group/libpcap#860 (comment) Do a configure check for pcap_set_immediate_mode() even though it has existed for 10 years. It is easy enough. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15451 Signed-off-by: Martin Schwenke <mschwenke@ddn.com> Reviewed-by: Amitay Isaacs <amitay@gmail.com> Autobuild-User(master): Amitay Isaacs <amitay@samba.org> Autobuild-Date(master): Tue Aug 15 10:53:52 UTC 2023 on atb-devel-224 (cherry picked from commit dc7b48c) Autobuild-User(v4-19-test): Jule Anger <janger@samba.org> Autobuild-Date(v4-19-test): Tue Aug 29 09:34:35 UTC 2023 on atb-devel-224
I beleive there may be a regression between libpap versions 1.9.0 and 1.9.1 when using select() on a file descriptor returned by pcap_get_selectable_fd().
Operating system: Linux (problem first reported on Arch Linux 2019.10.01 x64, reproduced on Debian 10 "Buster" x64)
Compiler: gcc
Summary of problem:
arp-scan ( https://github.com/royhills/arp-scan ) uses libpcap to receive ARP response packets. The arp-scan pcap code has worked up to and including libpcap 1.9.0, but fails on libpcap 1.9.1.
No errors are reported, but no ARP response packets are processed. The statistics from pcap_stats() are non-zero, indicating that packets are matching the filter expression.
The key pcap API calls go like this (much simplified):
pcap_handle = pcap_create(if_name, errbuf)
pcap_fd=pcap_get_selectable_fd(pcap_handle)
LOOP:
n = select(pcap_fd+1, &readset, NULL, NULL, &to)
if (n > 0)
pcap_dispatch(pcap_handle, -1, callback, NULL)
With libpcap 1.9.1, select() is always returning zero indicating nothing ready to read on pcap_fd, so pcap_dispatch() is never called.
The problem is also present on the latest git commit (ac945a4).
Running git bisect between tags/libpcap-1.9.0 and tags/libpcap-1.9.1 gives the following:
See also the arp-scan issue at: royhills/arp-scan#42
To reproduce:
Run the latest version of arp-scan. A successful run will be able to recieve and display the ARP response packets like this:
A failing run will receive packets but display nothing like this:
The text was updated successfully, but these errors were encountered: