NetworkTracker leaks a connectTrackerTimes node per outbound TCP connection, and PurgeStale never runs on busy hosts
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 55/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- c
- Bereich
- networking
Rechercherichtung
Start by reading networkTracker.cpp, especially NetworkTracker::PurgeStale and NetworkTracker::SeenConnect; the issue identifies both faulty paths and includes a proposed fix. Build the project and run a reproduction with a NetworkConnect rule and repeated loopback TCP connections. Done when the tracker removes established connections using the stored timestamp and stale entries are swept on busy hosts; the issue says the proposed patch has not been built or tested.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Version: sysmonforlinux 1.5.3 (networkTracker.cpp is unchanged on main at b2f11cc07a). Seen on Ubuntu 22.04 (kernel 5.15) and Ubuntu with kernel 7.0.
Symptom
The sysmon heap grows linearly with the host's rate of outbound TCP connections and is only freed by a restart. On a 4 GB nginx reverse proxy making about 11 outbound connections per second, the sysmon heap (VmData) reached 2.6 GB after 36 days (about 70 MB/day), leaving the host with 60 MB available. Hosts with few outbound connections grow only a few MB per day, which hides the bug.
Any configuration with a NetworkConnect rule triggers it, because processNetworkEvent feeds the tracker before rule matching. An include rule that matches only wget/curl, plus a 127. exclude, still leaks on every connection.
Reproduction
With any NetworkConnect include rule loaded, open 20,000 loopback TCP connections (connect, then close). The sysmon RSS grows by about 2 MB (roughly 100 bytes per connection) and never shrinks.
Evidence
A sample of the long-running process's heap was almost entirely 64-byte malloc chunks, each a red-black tree node whose value is (LONGLONG time in 100 ns ticks, kernel socket pointer). That is the node layout of std::map<LONGLONG, const void *>, i.e. connectTrackerTimes. The heap held about 42 million of them, with timestamps three weeks old, although staleDuration is 15 minutes.
Cause
Two bugs in networkTracker.cpp:
-
Wrong erase key on
TCP_ESTABLISHED. InSeenConnect, the branch for an already-tracked socket reachingTCP_ESTABLISHEDcallsconnectTrackerTimes.erase(event->m_EventTime.QuadPart). That is the time of the ESTABLISHED event, but the entry was inserted under the time of the earlier SYN_SENT event, which is stored inret.first->second.second. The erase misses, so every successful outbound connection orphans oneconnectTrackerTimesnode. TheTCP_CLOSEbranch already erases by the stored time correctly. -
PurgeStalenever runs on a busy host.PurgeStalerefreshestimeLastCheckedat the end of every call, not only after a sweep. It is called on every connect and accept, socurTime - timeLastChecked > checkDuration(60 s) holds only after a full minute with no TCP connect or accept events at all. On a server that never happens, so the 15-minute stale sweep that would collect the orphans never runs. This also stopsacceptTrackerTimesfrom ever being swept.
Proposed fix
--- a/networkTracker.cpp
+++ b/networkTracker.cpp
@@ void NetworkTracker::PurgeStale()
break; // as this is an ordered map, we have exhausted all stale items
}
}
- }
-
- GetSystemTimeAsLargeInteger(&timeLastChecked);
+ timeLastChecked = curTime;
+ }
}
@@ pid_t NetworkTracker::SeenConnect(PSYSMON_EVENT_HEADER eventHdr)
if (event->m_NewState == TCP_ESTABLISHED) {
// connection is established, so remove it
- connectTracker.erase(event->m_SockId);
- connectTrackerTimes.erase(event->m_EventTime.QuadPart);
+ connectTrackerTimes.erase(ret.first->second.second);
+ connectTracker.erase(ret.first);
}
The first hunk lets the periodic sweep run as intended, which also acts as a backstop for any other path that leaves entries behind. The second removes the orphan at its source. The patch has not been built or tested yet.
Workaround
Cap the service with a systemd drop-in, for example MemoryMax=512M with the unit's existing Restart=on-failure, plus StartLimitIntervalSec=0. The restart limit matters because a restarted sysmon can fail with libbpf: failed to mmap perf buffer: -ENOMEM on a fragmented host and would otherwise give up after five attempts.
Possibly related: #211 (memory growth, though its Valgrind output points at ProcessCache).
- Vorherrschende Sprache
- C
- Sterne
- 2.2k
- Forks
- 224
- Ø Merge
- 4 Std. 50 Min.
- Gemergte PRs (30 T.)
- 3
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus microsoft/Sysmon-Linux
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 68/100
microsoft/Sysmon-Linux#253 ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 72/100
microsoft/Sysmon-Linux#252 ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 12/100
microsoft/Sysmon-Linux#246 · 3 Kommentare ·
-
Sysmon service executable remains `(deleted)` after restart, causing repeated needrestart restarts and systemd start-limit-hitEvtl. wieder frei @MarioHewardt hat das vor 31 Tagen übernommen, und es ist kein Pull Request offen. Offen
microsoft/Sysmon-Linux#244 · 1 zugewiesene Person ·
-
ProcessTerminate events intermittently report an unrelated user's UID instead of the terminating process's UIDEvtl. vergeben @MarioHewardt hat das vor 111 Tagen übernommen. Offen
microsoft/Sysmon-Linux#238 · 1 zugewiesene Person ·
Alle Issues in microsoft/Sysmon-Linux
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
ly05010419/MacNativeGames#2001 ·
Maintainer antworten meist innerhalb von 1 Tag
-
area/docdb kind/bug priority/medium status/awaiting-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
yugabyte/yugabyte-db#37426 ·
Maintainer antworten meist innerhalb von 1 Tag
-
area/documentation
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
obsproject/obs-studio#14184 ·
Maintainer antworten meist innerhalb von 1 Tag
-
extension-modules type-bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
30-minutes algorithm any-language beginner-friendly c community cpp csharp data-structures go good first issue hacktoberfest help wanted kotlin learning leetcode php ruby rust swift
Schwierigkeit 2/5 Unter einer Stunde Anfängerfreundlichkeit 85/100
Huerte/algo-solutions-python#211 ·
Maintainer antworten meist innerhalb von 1 Tag