aboutsummaryrefslogtreecommitdiff
path: root/filesystem
AgeCommit message (Collapse)Author
2020-05-09filesystem: improve errorsEric Biggers
Introduce filesystem.ErrEncryptionNotEnabled and filesystem.ErrEncryptionNotSupported which include the Mount as context, and translate the corresponding metadata/ errors into them. Then make these errors show much better suggestions. Also replace lots of other filesystem/ errors with either custom types or with unnamed one-off errors that include more context. Fix backwards wrapping in lots of cases. Finally, don't include the mountpoint in places where it's not useful, like OS-level errors that already include the path.
2020-05-09actions/policy: improve errorsEric Biggers
ErrMissingPolicyMetadata: Include the mount, directory path, and metadata path. Also move the explanation into actions/ since it doesn't refer to any CLI command. ErrPolicyMetadataMismatch: Include a lot more information. Also start checking for consistency of the policy key descriptors, not just the encryption options. Add a test for this. ErrDifferentFilesystem: Include the mountpoints. ErrOnlyProtector: Clarify the message and include the protector descriptor. ErrAlreadyProtected: ErrNotProtected: Include the policy and protector descriptors. ErrAccessDeniedPossiblyV2: Make it slightly clearer what failed. Also move the explanation into actions/ since it doesn't refer to any CLI command.
2020-05-09cmd/fscrypt: add FSCRYPT_CONSISTENT_OUTPUT environmental variableEric Biggers
Allow setting FSCRYPT_CONSISTENT_OUTPUT=1 in the environment to cause policies and protectors to sorted by last modification time. The CLI tests need this to make the output of 'fscrypt' ordered in a consistent way with regard to the operations performed.
2020-04-16Allow fscrypt to work in containers (#213)Eric Biggers
Update the /proc/self/mountinfo parsing code to allow selecting a Mount with Subtree != "/", i.e. a Mount not of the full filesystem. This is needed to allow fscrypt to work in containers, where the root of the filesystem may not be mounted. See findMainMount() for details about the algorithm used. Resolves https://github.com/google/fscrypt/issues/211
2020-03-23Improve error message when unlocking v2 policy is unsupportedEric Biggers
If trying to unlock a v2-encrypted directory fails because the kernel lacks support for v2 policies, show a better error message. This can happen if someone downgrades their kernel or tries to access encrypted directories on removable storage from a computer with an older kernel. Detecting this case is difficult since all we have to go with is EACCES when opening the directory. Implement a heuristic where if get EACCES, we actually have read access to the directory, and the kernel doesn't support v2 policies, we show the improved error message. Before: # fscrypt unlock dir [ERROR] fscrypt unlock: open dir: permission denied After: # fscrypt unlock dir [ERROR] fscrypt unlock: open dir: permission denied This may be caused by the directory using a v2 encryption policy and the current kernel not supporting it. If indeed the case, then this directory can only be used on kernel v5.4 and later. You can create directories accessible on older kernels by changing policy_version to 1 in /etc/fscrypt.conf.
2020-01-28filesystem: don't overwrite existing protector linksEric Biggers
When adding a protector to a policy, don't unconditionally overwrite the protector link, because it may already exist. Instead, if it already exists and points to the mount, just use it. If it already exists and points to the wrong place, return an error. Also add a bool to the return value of AddLinkedProtector() so that callers can check whether the link was newly created or not.
2020-01-23filesystem: remove canonicalizePath() (#185)ebiggers
canonicalizePath() is now only used by an error path in getMountFromLink(), which we can make use getDeviceName() instead.
2019-11-27Allow filesystem links to contain leading/trailing whitespaceEric Biggers
To make manually editing linked protectors slightly more user-friendly, automatically strip any leading or trailing whitespace. E.g. treat "UUID=3a6d9a76-47f0-4f13-81bf-3332fbe984fb\n" the same as "UUID=3a6d9a76-47f0-4f13-81bf-3332fbe984fb". Update https://github.com/google/fscrypt/issues/115
2019-10-30filesystem: add unit tests for loadMountInfo()Eric Biggers
Add a version of loadMountInfo() that takes an io.Reader parameter to allow injecting a custom mountinfo file, then add some unit tests.
2019-10-30filesystem: handle bind mounts properlyEric Biggers
Currently, fscrypt treats bind mounts as separate filesystems. This is broken because fscrypt will look for a directory's encryption policy in different places depending on which mount it's accessed through. This forces users to create an fscrypt metadata directory at every bind mount, and to copy fscrypt metadata around between mounts. Fix this by storing fscrypt metadata only at the root of the filesystem. To accomplish this: - Make mountsByDevice store only a single Mount per filesystem, rather than multiple. For this Mount, choose a mount of the full filesystem if available, preferably a read-write mount. If the filesystem has only bind mounts, store a nil entry in mountsByDevice so we can show a proper error message later. - Change FindMount() and GetMount() to look up the Mount by device number rather than by path, so that they don't return different Mounts depending on which path is used. - Change AllFilesystems() to not return bind mounts. - Due to the above changes, the mountsByPath map is no longer needed outside of loadMountInfo(). So make it a local variable there. Resolves https://github.com/google/fscrypt/issues/59
2019-10-30filesystem: make link handling more robustEric Biggers
The previous patch fixed making linked protectors to /dev/root, by setting Mount.Device to the real device node rather than /dev/root. That's good, but it also hints that the linked protector handling is unnecessarily fragile, as it relies on the device node name matching exactly. The Linux kernel allows the same device to have multiple device nodes, and path comparisons are slow and error-prone in general. Change it to compare the device number instead.
2019-10-30filesystem: get correct device for kernel-mounted rootfsEric Biggers
A root filesystem mounted via the kernel command line always has a source of "/dev/root", which isn't a real device node. This makes fscrypt think this filesystem doesn't have a source device, which breaks creating login passphrase-protected directories on other filesystems: fscrypt encrypt: filesystem /: no device for mount "/": system error: cannot create filesystem link This also makes 'fscrypt status' show a blank source device: MOUNTPOINT DEVICE FILESYSTEM ENCRYPTION FSCRYPT / ext4 supported Yes To fix this case, update loadMountInfo() to map the device number to the device name via sysfs rather than use the mount source field.
2019-10-30filesystem: add device number utilitiesEric Biggers
Add a utility type and functions for handling device numbers.
2019-10-30filesystem: skip unnecessary mountpoint canonicalizationEric Biggers
The kernel always shows mountpoints as absolute paths without symlinks, so there's no need to canonicalize them in userspace.
2019-10-30filesystem: switch to using /proc/self/mountinfoEric Biggers
Change loadMountInfo() to load the mounts directly from /proc/self/mountinfo, rather than use the mntent.h C library calls. This is needed for correct handling of bind mounts and of "/dev/root", since /proc/self/mountinfo has extra fields which show the mounted subtree and the filesystem's device number. /proc/mounts lacks these fields, and the C library calls can't provide them. To start, this patch just switches to using /proc/self/mountinfo, without doing anything with the extra fields yet. As a bonus, this eliminates all C code in mountpoint.go.
2019-10-29filesystem: rename getMountInfo() to loadMountInfo()Eric Biggers
Make it clearer that this function loads data into global data structures, and doesn't return anything.
2019-10-29filesystem: remove Mount.OptionsEric Biggers
fscrypt doesn't currently do anything with the mount options, so remove them from the Mount structure for now.
2019-10-29filesystem: rename Mount.Filesystem to Mount.FilesystemTypeEric Biggers
Make it clear that this refers to a type of filesystem such as "ext4", rather than to a specific filesystem instance.
2019-10-25Added capacity to slice creation, when capacity is known (#159)Vivek V
Simple optimization to reduce memory allocations and copying when appending.
2019-10-23actions/config: ensure config file is created with mode 0644 (#152)ebiggers
If the user has set a restrictive umask, e.g. 0077, then /etc/fscrypt.conf would be created without the world-readable bit set. Fix it by overriding the umask when creating the file. Resolves https://github.com/google/fscrypt/issues/151
2019-10-23filesystem: Move test-only code to test filesJoe Richey
This makes it easier to understand which code is actually invoked by the command-line tool.
2019-10-01filesystem: allow .fscrypt to be a symlinkEric Biggers
Support the case where the user has a read-only root filesystem (e.g. with OSTree) and had previously created a symlink /.fscrypt pointing to a writable location, so that login protectors can be created there. Resolves https://github.com/google/fscrypt/issues/131
2019-09-09writeDataAtomic() fixes (#140)ebiggers
* filesystem: ensure data is persisted before returning success Sync the temporary file before renaming it, to ensure that after a crash, the destination file isn't zero-length or otherwise incomplete. Also sync the directory after the rename, to ensure the rename has been persisted before returning success. * filesystem: don't use fixed temporary file name Using a fixed temporary file name in a world-writable sticky directory is problematic since another user can create the file first. Use ioutil.TempFile() to do it properly. It uses O_EXCL under the hood to ensure the file is newly created.
2019-09-08Fix various typos and grammatical errors (#141)ebiggers
These were found by a combination of manual review and a custom script that checks for common errors. Also removed an outdated sentence from the comment for setupBefore().
2019-08-28Run 'make format' with latest version of goimportsEric Biggers
This fixes a CI failure, caused by goimports changing how it formats the imports.
2018-09-02feat(spell-check): add make command for spell check.Deepesh Pathak
* Remove spelling mistakes in the repository * Add travis script to check for typos. * Add command to Makefile to check for typos. * Fixes #71
2018-08-30Use proto.Equal instead of reflect.DeepEqualsJoe Richey joerichey@google.com
2017-08-31filesystem: libblkid -> search /dev/disk/by-uuidJoe Richey
2017-07-18tests: Unit tests and Integration tests workJoe Richey joerichey@google.com
Now the testing functions will skip the integration tests if a testing filesystem is not specified.
2017-07-17Small fixes so "make lint" doesn't complain.Joe Richey joerichey@google.com
2017-07-17Changes from "make format"Joe Richey joerichey@google.com
2017-07-17filesystem: Distinguish support and setup for fsJoe Richey joerichey@google.com
This commit splits two pieces of functionality. Detecting if the fscrypt metadata exists is now in CheckSetup() and checking if the filesystem supports encryption is now in CheckSupport().
2017-06-28Finalize import paths and documentationv0.1.00.1.0Joe Richey joerichey@google.com
This commit changes all the internal import paths from `fscrypt/foo` to `github.com/google/fscrypt/foo` so that it can be built once we release externaly. The documentation in README.md is updated accordingly. Also, the README has a note noting that we do not make any guarantees about project stability before 1.0 (when it ships with Ubuntu). Change-Id: I6ba86e442c74057c8a06ba32a42e17f94833e280
2017-06-28actions: error handling and API changedJoe Richey joerichey@google.com
This commit changes the error handling for the actions package to use the error handling library github.com/pkg/errors. This means replacing "errors" with "github.com/pkg/errors", reworking some of the error values, and wrapping some errors with additional context. This commit also changes the Protector/Policy API, moving most of the package functionality into Protector or Policy methods. These types are now "locked" when they are queried from the filesystem, and Unlock() must be used to get their corresponding keys. Note that only certain operations will require unlocking the keys. Certain unnecessary functions and methods are also removed. This CL also fixes two bugs reported by Tyler Hicks in CreateConfigFile. CPU time is used instead of wall time, and kiB is used instead of kB. Change-Id: I88f45659e9fe4938d148843e3289e7b6d5b698d8
2017-06-28Change error handling to new packageJoe Richey joerichey@google.com
This commit changes the error handing for the crypto, filesystem, metadata, pam, and util packages to use the error handling library github.com/pkg/errors. This means elimination of the FSError type, an increased use of wrapping errors (as opposed to logging), switching on the Cause() of an error (as opposed to its value), and improving our integration tests involving TEST_FILESYSTEM_ROOT. This commit also fixes a few bugs with the keyring code to ensure that our {Find|Remove|Insert}PolicyKey functions are always operating on the same keyring. The check for filesystem support has been moved from the filesystem package to the metadata package. Finally, the API for the filesystem package has been slightly modified: * filesystem.AllFilesystems() now returns all the filesystems in sorted order * certain path methods are now public O_SYNC is also removed for writing the metadata. We don't get that much from syncing the metadata, as the actual file data could also be corrupted by and IO error. The sync operation is also occasionally very slow (~3 seconds) and can be unfriendly to battery life. Change-Id: I392c2655141714b16dfdbc84ac09780072be2cf0
2017-06-15metadata: change encryption mode namesJoe Richey joerichey@google.com
As new encryption modes are being added to the kernel that use 128 bit keys (see https://patchwork.kernel.org/patch/9741913), we will need the encryption modes to be more descriptive. This change breaks backwards compatibility for the protobuf, but that's fine because we have not released yet. Change-Id: Ifb58d3d5a42db491f1e5393c12f3d260d9a091de
2017-06-15filesystem: change support detection and bug-fixesJoe Richey joerichey@google.com
Instead of checking if the filesystem type is correct, we now detect if a filesystem supports encryption by trying to read a policy on its root directory. The error returned tells us if there is support or not. This commit also fixes a bug in the use libblkid. Throughout all of fscrypt, cannonicalizePath() is used before any path comparison or lookup. However, the canonical device path in the blkid cache may differ from our idea of a canonical path. Additional blkid functions are needed to perform the necessary translation. This is noted in the documentation of makeLink(). Finally, this commit makes a few API changes. AllSupporedFilesystems() now returns an error, and a GetProtector() method now replaces the GetLinkedProtector() and GetEitherProtector() methods. A PathSorter has also been added so Mounts can be sorted in a reliable order. Change-Id: I664f46fafd1483ebecb743c061b03d708b3233a4
2017-06-15pam: checking a user's login passphraseJoe Richey joerichey@google.com
This commit adds in the fscrypt/pam package. This package will hold all functionality related to Linux Pluggable Authentication Modules (PAM). Right now this package uses cgo to mock a PAM conversation, allowing the function to check if a provided passphrase actually belongs to a user. Due to the nature of cgo callbacks, global state of the key to check is necessary for this function. This commit also addresses some issues about building the cgo components. Now, only the minimal linking flags are included in the go files. Additional linker flags may now be necessary to build a static binary of fscrypt. This is addressed in the Makefile and README. Finally, this commit fixes a bug where the tests would not run correctly due to shared global state on the testing filesystem. Fixed, by having all the tests run sequentially. Change-Id: Ia43636801da984b505d2f43dd14127b7cfbf2c48
2017-05-31filesystem: creating the directories and filesJoe Richey joerichey@google.com
This commit adds in the filesystem subpackage. The goal of this package is to provide and interface for adding to and removing from the metadata storage for a given filesystem. This is primarily done in filesystem.go. To facilitate this functionality, mountpoint.go exposes an interface for querying the system about the current mounted filesystems and their information. Note that this operation is done with a lazy loading mechanism. To refer to other filesystems, we use link files that can be parsed by libblkid. The README is also updated to account for this new dependancy. This package uses the FSError type under the hood so that error messages will include the filesystem name, but callers can still check for specific error instances. Change-Id: I74fe4e84b8e3a5b73f1337c35307ffe0bf7cdea9