PuTTY vulnerability vuln-ech-overflow

Home | Licence | FAQ | Docs | Download | Keys | Links
Mirrors | Updates | Feedback | Changes | Wishlist | Team

summary: Vulnerability: integer overflow and buffer underrun in terminal emulator's ECH handling
class: vulnerability: This is a security vulnerability.
difficulty: fun: Just needs tuits, and not many of them.
priority: high: This should be fixed in the next release.
absent-in: 0.53b r2425 ea5be2db381206798f688cf2bac464a24a2856d9
present-in: 8de5682450393513f25d1a231677f7d866c8d9d4 r2426 0.54 0.65
fixed-in: 6056396f77cafc7e40da4d09f1d6212408dcb065 e3fe709a8f6a633647088e9ed7264be5fb740426 2015-11-08 0.66

Versions of PuTTY and pterm between 0.54 and 0.65 inclusive have a potentially memory-corrupting integer overflow in the handling of the ECH (erase characters) control sequence in the terminal emulator.

To exploit a vulnerability in the terminal emulator, an attacker must be able to insert a carefully crafted escape sequence into the terminal stream. For a PuTTY SSH session, this must be before encryption, so the attacker likely needs access to the server you're connecting to. For instance, an attacker on a multi-user machine that you connect to could trick you into running cat on a file they control containing a malicious escape sequence. (Unix write(1) is not a vector for this, if implemented correctly.)

Only PuTTY, PuTTYtel, and pterm are affected; other PuTTY tools do not include the terminal emulator, so cannot be exploited this way.

The purpose of ECH is to erase multiple characters within a single line. To this end, it includes a numeric parameter to specify the number of characters to be erased. PuTTY accumulates this one digit at a time in an integer variable. As part of the processing of ECH, the check_boundary function checks whether the start or end of the erased range falls in the middle of a double-width character (such as a kanji ideograph) so that it can ensure that the whole character is erased. Each character cell in the live terminal is held as a structure containing among other things the character code and a word of attributes. A double-width character is recorded by having a special value called UCSWIDE as the character code in the second cell, and when check_boundary detects that value, it resets the character code of both cells to a fixed value and copies the attributes from the left one to the right one.

The vulnerability arises because PuTTY uses signed integer variables to hold the number of characters to be erased and doesn't adequately check for overflow. This means that by passing a very large parameter to ECH, an attacker could cause check_boundary to inspect memory outside the terminal buffer. Were it to find UCSWIDE there, it would corrupt some nearby memory. This might be exploitable if the attacker could arrange for UCSWIDE to be in memory somewhere near a sensitive data structure.

This bug was found with the help of American Fuzzy Lop and has been assigned CVE ID CVE-2015-5309.

If you want to comment on this web site, see the Feedback page.
Audit trail for this vulnerability.
(last revision of this bug record was at 2015-11-07 13:07:39 +0000)