ecryptfs: validate auth tok payload size
Subsystems (2)
PATCH v2 1/1 ecryptfs: validate auth tok payload size
Validate that a key payload is large enough to hold a struct ecryptfs_auth_tok, and that the password token's session_key_encryption_key_bytes fits within session_key_encryption_key[], before the payload is dereferenced.
---
Changes in v2:
- Add Reported-by tag.
fs/ecryptfs/ecryptfs_kernel.h | 6 ++++++ fs/ecryptfs/keystore.c | 7 +++++++ 2 files changed, 13 insertions(+)
fs/ecryptfs/ecryptfs_kernel.h +6 -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; }
@@ -124,6 +127,9 @@ ecryptfs_get_key_payload_data(struct key *key)if (!ukp)return ERR_PTR (-EKEYREVOKED ); +if (ukp->datalen <sizeof (struct ecryptfs_auth_tok )) +return ERR_PTR (-EINVAL ); +return (struct ecryptfs_auth_tok *)ukp->data; }
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 sKEK size\n" ); + rc = -EINVAL ; + goto out; + } out:return rc; }
Signature · 1 line
2.51.0
Tyler Hicks
maintainerQuoted 4 lines · Adriano Cordova
Validate that a key payload is large enough to hold a struct
ecryptfs_auth_tok, and that the password token'ssession_key_encryption_key_bytesfits within session_key_encryption_key[], before the payload is dereferenced.
Hi Adriano - Thank you for the fixes!
Quoted 6 lines
Cc <[email protected]>Reported-by [email protected]Reported-by Nguyen Duy Nhat Anh <[email protected]>Tested-by [email protected]
Change this tag from Link: to Closes:, please.
Quoted 14 lines
Signed-off-by Adriano Cordova <[email protected]>---
Changes in v2:
- Add Reported-by tag.fs/ecryptfs/ecryptfs_kernel.h | 6 ++++++ fs/ecryptfs/keystore.c | 7 +++++++ 2 files changed, 13 insertions(+)fs/ecryptfs/ecryptfs_kernel.h +0
-0
fs/ecryptfs/ecryptfs_kernel.h ecryptfs_get_encrypted_key_payload_data(struct key *key) · line 93
Quoted 6 lines
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 ); +
This change should be in its own patch with the following Fixes tag:
fs/ecryptfs/ecryptfs_kernel.h ecryptfs_get_key_payload_data(struct key *key) · line 132
Quoted 10 lines
fs/ecryptfs/ecryptfs_kernel.h +3
-0return (struct ecryptfs_auth_tok *)payload->payload_data; }@@ -124,6 +127,9 @@ ecryptfs_get_key_payload_data(struct key *key)if (!ukp)return ERR_PTR (-EKEYREVOKED ); +if (ukp->datalen <sizeof (struct ecryptfs_auth_tok )) +return ERR_PTR (-EINVAL ); +
Nguyen Duy Nhat Anh submitted this fix prior to your v1 so it is best if I take that initial patch. Please drop this change.
Quoted 8 lines
fs/ecryptfs/ecryptfs_kernel.h +0
-0return (struct ecryptfs_auth_tok *)ukp->data; }fs/ecryptfs/keystore.c +0
-0
fs/ecryptfs/keystore.c ecryptfs_verify_auth_tok_from_key(struct key *auth_tok_key, · line 486
Quoted 10 lines
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 sKEK size\n" ); + rc = -EINVAL ; + goto out; + }
This change should be in its own patch with the following Fixes tag:
Thanks again!
Tyler
Quoted 6 lines
fs/ecryptfs/keystore.c +0
-0out:return rc; }Signature · 1 line
2.51.0
Quoted 78 lines · Tyler Hicks
Quoted 4 lines · Adriano Cordova
Validate that a key payload is large enough to hold a struct
ecryptfs_auth_tok, and that the password token'ssession_key_encryption_key_bytesfits within session_key_encryption_key[], before the payload is dereferenced.Hi Adriano - Thank you for the fixes!
Quoted 6 lines
Cc <[email protected]>Reported-by [email protected]Reported-by Nguyen Duy Nhat Anh <[email protected]>Tested-by [email protected]Change this tag from
Link:toCloses:, please.Quoted 14 lines
Signed-off-by Adriano Cordova <[email protected]>---
Changes in v2:
- Add Reported-by tag.fs/ecryptfs/ecryptfs_kernel.h | 6 ++++++ fs/ecryptfs/keystore.c | 7 +++++++ 2 files changed, 13 insertions(+)fs/ecryptfs/ecryptfs_kernel.h +0
-0fs/ecryptfs/ecryptfs_kernel.h ecryptfs_get_encrypted_key_payload_data(struct key *key) · line 93
Quoted 6 lines
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 ); +This change should be in its own patch with the following Fixes tag:
Fixes 1252cc3b232e ("eCryptfs: added support for the encrypted key type")fs/ecryptfs/ecryptfs_kernel.h ecryptfs_get_key_payload_data(struct key *key) · line 132
Quoted 10 lines
fs/ecryptfs/ecryptfs_kernel.h +3
-0return (struct ecryptfs_auth_tok *)payload->payload_data; }@@ -124,6 +127,9 @@ ecryptfs_get_key_payload_data(struct key *key)if (!ukp)return ERR_PTR (-EKEYREVOKED ); +if (ukp->datalen <sizeof (struct ecryptfs_auth_tok )) +return ERR_PTR (-EINVAL ); +Nguyen Duy Nhat Anh submitted this fix prior to your v1 so it is best if I take that initial patch. Please drop this change.
Quoted 8 lines
fs/ecryptfs/ecryptfs_kernel.h +0
-0return (struct ecryptfs_auth_tok *)ukp->data; }fs/ecryptfs/keystore.c +0
-0fs/ecryptfs/keystore.c ecryptfs_verify_auth_tok_from_key(struct key *auth_tok_key, · line 486
Quoted 10 lines
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 sKEK size\n" ); + rc = -EINVAL ; + goto out; + }This change should be in its own patch with the following Fixes tag:
Quoted 12 lines
Fixes 9c79f34f7ee7 ("eCryptfs: Filename Encryption: Tag 70 packets")Thanks again!
Tyler
Quoted 6 lines
fs/ecryptfs/keystore.c +0
-1out:return rc; } --2.51.0
Hi Tyler, thanks for the review. I will split the changes and send a v2.
Adriano