Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 932301a5 authored by Eric Biggers's avatar Eric Biggers Committed by Jaegeuk Kim
Browse files

fscrypt: use ENOPKG when crypto API support missing



Return ENOPKG rather than ENOENT when trying to open a file that's
encrypted using algorithms not available in the kernel's crypto API.

This avoids an ambiguity, since ENOENT is also returned when the file
doesn't exist.

Note: this is the same approach I'm taking for fs-verity.

Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
parent 60f50d13
Loading
Loading
Loading
Loading
+11 −9
Original line number Diff line number Diff line
@@ -237,11 +237,12 @@ allocate_skcipher_for_mode(struct fscrypt_mode *mode, const u8 *raw_key,

	tfm = crypto_alloc_skcipher(mode->cipher_str, 0, 0);
	if (IS_ERR(tfm)) {
		if (PTR_ERR(tfm) == -ENOENT)
		if (PTR_ERR(tfm) == -ENOENT) {
			fscrypt_warn(inode,
				     "Missing crypto API support for %s (API name: \"%s\")",
				     mode->friendly_name, mode->cipher_str);
		else
			return ERR_PTR(-ENOPKG);
		}
		fscrypt_err(inode, "Error allocating '%s' transform: %ld",
			    mode->cipher_str, PTR_ERR(tfm));
		return tfm;
@@ -389,10 +390,11 @@ static int derive_essiv_salt(const u8 *key, int keysize, u8 *salt)

		tfm = crypto_alloc_shash("sha256", 0, 0);
		if (IS_ERR(tfm)) {
			if (PTR_ERR(tfm) == -ENOENT)
			if (PTR_ERR(tfm) == -ENOENT) {
				fscrypt_warn(NULL,
					     "Missing crypto API support for SHA-256");
			else
				return -ENOPKG;
			}
			fscrypt_err(NULL,
				    "Error allocating SHA-256 transform: %ld",
				    PTR_ERR(tfm));