Skip to content

Enable DEP and ASLR.#371

Merged
phoerious merged 3 commits intokeepassxreboot:developfrom
rockihack:DEP+ASLR
Mar 10, 2017
Merged

Enable DEP and ASLR.#371
phoerious merged 3 commits intokeepassxreboot:developfrom
rockihack:DEP+ASLR

Conversation

@rockihack
Copy link
Copy Markdown
Contributor

Description

Enable Data Execution Prevention (DEP) and Address Layout Randomization (ASLR) on windows.

Motivation and Context

DEP and ASLR are simple exploit mitigation technologies. DEP is currently not enforced and ASLR is not enabled at all.

https://www.microsoft.com/security/sir/strategy/default.aspx#!section_3_3
https://blogs.technet.microsoft.com/srd/2010/12/08/on-the-effectiveness-of-dep-and-aslr/

How Has This Been Tested?

Windows 7 + ProcessExplorer

Types of changes

  • ✅ New feature (non-breaking change which adds functionality)

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]

@TheZ3ro
Copy link
Copy Markdown
Contributor

TheZ3ro commented Mar 3, 2017

👍

@rockihack
Copy link
Copy Markdown
Contributor Author

It should be verified that keepassxc follows security best practices on windows, macOS and linux.
I just noticed this on windows but I don't have enough time to look into all platforms.

@phoerious
Copy link
Copy Markdown
Member

phoerious commented Mar 3, 2017

