opensnitch icon indicating copy to clipboard operation
opensnitch copied to clipboard

Opensnitch gets confused when ping running at the same time as browsing with Firefox

Open jspiros opened this issue 3 years ago • 8 comments

Using the latest 0.6.0-rc.5-1 release Debian package on a Debian testing/unstable system. Had issues with earlier versions and NFS due to not having eBPF module, but now that it bundles it, NFS works well, so I assume eBPF is working.

Today I noticed some weird sluggishness in Firefox that I intuited may be network issues, so I started a test ping to google.com in a terminal window while I continued browsing. (The ping did reveal some packet loss, I need to check the switches between me and my router as the router shows no dropped packets).

As I loaded up printables.com in Firefox, I got an opensnitch popup relating to the ping google.com process but it seemed to think ping was trying to send ICMP to a printables.com domain. Indeed, even now as I loaded the page to report this issue, I got a similar popup, again relating to the still-running ping command, but some unrelated IP that I presume has to do with GitHub.

So, in short, it seems Opensnitch is getting confused. I didn't react quickly enough to screenshot the popups but I found the event log portion where the printables event occured.

(The screenshot makes the UI look broken, I think that's just because I'm using qt5ct under Cinnamon to try and theme Qt sensibly, and I clearly have failed. Other Qt programs are having similar issues, it's not Opensnitch's fault, I just haven't gotten around to fixing it yet.)

Screenshot from 2023-05-04 01-03-54

jspiros avatar May 04 '23 05:05 jspiros

Oh, and if it helps, I think in both the case of Printables.com and GitHub, I had to authenticate with both sites, and the popup occurred around when I was authenticating, either during or right after. It wouldn't surprise me if something those sites are doing while authenticating is related to Opensnitch's confusion.

jspiros avatar May 04 '23 06:05 jspiros

Hi @jspiros ,

Thank you for reporting this issue. Please, set LogLevel to DEBUG under Preferences -> Nodes, and see if there're ebpf events in the log file /var/log/opensnitchd.log (specially [eBPF exec event], but also [ebpf conn]).

Do you usually suspend your computer?

Given the description of the problem, it could be caused by:

  1. a problem with the cache of domains+CNAMEs, where multiple domains are hosted on the same IP and depending on the rules it could cause this behavior (allow->wget to www.github.developerdan.com (185.199.109.153) , but we return from cache lightswitch05.github.io for 185.199.109.153, so the rule doesn't match and we show a pop-up).
  2. ebpf not working as expected, we fallback to proc and we don't return the correct process. But given the screenshot doesn't seem to be the case.

None of the both possible causes really explains this behaviour. printables.com seems to be hosted on cloudflare, while google on google and github on .. github.

Anyway, if you manage to reproduce it again, I'd love the read the debug logs. It's a pity that we don't have right now a way of displaying all the details of a connection (I'll add it ASAP).

gustavo-iniguez-goya avatar May 04 '23 23:05 gustavo-iniguez-goya

I never suspend my computer. I am able to reproduce this most of the time, even between reboots. I've attached the section of the debug log that starts when I start the ping, and ends when I deny the false ping to printables.com. opensnitchd.log

jspiros avatar May 06 '23 09:05 jspiros

thank you!

This is what's happenning:

Firefox tries to load media.printables.com, and first it tries to resolve the domain:

[2023-05-06 09:29:50] ^[[100m DBG  ✔ /usr/lib/firefox/firefox -> media.printables.com:53 (allow-always-simple-192-168-0-0-16)
[2023-05-06 09:29:50] ^[[100m DBG  new connection udp => 37670:192.168.0.6 -> 192.168.254.1 (media.printables.com):53 uid: 1000
[2023-05-06 09:29:50] ^[[100m DBG  [ebpf conn] in cache: udp37670192.168.0.6192.168.254.153, 2720 -> /usr/lib/firefox/firefox
[2023-05-06 09:29:50] ^[[100m DBG  ✔ /usr/lib/firefox/firefox -> media.printables.com:53 (allow-always-simple-192-168-0-0-16)
[2023-05-06 09:29:50] ^[[100m DBG  New DNS record: 172.67.5.123 -> media.printables.com

The query returns 172.67.5.123 for media.printables.com, which is correct.

Then it establishes a udp connection (quic?) to the domain:


[2023-05-06 09:29:50] ^[[100m DBG  new connection udp => 47809:192.168.0.6 -> 172.67.5.123 (media.printables.com):443 uid: 1000
[2023-05-06 09:29:50] ^[[100m DBG  [ebpf conn] not in cache, but in execEvents: udp47809192.168.0.6172.67.5.123443, 2720 -> /usr/lib/firefox/firefox
[2023-05-06 09:29:50] ^[[100m DBG  [ebpf conn] adding item to cache: udp47809192.168.0.6172.67.5.123443
[2023-05-06 09:29:50] ^[[100m DBG  ✔ /usr/lib/firefox/firefox -> media.printables.com:443 (allow-always-list-usr-lib-firefox-firefox-443)

good.

Now the strange behaviour is that just after the firefox 443 connection, there's an ICMP to 172.67.5.123: [2023-05-06 09:29:51] ^[[100m DBG new connection icmp => 0:192.168.0.6 -> 172.67.5.123 (media.printables.com):0 uid: 4294967295

When we receive a connection that's not a DNS query, we look in the domains cache to see if the IP has a domain, then we associate it, hence the 172.67.5.123 (media.printables.com):.

Then we proceed to lookup the process that initiated that ICMP:

[2023-05-06 09:29:51] ^[[100m DBG  new connection icmp => 0:192.168.0.6 -> 172.67.5.123 (media.printables.com):0 uid: 4294967295
[2023-05-06 09:29:51] ^[[100m DBG  [0/1] outgoing connection uid: 1000, 0:192.168.0.6 -> 172.67.5.123:0 || netlink response: 1:0.0.0.0 -> 0.0.0.0:0 inode: 45055 - loopback: f$
[2023-05-06 09:29:51] ^[[100m DBG  GetSocketInfo() invalid: 1:0.0.0.0 -> 0.0.0.0:0
[2023-05-06 09:29:51] ^[[100m DBG  netlink socket not found, adding entry:  0:192.168.0.6 -> 172.67.5.123:0 || 1:0.0.0.0 -> 0.0.0.0:0 inode: 45055 state: close
[2023-05-06 09:29:51] ^[[100m DBG  [0/1] outgoing connection uid: 1000, 0:192.168.0.6 -> 172.67.5.123:0 || netlink response: 1:0.0.0.0 -> 0.0.0.0:0 inode: 45055 - loopback: f$
[2023-05-06 09:29:51] ^[[100m DBG  GetSocketInfo() invalid: 1:0.0.0.0 -> 0.0.0.0:0
[2023-05-06 09:29:51] ^[[100m DBG  netlink socket not found, adding entry:  0:192.168.0.6 -> 172.67.5.123:0 || 1:0.0.0.0 -> 0.0.0.0:0 inode: 45055 state: close
[2023-05-06 09:29:51] ^[[100m DBG  new pid lookup took (4390): 4.667572ms
[2023-05-06 09:29:51] ^[[100m DBG  [0] PID found 4390 [45055]

The ICMP connection was not found via ebpf (no [ebpf] traces), so we fallback to procfs, dumping the inodes to see if any of them matched the properties of the connection.

The left side of || is what we expect, and the right side what the kernel dumps filtering by source port. We didn't get any valid inode for the connection (GetSocketInfo() invalid: 1:0.0.0.0 -> 0.0.0.0:0) but as a last resort we added the entry in the hope to find the PID.

We found the PID by that inode, but unfortunately it's the PID of ping instead of firefox's.

soo, one solution could be intercept ICMP packets at ebpf level. A workaround for this particular problem would be to allow ICMP, adding a firewall rule to nftables (either using the GUI or just using nft).

gustavo-iniguez-goya avatar May 06 '23 15:05 gustavo-iniguez-goya

Very interesting. I wonder if/why Firefox is sending the ICMP packets. On my macOS machine (where I use Little Snitch), I never see anything related to Firefox sending ICMP for these sites (and I think it supports catching ICMP; at least, it allows the creation of rules for ICMP, TCP, UDP, IRTP, and ICMPv6, so I assume so), so maybe it's something specific to my Linux machine and not even Firefox itself.

Anyway, I hope OpenSnitch will eventually use eBPF for ICMP too so it doesn't get confused (and I can be more sure about what process is doing it). For now, it's not that big of a deal, though I prefer some alert to none so I'm not going to create a rule as a workaround.

jspiros avatar May 07 '23 09:05 jspiros

most likely ICMP is from firefox captive portal, try disabling it and see if it fixes the issue:

https://support.mozilla.org/en-US/kb/how-stop-firefox-making-automatic-connections#w_network-detection

swx-1 avatar May 28 '23 07:05 swx-1

The reason of this behaviour was explained in detail here: https://github.com/evilsocket/opensnitch/discussions/946#discussioncomment-6035934

Sorry for not update this issue with the link.

gustavo-iniguez-goya avatar Jul 23 '23 15:07 gustavo-iniguez-goya

@gustavo-iniguez-goya analysis above already pinpointed where the misattribution happens (procfs fallback picks the inode of an unrelated raw ICMP socket). I can confirm it — misattributed to /usr/bin/vmnet-natd in my case.

Environment:

  • opensnitchd: 1.8.0 (built from https://build.opensuse.org/package/show/home:jloehel:security/opensnitch, carries several additional patches)
  • OS: openSUSE Tumbleweed
  • Kernel: 7.1.8-1-default
  • process monitor: ebpf

Reproducer:

[!NOTE]
reliable on my machine, not yet tested elsewhere

Open a site in Chromium (google.com, linkedin.com), then close the browser. Chromium tears down its UDP sockets on close before the in-flight server replies arrive; the kernel answers each reply with ICMP type 3 code 3 (port unreachable).

1. The ICMP is generated by the kernel — bpftrace on kprobe:__icmp_send during the reproducer:

14:01:06 type=3 code=3 offender_src=142.251.155.119 offender_dst=192.168.10.135 comm=swapper/6

        __icmp_send+5
        udp_rcv+1093
        ip_protocol_deliver_rcu+195
        ip_local_deliver_finish+133
        __netif_receive_skb_one_core+133
        process_backlog+152
        __napi_poll+62
        net_rx_action+780
        handle_softirqs+209
        __irq_exit_rcu+161
        common_interrupt+133
        asm_common_interrupt+38
        cpuidle_enter_state+187
        cpuidle_enter+49
        do_idle+343
        cpu_startup_entry+41
        start_secondary+281
        common_startup_64+318

No process context — plain udp_rcv → __icmp_send (UDP datagram arrives, no socket listening anymore). strace -f -e trace=%network on the blamed process shows no syscalls during the event.

2. The trigger on the wire (opensnitchd stopped for this capture) Chromium sends its final datagrams on closing (flow 49107) and tears down the socket immediately:

16:37:00.967296 IP (tos 0x0, ttl 64, id 1223, offset 0, flags [DF], proto UDP (17), length 77)
    192.168.10.135.49107 > 142.251.151.119.443: [udp sum ok] UDP, length 49

~5 ms later the server's replies arrive — the socket is already gone, and the kernel answers each one immediately:

16:37:00.972788 IP (tos 0x0, ttl 56, id 0, offset 0, flags [DF], proto UDP (17), length 237)
    142.251.151.119.443 > 192.168.10.135.49107: [udp sum ok] UDP, length 209
16:37:00.972829 IP (tos 0xc0, ttl 64, id 25261, offset 0, flags [none], proto ICMP (1), length 265)
    192.168.10.135 > 142.251.151.119: ICMP 192.168.10.135 udp port 49107 unreachable, length 245
	IP (tos 0x0, ttl 56, id 0, offset 0, flags [DF], proto UDP (17), length 237)
    142.251.151.119.443 > 192.168.10.135.49107: [udp sum ok] UDP, length 209
16:37:00.973621 IP (tos 0x0, ttl 56, id 0, offset 0, flags [DF], proto UDP (17), length 59)
    142.251.151.119.443 > 192.168.10.135.49107: [udp sum ok] UDP, length 31
16:37:00.973626 IP (tos 0xc0, ttl 64, id 25262, offset 0, flags [none], proto ICMP (1), length 87)
    192.168.10.135 > 142.251.151.119: ICMP 192.168.10.135 udp port 49107 unreachable, length 67
	IP (tos 0x0, ttl 56, id 0, offset 0, flags [DF], proto UDP (17), length 59)
    142.251.151.119.443 > 192.168.10.135.49107: [udp sum ok] UDP, length 31

3. opensnitchd attributes this kernel-generated packet to vmnet-natd The debug log of the event; packet UID 0xffffffff, eBPF correctly finds nothing, the raw socket is rejected as invalid, but then got added anyway:

[!NOTE]
unrelated events cut, marked with [...]

new connection icmp => 0:192.168.10.135 -> 142.251.153.119:0 uid: 4294967295, mark: 0
[0/1] outgoing connection uid: 0, 0:192.168.10.135 -> 142.251.153.119:0 || netlink response: 1:0.0.0.0 -> 0.0.0.0:0 inode: 1922052
GetSocketInfo() invalid: 1:0.0.0.0 -> 0.0.0.0:0
netlink socket not found, adding entry:  0:192.168.10.135 -> 142.251.153.119:0 || 1:0.0.0.0 -> 0.0.0.0:0 inode: 1922052 state: close
[ebpf conn] PID not found via eBPF, falling back to proc
[...]
Socket found in known pids 20.029µs, pid: 234384, inode: 1922052, pos: 0, pids in cache: 17
[0] PID found 234384 [1922052]
[...]
✔ /usr/bin/vmnet-natd -> 0:192.168.10.135 => www.google.com (142.251.153.119):0

The blamed process is whatever happens to hold a raw ICMP socket at that moment: with vmware networking stopped and nping --icmp -c 30 --delay 10s 1.1.1.1 idling in the background, opensnitchd attributes the identical event to /usr/bin/nping instead.

Happy to provide more data if necessary

Thanks for that awesome project ❤️

jloehel avatar Aug 26 '26 23:08 jloehel