Skip to content
Info disclosure Write-up Intermediate

Readline crime: exploiting a SUID logic bug

A logic bug in the readline library causes it to print parts of the input file when parsing errors occur, and because the SUID binary chfn uses readline and respects the INPUTRC environment variable, an attacker can set INPUTRC to a sensitive file like an SSH private key and have portions of it printed to the terminal. This allows an attacker to partially read files that the attacker cannot normally access, potentially leading to lateral movement if a user's private key is stored in a known location.

roddux Follow

Published on blog.trailofbits.com

I discovered a logic bug in the readline dependency that partially reveals file information when parsing the file specified in the INPUTRC environment variable. This could allow attackers to move laterally on a box where sshd is running, a given user is able to login, and the user’s private key is stored in a known…

roddux, on blog.trailofbits.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely, readline does not account for being used in a privileged context and prints parts of the input file in error messages, which leaks information when the file is sensitive.

Impact

An attacker could partially read files they cannot normally access, such as SSH private keys, potentially enabling lateral movement, but only on systems where chfn is SUID and uses readline, and the impact is limited because only certain lines are leaked and many distributions are unaffected.

What the attacker needed

Chfn is SUID and uses readline; attacker can set INPUTRC environment variable; target file contains lines matching leak conditions

The fix

The bug was fixed by removing readline support from chfn in util-linux.

How it was found

  1. Set the INPUTRC environment variable to point to a sensitive file such as /etc/shadow.
  2. Run the chfn command, which uses readline and respects INPUTRC.
  3. Observe that readline prints an error message containing part of the file's content.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

Some programs run with extra privileges (SUID) so they can do tasks normal users cannot. One such program, chfn, uses a library called readline to handle input, and readline reads a file specified by an environment variable called INPUTRC. If that file contains lines that readline cannot understand, it prints an error message that includes part of the line, so by pointing INPUTRC at a secret file like an SSH private key, an attacker can make the program reveal pieces of that file.

What is Info disclosure?

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.

Similar reports

View all

Same bug class and techniques, clearest first.

Information disclosure

The lesson behind this report.

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.