Skip to content

Fix abort() calls when importing malformed SSH keys#12821

Open
stoeckmann wants to merge 2 commits into
keepassxreboot:developfrom
stoeckmann:asn1_checks
Open

Fix abort() calls when importing malformed SSH keys#12821
stoeckmann wants to merge 2 commits into
keepassxreboot:developfrom
stoeckmann:asn1_checks

Conversation

@stoeckmann
Copy link
Copy Markdown
Contributor

The ASN.1 parser code lacks some error checking, which leads to issues if the parser encounters incomplete keys. Also, if an integer is denoted to be around 2 GB in size, the subsequent array resizing leads to an abort() call within Qt 5, shutting down KeePassXC.

The fix includes adding all missing error checks and introducing a length limit of 10 MB for an integer. It is highly unlikely that this limit will ever be reached. Also, 1024 * 1024 * 10 is already used as "artificial" limit within KeePassXC, in case someone wonders where this magic value comes from.

Testing strategy

I have added a unit test, but it can be reproduced with KeePassXC this way:

  1. Enable SSH Agent
  2. Create poc.txt with the following content
-----BEGIN RSA PRIVATE KEY-----
MAACAQAChH////8=
-----END RSA PRIVATE KEY-----
  1. Edit or create an entry
  2. Try to add "external file" by choosing poc.txt
  3. KeePassXC shuts down

Type of change

  • ✅ Bug fix (non-breaking change that fixes an issue)
  • ✅ Refactor (significant modification to existing code)

Comment thread src/sshagent/ASN1Key.cpp Outdated
Comment on lines +31 to +33
stream.read(tag);
if (!stream.read(tag)) {
return false;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if this would be more clearly implemented as a preprocessor define: VALIDATE_RETURN(stream.read(tag))

#define VALIDATE_RETURN(call) if (!call) { return false; }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with that. Adjusted.

I/O operations might fail, so test if they succeed.

While at it, use newly introduced VALIDATE_RETURN for
parsePrivateHeader as well.
Values around 2 GB lead to abort() calls within Qt 5.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants