Background

russh is a low-level, asynchronous SSH 2.0 client and server library for Rust, built on the Tokio runtime. Other Rust programs embed it when they need SSH. It also includes an implementation of the SSH agent protocol.

An SSH agent is a background program that holds a user’s private keys in memory so that they do not have to type a passphrase for every connection. Clients add a key with an “add identity” request. The request can include constraints, extra conditions such as “remove this key after 10 minutes” (the command-line ssh-add -t). Agents can also be forwarded to remote machines, so a program on a remote server may be able to talk to the agent over the SSH connection. russh clients accept a server’s agent-forwarding channel (auth-agent@openssh.com) by default.

Terms used below:

  • Task is a lightweight unit of concurrent work in Rust’s tokio async runtime. Each one uses memory and is tracked by the scheduler.
  • Amplification is when a small input forces a much larger amount of work or memory use.
  • Lifetime constraint is the agent request field (SSH_AGENT_CONSTRAIN_LIFETIME) that carries the key’s expiry time in seconds.

Summary

A constrained add-key request can contain many lifetime records, and the agent server creates a separate sleeping task for each one. Every task retains key data and a timer. There is no per-key task limit, and a later decoding failure does not cancel work already spawned.

The proof of concept converted about 10.2 MiB of agent traffic into roughly 2.1 million tasks and a memory increase of about 1.4 GiB. Comparable traffic sent as unconstrained add-key requests produced little growth. The expensive behavior comes from processing constraints, not from the volume of key material alone.

How the Vulnerability Works

A request to an SSH agent is a list of bytes that the agent decodes step by step. A lifetime constraint takes five bytes, a one-byte type and a four-byte number of seconds. The only limit on how many constraints one request can carry is the size of the whole message, which the agent caps at 256 KiB. That is room for about 52,000 records.

russh handled each constraint the moment it was decoded. For every lifetime record, it cloned the key’s data and started a new background task that sleeps for the stated number of seconds and then deletes the key. A single request can repeat the five-byte record tens of thousands of times, and each repeat starts its own task:

add-key request:   [key data] [lifetime 3600] [lifetime 3600] [lifetime 3600] ... (about 52,000 per request)
agent behaviour:   spawn task + clone key  ->  spawn task + clone key  ->  spawn task + clone key ...

Each task sleeps, and the duration is a 32-bit number of seconds, so the attacker can make it last up to about 136 years. Each also holds its own copy of the key. In the measurement, about 10 MiB of agent traffic produced about 2.1 million tasks and about 1.4 GiB of extra memory. Sending the same amount of data as plain add-key requests with no constraints barely changed memory use, so the cost comes from the constraint handling and not from the volume of the data.

Two further details keep the damage in place. Adding the same key again does not cancel the old tasks. And the decoder starts these tasks before it has accepted the whole request, so if a later constraint is invalid and the request is rejected, the tasks that were already created stay alive.

The attacker only needs to be able to talk to the agent, for example as a process on the same machine with access to its socket, or through a forwarded agent connection. The impact is availability: the agent process slows down or runs out of memory. This is uncontrolled resource allocation (CWE-770). The fix is to validate the full request first and to limit or reject duplicate lifetime constraints.

Prerequisites

The attacker must be able to speak the agent protocol to a russh-based agent. This can be a local process with access to the agent socket, or a remote SSH server reached through an agent-forwarding arrangement.

The issue is in the agent implementation. Network access to an unrelated public SSH listener does not establish access to this path. The deployment must provide a route to the affected agent protocol handler.

Attack Path

Attack route
Attacker routeMitigationCtrl + scroll to zoom
  1. START
    Peer can reach a russh agent
  2. STEP 01
    Send many lifetime constraints on one key

    Each small record otherwise creates another timer task retaining key data.

    MITIGATION Reject duplicate lifetime constraints

  3. STEP 02
    Decoder schedules work before validation completes

    MITIGATION Validate the full request before scheduling tasks

  4. STEP 03
    Repeat constrained add-key requests
  5. STEP 04
    Agent memory and task count grow

Root Cause

The decoder handles each SSH_AGENT_CONSTRAIN_LIFETIME record as it encounters it. That record contains a one-byte type and a four-byte lifetime. The handler clones key data and calls tokio::spawn to sleep for the declared lifetime before removing the key.

One request can repeat this five-byte record tens of thousands of times. Timers can remain resident for very long intervals because the lifetime is a 32-bit number of seconds. Reusing a key does not remove tasks created by earlier records.

Scheduling also occurs before the full request has been accepted. A later invalid constraint can reject the request while earlier tasks remain alive. A message-size limit alone does not enforce a bounded number of expiry tasks per key.

Validation

The proof of concept ran a real russh agent server at revision efa9a03 (v0.63.3 plus ten later commits). It compared unconstrained requests with requests containing about 52,000 lifetime records each.

TrafficIntended resource behaviorRecorded result
Comparable volume of unconstrained addsBounded key stateAbout 268 KiB memory increase
Forty constrained requestsBounded timers per keyAbout 1,447,856 KiB memory increase
Repeated lifetime recordsReject or consolidate duplicate expiryRoughly 2.1 million timer tasks scheduled

The server acknowledged requests while memory grew. The task estimate follows the number of processed records. The memory figures were measured in the lab and do not establish a fixed multiplier across runtimes or allocators.

Impact

A reachable agent peer can exhaust memory and scheduler resources, disrupting the user’s key agent. This resource-exhaustion path did not establish key disclosure, unauthorized signatures or modification of unrelated data.

Overview follows the published GitHub rating of 4.3 under CVSS v3.1 (CVSS:3.1/AV:A/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L). The attacker must be able to reach the agent, so arbitrary internet clients cannot trigger this against a typical deployment.

Remediation

Upgrade to 0.64.1 or later. The linked patch rejects a second lifetime constraint and defers the expiry task until constraint parsing has succeeded. A request can no longer schedule one independent task for each duplicate lifetime record.

Restrict agent-socket access and forwarding to trusted peers while upgrading. Regression tests should cover duplicate constraints, failures after a valid constraint and normal expiry. Rejected requests should leave neither inserted keys nor cleanup work behind.

References