Skip to contentSkip to conversation

ecryptfs: reject short encrypted key payloads

PATCH In review Adriano Cordova 2 participants 3 messages Oct 16 – Oct 22

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 ecryptfs: reject short encrypted key payloads

Reject payloads too short to hold a struct ecryptfs_auth_tok, as a key created with a non-ecryptfs format is shorter than the struct, so the payload gets dereferenced past its end.

Fixes 1252cc3b232e ("eCryptfs: added support for the encrypted key type")

---
Changes in v3:
- Split the v2 patch.
- Remove Nguyen Duy Nhat Anh change and its Reported-by tag.

Changes in v2:
- Add Reported-by tag.

 fs/ecryptfs/ecryptfs_kernel.h | 3 +++
 1 file changed, 3 insertions(+)
fs/ecryptfs/ecryptfs_kernel.h +3 -0
index 58165928ed1e..d4fef71738b0 100644
@@ -88,6 +88,9 @@ ecryptfs_get_encrypted_key_payload_data(struct key *key)
 	if (!payload)
 		return ERR_PTR(-EKEYREVOKED);
 
+	if (payload->payload_datalen < sizeof(struct ecryptfs_auth_tok))
+		return ERR_PTR(-EINVAL);
+
 	return (struct ecryptfs_auth_tok *)payload->payload_data;
 }
 
Signature · 1 line
2.51.0
#1 lore raw

PATCH v3 2/2 ecryptfs: bound session_key_encryption_key_bytes in auth tok

Let ecryptfs_verify_auth_tok_from_key() validate the password's session_key_encryption_key_bytes length. When it is larger than ECRYPTFS_MAX_KEY_BYTES, md5() reads past session_key_encryption_key[]. Reject such auth toks.

Fixes 9c79f34f7ee7 ("eCryptfs: Filename Encryption: Tag 70 packets")
Reported-by [email protected]

---
Changes in v3:
- Split the v2 patch.
- Change the Link: tag to Closes:.
- Remove Nguyen Duy Nhat Anh change and its Reported-by tag.

 fs/ecryptfs/keystore.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/ecryptfs/keystore.c +7 -0
index 51651314b7a6..c2ba230c71fd 100644
@@ -477,6 +477,13 @@ ecryptfs_verify_auth_tok_from_key(struct key *auth_tok_key,
 		rc = -EINVAL;
 		goto out;
 	}
+	if ((*auth_tok)->token_type == ECRYPTFS_PASSWORD &&
+	    (*auth_tok)->token.password.session_key_encryption_key_bytes >
+	    ECRYPTFS_MAX_KEY_BYTES) {
+		printk(KERN_ERR "Invalid password auth_tok session key size\n");
+		rc = -EINVAL;
+		goto out;
+	}
 out:
 	return rc;
 }
Signature · 1 line
2.51.0
maintainer
#2 lore raw
In reply to Adriano Cordova
Quoted 3 lines · Adriano Cordova

Reject payloads too short to hold a struct ecryptfs_auth_tok, as a key created with a non-ecryptfs format is shorter than the struct, so the payload gets dereferenced past its end.

Thank you! This has been applied to the next branch of the tyhicks/ecryptfs.git tree.

I made one small change to the first patch's commit message. Instead of "as a key created with a non-ecryptfs format is shorter than the struct", I changed it to "as a key created with a non-ecryptfs format can be shorter than the struct".

You can find a direct link below but please be aware that the commit hash is unstable and, therefore, the URL may not be valid in the future.

[1/2] ecryptfs: reject short encrypted key payloads

      https://git.kernel.org/tyhicks/ecryptfs/c/00cc31a869e2f635e6455685c91c4c9045c96ebd
[2/2] ecryptfs: bound session_key_encryption_key_bytes in auth tok
      https://git.kernel.org/tyhicks/ecryptfs/c/8f6626bd6594a78f454d02b27b74a580c890cab9

Tyler