[RFC][PATCH 4/5] encrypted-keys: check hex2bin result

From: Mimi Zohar
Date: Fri Sep 16 2011 - 08:51:32 EST


From: Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx>

For each hex2bin call in encrypted keys, check that the ascii hex string
is valid. On failure, return -EINVAL.

Signed-off-by: Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx>
Signed-off-by: Mimi Zohar <zohar@xxxxxxxxxxxxxxxxxx>
---
security/keys/encrypted-keys/encrypted.c | 11 ++++++++---
1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/security/keys/encrypted-keys/encrypted.c b/security/keys/encrypted-keys/encrypted.c
index 3f57795..cd654d9 100644
--- a/security/keys/encrypted-keys/encrypted.c
+++ b/security/keys/encrypted-keys/encrypted.c
@@ -667,11 +667,16 @@ static int encrypted_key_decrypt(struct encrypted_key_payload *epayload,
return -EINVAL;

hex_encoded_data = hex_encoded_iv + (2 * ivsize) + 2;
- hex2bin(epayload->iv, hex_encoded_iv, ivsize);
- hex2bin(epayload->encrypted_data, hex_encoded_data, encrypted_datalen);
+ if (!hex2bin(epayload->iv, hex_encoded_iv, ivsize))
+ return -EINVAL;
+ if (!hex2bin(epayload->encrypted_data, hex_encoded_data,
+ encrypted_datalen))
+ return -EINVAL;

hmac = epayload->format + epayload->datablob_len;
- hex2bin(hmac, hex_encoded_data + (encrypted_datalen * 2), HASH_SIZE);
+ if (!hex2bin(hmac, hex_encoded_data + (encrypted_datalen * 2),
+ HASH_SIZE))
+ return -EINVAL;

mkey = request_master_key(epayload, &master_key, &master_keylen);
if (IS_ERR(mkey))
--
1.7.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/