ima: prevent buffer overflow in ima_alloc_tfm()
authorDmitry Kasatkin <d.kasatkin@samsung.com>
Fri, 15 Aug 2014 10:28:52 +0000 (13:28 +0300)
committerMimi Zohar <zohar@linux.vnet.ibm.com>
Tue, 2 Sep 2014 21:03:36 +0000 (17:03 -0400)
This patch fixes the case where the file's signature/hash xattr contains
an invalid hash algorithm.  Although we can not verify the xattr, we still
need to measure the file.  Use the default IMA hash algorithm.

Signed-off-by: Dmitry Kasatkin <d.kasatkin@samsung.com>
Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
security/integrity/ima/ima_crypto.c

index 2d103dc13d907119386017c3c4e645e6157698ff..1178b307d5621e23ef1be2eda7c5650fb2333d06 100644 (file)
@@ -116,7 +116,10 @@ static struct crypto_shash *ima_alloc_tfm(enum hash_algo algo)
        struct crypto_shash *tfm = ima_shash_tfm;
        int rc;
 
-       if (algo != ima_hash_algo && algo < HASH_ALGO__LAST) {
+       if (algo < 0 || algo >= HASH_ALGO__LAST)
+               algo = ima_hash_algo;
+
+       if (algo != ima_hash_algo) {
                tfm = crypto_alloc_shash(hash_algo_name[algo], 0, 0);
                if (IS_ERR(tfm)) {
                        rc = PTR_ERR(tfm);