Process memory
This page is published from the agent repository. Edit on GitHub View source
Fileless payloads (a memfd executed in place, an injected region) leave nothing on disk for a file
scan. sensor-linux-procmem is the mechanism
the YARA memory scan uses to look at a running process: list its mappings and read bytes from them.
It holds no policy. Which regions to read, how much and when is the yara crate's memory module;
the agent adapts the two in memscan.rs.
API
| Function | Reads | Returns |
|---|---|---|
parse_maps_line | one /proc/<pid>/maps line | MapsEntry { start, end, perms, pathname } or MapsError |
parse_maps | a whole maps file | entries and the count of malformed lines |
read_maps | /proc/<pid>/maps | entries and malformed count |
read_memory | /proc/<pid>/mem at start | up to len bytes |
Behaviour
- Untrusted input. The pathname column is whatever the process named its file, including a
memfdname with arbitrary bytes. The maps file is read as bytes and decoded lossily: strict UTF-8 would fail the whole file and let exactly the process being scanned opt out. Pathnames may contain spaces; the parser takes everything after the fifth field. A malformed line is counted, not fatal. - Reads are bounded by the caller's
lenand by what the kernel returns. A short read stops; a hole partway through (a guard page) keeps what was read; an unreadable first byte is an error (the region was unmapped since the maps were read).EINTRis retried. - Permission. The kernel gates
/proc/<pid>/memwithptrace_may_access: same uid and dumpable, orCAP_SYS_PTRACE. Without it the open fails withPermissionDenied, which the scan queue counts as unreadable. Granting the agentCAP_SYS_PTRACEis an operator choice. - On non-Unix targets
read_memoryreturnsUnsupported.
Testing
Unit tests cover maps lines with spaces, deleted files, memfd names (including one named with
bytes that are not UTF-8), anonymous mappings and malformed ranges, and read the test process's own
memory through /proc/self.