ecryptfs: reject short encrypted key payloads
Subsystems (2)
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.
---
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
@@ -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
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.
---
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
@@ -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
Tyler Hicks
maintainerQuoted 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