Address randomization on Linux seems to be implemented with PIC and therefore incurs a slight performance penalty (at least on x86, x86_64 doesn't have these problems as much). At least that's what I found in this (rather dated) article: https://insights.sei.cmu.edu/cert/2014/02/differences-between-aslr-on-windows-and-linux.html
However, at least some randomization of shared libs etc. is enabled by default on almost all Linux distributions.

@phoerious
Copy link
Copy Markdown
Member

phoerious commented Mar 4, 2017

Alright, did some more digging. For Linux, we need the options -pie -fPIE for full ASLR. Otherwise the ELF memory section will not be randomized. At least on my system, though, -pie is on by default, so Clang complains that the option is unused. If we add this option, we should maybe also add -Qunused-arguments to suppress that warning.

For stack protection, -fstack-protector can be used, which is already enabled in our CMakeLists.txt. At the cost of performance, this could be replaced with -fstack-protector-all or at least -fstack-protector-strong.

The other thing we could enable is relocation read-only (relro). Partial relro is already enabled with -z,relro. By adding -z,now we could change this to full relro, which also makes the full GOT read-only.

@kairaven
Copy link
Copy Markdown

kairaven commented Mar 4, 2017

I changed CMakeLists.txt with 2.1.2 before and with 2.1.3 (shows 2.1.2 in about) today with the modifications phoerious mentioned and i get with hardening-check under Debian Jessie:

/usr/local/bin/keepassxc:
Position Independent Executable: yes
Stack protected: yes
Fortify Source functions: no, only unprotected functions found!
Read-only relocations: yes
Immediate binding: yes

with an unmodified CMakeLists.txt i get:

src/keepassxc:
Position Independent Executable: no, normal executable!
Stack protected: yes
Fortify Source functions: no, only unprotected functions found!
Read-only relocations: yes
Immediate binding: no, not found!

Fortify Source functions didn't work for me with keepassx and keepassxc, but apart from that keepassxc works fine.

@phoerious
Copy link
Copy Markdown
Member

Fortify source is enabled for release builds in CMakeLists.txt. But it might be possible, that the setting is not really applied because the regular expression in the surrounding if condition is not wrapped in double quotes. I had something like that earlier. But as I understand it, it only checks for overflows in C string functions anyway. So it would be useful at most for code on external libraries.

@TheZ3ro
Copy link
Copy Markdown
Contributor

TheZ3ro commented Mar 6, 2017

Any news about this? Can we merge?

@phoerious
Copy link
Copy Markdown
Member

phoerious commented Mar 6, 2017

We should add the additional flags I suggested and maybe check if there are similar flags for the Mac.
And this branch also needs to be rebased first.

@rockihack
Copy link
Copy Markdown
Contributor Author

rockihack commented Mar 8, 2017

According to https://en.wikipedia.org/wiki/Data_Execution_Prevention#macOS all 64-bit executables have NX stack and heap (DEP) since 10.5 and https://en.wikipedia.org/wiki/Address_space_layout_randomization#OS_X states that all executables since 10.7 support ASLR.

$ otool -hv KeePassX 
Mach header
      magic cputype cpusubtype  caps    filetype ncmds sizeofcmds      flags
MH_MAGIC_64  **X86_64**        ALL LIB64     EXECUTE    21       2624   NOUNDEFS DYLDLINK TWOLEVEL BINDS_TO_WEAK **PIE**

@phoerious
Copy link
Copy Markdown
Member

I guess that means we only need to enable the flags for Linux and are set and ready?

@rockihack
Copy link
Copy Markdown
Contributor Author

I think so. It seems that its enabled by default on macOS and you need to "opt-out" to disable it.

@rockihack
Copy link
Copy Markdown
Contributor Author

DLLs on windows are relocatable by default but nevertheless DEP+ASLR should be enabled.
Verified with dumpbin /headers libkeepassx-autotype-windows.dll.

@phoerious
Copy link
Copy Markdown
Member

phoerious commented Mar 10, 2017

Could you enable the option to allow me to push to your branch? I would like to add my Linux changes, but can't do so without copying the branch which would need a new PR.

@rockihack
Copy link
Copy Markdown
Contributor Author

Allow edits from maintainers. is already enabled.

@phoerious
Copy link
Copy Markdown
Member

phoerious commented Mar 10, 2017

Then I don't know why I couldn't push. Maybe the plus in the branch name or something. I cloned your repository instead of adding it as a remote, now it works.

@droidmonkey @TheZ3ro Could you have a look at the changes? I think we can merge this if you don't see any further issues. We need to rebase first, though.

@TheZ3ro
Copy link
Copy Markdown
Contributor

TheZ3ro commented Mar 10, 2017

Travis is failing

@phoerious
Copy link
Copy Markdown
Member

phoerious commented Mar 10, 2017

Somehow it can't find the right Zlib version. The two clang builds passed, though. Probably some Travis/Redis fuckup again. I restarted the build, let's see.

@phoerious
Copy link
Copy Markdown
Member

phoerious commented Mar 10, 2017

Looks like the error message is just completely misleading. -Qunused-arguments appears to be a clang-specific option, so I fixed it by only applying it when clang is used as a compiler.

@rockihack
Copy link
Copy Markdown
Contributor Author

Why did you use add_gcc_compiler_cflags instead of add_gcc_compiler_flags?

@phoerious
Copy link
Copy Markdown
Member

Because I am stupid (or my autocompletion is). I changed it and squashed the last two commits into the "Harden Linux binary" commit.

Copy link
Copy Markdown
Member

@phoerious phoerious left a comment

Choose a reason for hiding this comment

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

I rebased the branch, but it doesn't trigger Travis again. Seems like we have to merge it without.

@phoerious phoerious merged commit 7851d3d into keepassxreboot:develop Mar 10, 2017
droidmonkey added a commit that referenced this pull request Jun 25, 2017
- Added YubiKey 2FA integration for unlocking databases [#127]
- Added TOTP support [#519]
- Added CSV import tool [#146, #490]
- Added KeePassXC CLI tool [#254]
- Added diceware password generator [#373]
- Added support for entry references [#370, #378]
- Added support for Twofish encryption [#167]
- Enabled DEP and ASLR for in-memory protection [#371]
- Enabled single instance mode [#510]
- Enabled portable mode [#645]
- Enabled database lock on screensaver and session lock [#545]
- Redesigned welcome screen with common features and recent databases [#292]
- Multiple updates to search behavior [#168, #213, #374, #471, #603, #654]
- Added auto-type fields {CLEARFIELD}, {SPACE}, {{}, {}} [#267, #427, #480]
- Fixed auto-type errors on Linux [#550]
- Prompt user prior to executing a cmd:// URL [#235]
- Entry attributes can be protected (hidden) [#220]
- Added extended ascii to password generator [#538]
- Added new database icon to toolbar [#289]
- Added context menu entry to empty recycle bin in databases [#520]
- Added "apply" button to entry and group edit windows [#624]
- Added macOS tray icon and enabled minimize on close [#583]
- Fixed issues with unclean shutdowns [#170, #580]
- Changed keyboard shortcut to create new database to CTRL+SHIFT+N [#515]
- Compare window title to entry URLs [#556]
- Implemented inline error messages [#162]
- Ignore group expansion and other minor changes when making database "dirty" [#464]
- Updated license and copyright information on souce files [#632]
- Added contributors list to about dialog [#629]
@phoerious phoerious added pr: new feature Pull request adds a new feature and removed new feature labels Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: new feature Pull request adds a new feature security

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants