KEYS: trusted: Fix missing null return from kzalloc call
authorColin Ian King <colin.king@canonical.com>
Mon, 12 Apr 2021 16:01:01 +0000 (17:01 +0100)
committerJarkko Sakkinen <jarkko@kernel.org>
Wed, 14 Apr 2021 13:30:31 +0000 (16:30 +0300)
The kzalloc call can return null with the GFP_KERNEL flag so
add a null check and exit via a new error exit label. Use the
same exit error label for another error path too.

Addresses-Coverity: ("Dereference null return value")
Fixes: 830027e2cb55 ("KEYS: trusted: Add generic trusted keys framework")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Reviewed-by: Sumit Garg <sumit.garg@linaro.org>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
security/keys/trusted-keys/trusted_core.c

index ec3a066..9077479 100644 (file)
@@ -116,11 +116,13 @@ static struct trusted_key_payload *trusted_payload_alloc(struct key *key)
 
        ret = key_payload_reserve(key, sizeof(*p));
        if (ret < 0)
-               return p;
+               goto err;
        p = kzalloc(sizeof(*p), GFP_KERNEL);
+       if (!p)
+               goto err;
 
        p->migratable = migratable;
-
+err:
        return p;
 }