From: Boshi Wang <wangbo...@huawei.com>

[ Upstream commit ebe7c0a7be92bbd34c6ff5b55810546a0ee05bee ]

The hash_setup function always sets the hash_setup_done flag, even
when the hash algorithm is invalid.  This prevents the default hash
algorithm defined as CONFIG_IMA_DEFAULT_HASH from being used.

This patch sets hash_setup_done flag only for valid hash algorithms.

Fixes: e7a2ad7eb6f4 "ima: enable support for larger default filedata hash
        algorithms"
Signed-off-by: Boshi Wang <wangbo...@huawei.com>
Signed-off-by: Mimi Zohar <zo...@linux.vnet.ibm.com>

Signed-off-by: Sasha Levin <alexander.le...@verizon.com>
---
 security/integrity/ima/ima_main.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/security/integrity/ima/ima_main.c 
b/security/integrity/ima/ima_main.c
index 0e8762945e79..2b3def14b4fb 100644
--- a/security/integrity/ima/ima_main.c
+++ b/security/integrity/ima/ima_main.c
@@ -51,6 +51,8 @@ static int __init hash_setup(char *str)
                        ima_hash_algo = HASH_ALGO_SHA1;
                else if (strncmp(str, "md5", 3) == 0)
                        ima_hash_algo = HASH_ALGO_MD5;
+               else
+                       return 1;
                goto out;
        }
 
@@ -60,6 +62,8 @@ static int __init hash_setup(char *str)
                        break;
                }
        }
+       if (i == HASH_ALGO__LAST)
+               return 1;
 out:
        hash_setup_done = 1;
        return 1;
-- 
2.11.0

Reply via email to