[PATCH] security: keys: add NULL checking for key->type->instantiate
From: Geliang Tang
Date: Fri Jan 25 2019 - 02:16:45 EST
key->type->instantiate can be NULL, add NULL checking to prevent
NULL pointer dereference in __key_instantiate_and_link().
Signed-off-by: Geliang Tang <geliangtang@xxxxxxxxx>
---
security/keys/key.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/security/keys/key.c b/security/keys/key.c
index 44a80d6741a1..ae3cc11be0d2 100644
--- a/security/keys/key.c
+++ b/security/keys/key.c
@@ -438,7 +438,8 @@ static int __key_instantiate_and_link(struct key *key,
/* can't instantiate twice */
if (key->state == KEY_IS_UNINSTANTIATED) {
/* instantiate the key */
- ret = key->type->instantiate(key, prep);
+ if (key->type->instantiate)
+ ret = key->type->instantiate(key, prep);
if (ret == 0) {
/* mark the key as being instantiated */
--
2.17.1