aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2022-02-23filesystem: create metadata files with mode 0600Eric Biggers
Currently, fscrypt policies and protectors are world readable, as they are created with mode 0644. While this can be nice for use cases where users share these files, those use cases seem to be quite rare, and it's not a great default security-wise since it exposes password hashes to all users. While fscrypt uses a very strong password hash algorithm, it would still be best to follow the lead of /etc/shadow and keep this information non-world-readable. Therefore, start creating these files with mode 0600. Of course, if users do actually want to share these files, they have the option of simply chmod'ing them to a less restrictive mode. An option could also be added to make fscrypt use the old mode 0644; however, the need for that is currently unclear.
2022-02-23filesystem: preserve metadata file permissions on updatesEric Biggers
Since fscrypt replaces metadata files rather than overwrites them (to get atomicity), their owner will change to root if root makes a change. That isn't too much of an issue when the files have mode 0644. However, it will become a much bigger issue when the files have mode 0600, especially because existing files with mode 0644 would also get changed to have mode 0600. In preparation for this, start preserving the previous owner and mode of policy and protector files when they are updated.
2022-02-23Make all new metadata files owned by user when neededEric Biggers
Since commit 4c7c6631cc5a ("Set owner of login protectors to correct user"), login protectors are made owned by the user when root creates one on a user's behalf. That's good, but the same isn't true of other files that get created at the same time: - The policy protecting the directory - The protector link file, if the policy is on a different filesystem - The recovery protector, if the policy is on a different filesystem - The recovery instructions file In preparation for setting all metadata files to mode 0600, start making all these files owned by the user in this scenario as well.
2022-02-23Extend ownership validation to entire directory structureEric Biggers
A previous commit extended file ownership validation to policy and protector files (by default -- there's an opt-out in /etc/fscrypt.conf). However, that didn't apply to the parent directories: MOUNTPOINT MOUNTPOINT/.fscrypt MOUNTPOINT/.fscrypt/policies MOUNTPOINT/.fscrypt/protectors The problem is that if the parent directories aren't trusted (owned by another non-root user), then untrusted changes to their contents can be made at any time, including the introduction of symlinks and so on. While it's debatable how much of a problem this really is, given the other validations that are done, it seems to be appropriate to validate the parent directories too. Therefore, this commit applies the same ownership validations to the above four directories as are done on the metadata files themselves. In addition, it is validated that none of these directories are symlinks except for ".fscrypt" where this is explicitly supported.
2022-02-23Strictly validate metadata file ownership by defaultEric Biggers
The metadata validation checks introduced by the previous commits are good, but to reduce the attack surface it would be much better to avoid reading and parsing files owned by other users in the first place. There are some possible use cases for users sharing fscrypt metadata files, but I think that for the vast majority of users it is unneeded and just opens up attack surface. Thus, make fscrypt (and pam_fscrypt) not process policies or protectors owned by other users by default. Specifically, * If fscrypt or pam_fscrypt is running as a non-root user, only policies and protectors owned by the user or by root can be used. * If fscrypt is running as root, any policy or protector can be used. (This is to match user expectations -- starting a sudo session should gain rights, not remove rights.) * If pam_fscrypt is running as root, only policies and protectors owned by root can be used. Note that this only applies when the root user themselves has an fscrypt login protector, which is rare. Add an option 'allow_cross_user_metadata' to /etc/fscrypt.conf which allows restoring the old behavior for anyone who really needs it.
2022-02-23Make 'fscrypt setup' offer a choice of directory modesEric Biggers
World-writable directories are not appropriate for some systems, so offer a choice of single-user-writable and world-writable modes, with single-user-writable being the default. Add a new documentation section to help users decide which one to use.
2022-02-23filesystem: fall back to non-atomic overwrites when requiredEric Biggers
To allow users to update fscrypt metadata they own in single-user-writable metadata directories (introduced by the next commit), fall back to non-atomic overwrites when atomic ones can't be done due to not having write access to the directory.
2022-02-23filesystem: reject spoofed login protectorsEric Biggers
If a login protector contains a UID that differs from the file owner (and the file owner is not root), it might be a spoofed file that was created maliciously, so make sure to consider such files to be invalid.
2022-02-23filesystem: validate size and type of metadata filesEric Biggers
Don't allow reading metadata files that are very large, as they can crash the program due to the memory required. Similarly, don't allow reading metadata files that aren't regular files, such as FIFOs, or symlinks (which could point to a device node like /dev/zero), as that can hang the program. Both issues were particularly problematic for pam_fscrypt, as they could prevent users from being able to log in. Note: these checks are arguably unneeded if we strictly check the file ownership too, which a later commit will do. But there's no reason not to do these basic checks too.
2022-02-23bash_completion: fix command injection and incorrect completionsEric Biggers
Mountpoint paths might be untrusted arbitrary strings; the fscrypt bash completion script might need to complete to such strings. Unfortunately, the design of bash completion places some major footguns in the way of doing this correctly and securely: - "compgen -W" expands anything passed to it, so the argument to -W must be single-quoted to avoid an extra level of expansion. - The backslashes needed to escape meta-characters in the completed text aren't added automatically; they must be explicitly added. Note that the completion script for 'umount' used to have these same bugs (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=892179, https://github.com/util-linux/util-linux/issues/539). Fix these bugs in roughly the same way that 'umount' fixed them.
2022-02-23Make the output of 'fscrypt status' unambiguousEric Biggers
Following the example of /proc/self/mountinfo, replace the space, newline, tab, and backslash characters with octal escape sequences so that the output can be parsed unambiguously.
2022-02-11Merge pull request #345 from google/contributingJoseph Richey
CONTRIBUTING: update maintainers list
2022-02-11CONTRIBUTING: update maintainers listEric Biggers
2022-02-06v0.3.2v0.3.2Eric Biggers
2022-02-06filesystem: remove an outdated commentEric Biggers
2022-01-26Merge pull request #340 from google/fix-btrfsEric Biggers
Allow the root directory to be a btrfs filesystem
2022-01-26filesystem: fall back to path-only links if UUID cannot be determinedEric Biggers
This is needed to allow creating protector links to btrfs filesystems. Update https://github.com/google/fscrypt/issues/339
2022-01-26filesystem: make FindMount() fall back to search by pathEric Biggers
This is needed to make FindMount() work on btrfs filesystems. Update https://github.com/google/fscrypt/issues/339
2022-01-19filesystem: add back canonicalizePath()Eric Biggers
Restore the canonicalizePath() function from before commit f2eb79fb5fb10275c014b55c13e28ff02d3b70a8, since it's needed again. Update https://github.com/google/fscrypt/issues/339
2022-01-19filesystem: add back the mountsByPath mapEric Biggers
Add back the mountsByPath map, which indexes all Mounts by mountpoint. This is needed again. To avoid confusion, also rename two local variables named mountsByPath. mountsByPath won't contain nil entries, so also make AllFilesystems() use it instead of mountsByDevice. This shouldn't change its behavior. Update https://github.com/google/fscrypt/issues/339
2022-01-19Merge pull request #341 from google/fix-testEric Biggers
cli-tests: fix broken test
2022-01-19cli-tests: fix broken testEric Biggers
I'm not sure how this passed the GitHub checks.
2022-01-18Merge pull request #337 from google/broken-linksEric Biggers
filesystem: store mountpoint in link files as a fallback
2022-01-18Merge pull request #338 from google/remove-protector-from-policyEric Biggers
cmd/fscrypt: don't load protector in remove-protector-from-policy
2021-12-23cmd/fscrypt: don't load protector in remove-protector-from-policyEric Biggers
Make remove-protector-from-policy work even if the protector cannot be loaded (for example, due to having been deleted already). Fixes https://github.com/google/fscrypt/issues/258 Fixes https://github.com/google/fscrypt/issues/272
2021-12-23cli-tests: add helper functions to get protector descriptorsEric Biggers
2021-12-22filesystem: store mountpoint in link files as a fallbackEric Biggers
Currently, linked protectors use filesystem link files of the form "UUID=<uuid>". These links get broken if the filesystem's UUID changes, e.g. due to the filesystem being re-created even if the ".fscrypt" directory is backed up and restored. To prevent links from being broken (in most cases), start storing the mountpoint path in the link files too, in the form "UUID=<uuid>\nPATH=<path>\n". When following a link, try the UUID first, and if it doesn't work try the PATH. While it's possible that the path changed too, for login protectors (the usual use case of linked protectors) this won't be an issue as the path will always be "/". An alternative solution would be to fall back to scanning all filesystems for the needed protector descriptor. I decided not to do that, since relying on a global scan doesn't seem to be a good design. It wouldn't scale to large numbers of filesystems, it could cross security boundaries, and it would make it possible for adding a new filesystem to break fscrypt on existing filesystems. And if a global scan was an acceptable way to find protectors during normal use, then there would be no need for link files in the first place. Note: this change is backwards compatible (i.e., fscrypt will continue to recognize old link files) but not forwards-compatible (i.e., previous versions of fscrypt won't recognize new link files). Fixes https://github.com/google/fscrypt/issues/311
2021-12-22Merge pull request #336 from google/test-fixEric Biggers
context_text: remove pre-existing test.conf
2021-12-22context_text: remove pre-existing test.confEric Biggers
This fixes a test failure in the case where test.conf gets left over.
2021-12-21Merge pull request #335 from google/fix-typosEric Biggers
Fix a few typos
2021-12-21Fix a few typosEric Biggers
2021-12-21Merge pull request #334 from ebiggers/warn-on-chauthtok-failEric Biggers
pam_fscrypt: warn user if OLDAUTHTOK not given in chauthtok
2021-12-21pam_fscrypt: warn user if OLDAUTHTOK not given in chauthtokEric Biggers
If someone runs 'passwd USER' as root, the user is assigned a new login passphrase without their fscrypt login protector being updated. Detect this case and show a warning message using pam_info(). Fixes https://github.com/google/fscrypt/issues/273
2021-12-21Merge pull request #333 from ebiggers/doc-encryption-solutionsEric Biggers
README: elaborate on alternatives and threat model
2021-12-21README: elaborate on alternatives and threat modelEric Biggers
Fixes https://github.com/google/fscrypt/issues/318
2021-12-21README: write "Linux native filesystem encryption"Eric Biggers
"Linux filesystem encryption" sounds too vague. Write "Linux native filesystem encryption" instead.
2021-12-20Merge pull request #332 from ebiggers/skip-irrelevant-filesystemsEric Biggers
filesystem: avoid accessing irrelevant filesystems
2021-12-20filesystem: avoid accessing irrelevant filesystemsEric Biggers
Forbid 'fscrypt setup' on filesystems that aren't expected to support encryption (other than the root filesystem), and skip looking for fscrypt metadata directories on such filesystems. This has two benefits. First, it avoids the printing of annoying warnings like: pam_fscrypt[75038]: stat /run/user/0/.fscrypt: permission denied pam_fscrypt[75038]: stat /run/user/0/.fscrypt/policies: permission denied pam_fscrypt[75038]: stat /run/user/0/.fscrypt/protectors: permission denied pam_fscrypt[75038]: stat /sys/firmware/efi/efivars/.fscrypt: invalid argument pam_fscrypt[75038]: stat /sys/firmware/efi/efivars/.fscrypt/policies: invalid argument pam_fscrypt[75038]: stat /sys/firmware/efi/efivars/.fscrypt/protectors: invalid argument pam_fscrypt[75038]: stat /sys/fs/pstore/.fscrypt: permission denied pam_fscrypt[75038]: stat /sys/fs/pstore/.fscrypt/policies: permission denied pam_fscrypt[75038]: stat /sys/fs/pstore/.fscrypt/protectors: permission denied Second, it avoids long delays or side effects on some filesystems. To do this, introduce an allowlist of filesystem types that fscrypt will recognize. I wanted to avoid doing this, since this list will need to be updated in the future, but I don't see a better solution.
2021-12-20Merge pull request #331 from ebiggers/login-protector-permsEric Biggers
Set owner of login protectors to correct user
2021-12-20Merge pull request #329 from ebiggers/doc-ssh-issueEric Biggers
README: document issue with ssh ChallengeResponseAuthentication
2021-12-20Merge pull request #330 from google/avoid-warningEric Biggers
pam: avoid compiler warning in copyIntoSecret()
2021-12-19Set owner of login protectors to correct userEric Biggers
When the root user creates a login protector for a non-root user, make sure to chown() the protector file to make it owned by the user. Without this, the protector cannot be updated by the user, which causes it to get out of sync if the user changes their login passphrase. Fixes https://github.com/google/fscrypt/issues/319
2021-12-19pam: avoid compiler warning in copyIntoSecret()Eric Biggers
gcc 11 enabled -Wmaybe-uninitialized by default. It causes a false-positive warning in copyIntoSecret() because gcc doesn't understand that mlock() is special and doesn't read from the memory. Just initialize the memory to avoid this warning.
2021-12-19README: document issue with ssh ChallengeResponseAuthenticationEric Biggers
Update https://github.com/google/fscrypt/issues/321 Update https://github.com/google/fscrypt/issues/324
2021-11-29Merge pull request #326 from dimitry-ishenko/stdinEric Biggers
cmd/fscrypt: read key from stdin in non-interactive shell
2021-11-29cmd/fscrypt: read key from stdinDimitry Ishenko
Fixes #123
2021-10-18Release version v0.3.1v0.3.1Eric Biggers
2021-10-05Adjust recovery passphrase generationEric Biggers
As per the feedback at https://github.com/google/fscrypt/issues/115 where users didn't understand that the recovery passphrase is important, restore the original behavior where recovery passphrase generation happens automatically without a prompt. This applies to the case where 'fscrypt encrypt' is using a login protector on a non-root filesystem. However, leave the --no-recovery option so that the recovery passphrase can still be disabled if the user really wants to. Also, clarify the information provided about the recovery passphrase. Update https://github.com/google/fscrypt/issues/115
2021-09-22Merge pull request #317 from ebiggers/readme-symlink-bugJoseph Richey
README: mention LTS kernel versions with symlink bug fix
2021-09-22README: mention LTS kernel versions with symlink bug fixEric Biggers
Resolves https://github.com/google/fscrypt/issues/305