Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Implement in-memory encryption for reducing risk of swapping out sensitive information #3055

Closed
wants to merge 1 commit into from

Conversation

phoerious
Copy link
Member

@phoerious phoerious commented Apr 22, 2019

This PR is work in progress and not ready for production yet.
I am targeting this at 2.5, but it won't merge cleanly until release/2.4.2 has been merged back into develop.

Type of change

  • ✅ Refactor (significant modification to existing code)
  • ✅ New feature (non-breaking change which adds functionality)

Testing strategy

Tests are failing at the moment. New tests will be added.

Checklist:

  • ✅ I have read the CONTRIBUTING document. [REQUIRED]
  • ✅ My code follows the code style of this project. [REQUIRED]
  • ✅ All new and existing tests passed. [REQUIRED]
  • ✅ I have compiled and verified my code with -DWITH_ASAN=ON. [REQUIRED]
  • ✅ I have added tests to cover my changes.

@phoerious phoerious added this to the v2.5.0 milestone Apr 22, 2019
@phoerious phoerious force-pushed the feature/memory-protection-v3 branch 4 times, most recently from 1834b55 to ad74e24 Compare April 27, 2019 16:18
@sebast889
Copy link

sebast889 commented Apr 27, 2019

Just a question, is it possible to add in-memory encryption to notes as well? People usually store some sensitive information there as well like backup TOTP codes, account recovery codes, secret question answers, account related information etc.

@phoerious
Copy link
Member Author

Theoretically, we could encrypt everything. It's just a matter of performance. Be aware though, that this kind of encryption is really only to reduce the risk of stuff being swapped out in plaintext.

@sebast889
Copy link

Is there some way you're able to check if performance is still good enough if say you do encrypt everything?

I assume for most people that use KeepassXC they would be willing to give up some performance for this kind of security defense in depth.

@droidmonkey
Copy link
Member

It could certainly be an option under the security settings.

@phoerious
Copy link
Member Author

phoerious commented Apr 28, 2019

KDBX has metadata fields that define which fields to protect by default. We respect those settings, but have no GUI for modifying them.

@droidmonkey droidmonkey reopened this Jun 1, 2019
This reduces the risk of sensitive information being swapped to disk.
It is NOT a guarantee that no sensitive information can be extracted
from the process memory (we have other permission-based countermeasures
for that in place). Passwords and other data still need to be accessed
and shown in plaintext at some point and there is no way to do that
without having a decrypted copy in memory. However, this patch reduces
the risk of long-lived objects being swapped to disk in plain text from
where they may be recoverable by an attacker.

Encryption only applies to fields marked as "Protected" (which is the
default for the password field) and attachments. Attachments are
always encrypted, independently of whether they are marked as
"Protected", since there is no GUI option to set this flag and we
can safely assume that attachments very often contain private keys
and other highly critical information.
@droidmonkey droidmonkey changed the base branch from release/2.4.2 to develop June 1, 2019 00:16
@droidmonkey droidmonkey force-pushed the feature/memory-protection-v3 branch from ad74e24 to 1c2b8cb Compare June 1, 2019 00:17
@m-khvoinitsky
Copy link

This seems to me like a bogus security measure: you can't avoid swapping sensitive data completely but you will complicate code base which can lead to bugs. Shouldn't OSes have some mechanisms to avoid swapping sensitive memory pages? At least Linux has mlock(2).

@phoerious
Copy link
Member Author

phoerious commented Aug 18, 2019

We would have to mlock the whole process memory. Encryption reduces the risk that swapped parts are recoverable in plain text. OpenSSH has implemented similar measures against Spectre side-channel attacks.

The added complexity is very minimal. This patch just needs to be updated to reflect the current develop branch.

@m-khvoinitsky
Copy link

m-khvoinitsky commented Aug 18, 2019

We would have to mlock the whole process memory.

Why? At least you can mlock only pages which contain data (not code). On the other hand, keepassxc eats not so much memory — mlock-ing even whole process wouldn't cause many troubles.

@phoerious
Copy link
Member Author

We have no control over Qt's memory allocation.

@droidmonkey droidmonkey modified the milestones: v2.5.0, v2.6.0 Oct 5, 2019
@droidmonkey
Copy link
Member

I am closing this until its ready. I think 2.6.0 is big enough refactor as it stands, lets not introduce more entropy to our changes with this.

@droidmonkey droidmonkey removed this from the v2.6.0 milestone Jul 6, 2020
@phoerious phoerious deleted the feature/memory-protection-v3 branch March 24, 2022 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants