Skip to contentSkip to conversation

ecryptfs: validate auth tok payload size

PATCH Superseded Adriano Cordova 2 participants 3 messages Oct 1 – Oct 4

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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.

---
 fs/ecryptfs/ecryptfs_kernel.h | 6 ++++++
 fs/ecryptfs/keystore.c        | 7 +++++++
 2 files changed, 13 insertions(+)
fs/ecryptfs/ecryptfs_kernel.h +6 -0
index 58165928ed1e..4315c18ba1cd 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;
 }
 
@@ -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
index 51651314b7a6..7f2dbc81fcbc 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 sKEK size\n");
+		rc = -EINVAL;
+		goto out;
+	}
 out:
 	return rc;
 }
Signature · 1 line
2.51.0
#2 lore raw
Quoted 7 lines · Nguyen Duy Nhat Anh

Hi Adriano,

I noticed this patch touches the exact same lines as a bug fix I submitted earlier for ecryptfs (the ecryptfs_get_key_payload_data fix):
https://lore.kernel.org/all/[email protected]/T/

Quoted 5 lines

Since your patch expands on this area, could you please add my Co-developed-by or Reported-by tag to this series?

Thanks,
Anh

Hi Anh,

Sure, I will send a v2