Thread (6 messages) 6 messages, 4 authors, 2021-04-14

Re: [PATCH][next] KEYS: trusted: Fix missing null return from kzalloc call

From: Sumit Garg <hidden>
Date: 2021-04-13 05:29:08
Also in: kernel-janitors, keyrings, linux-integrity, lkml

On Mon, 12 Apr 2021 at 21:31, Colin King [off-list ref] wrote:
From: Colin Ian King <redacted>

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 <redacted>
---
 security/keys/trusted-keys/trusted_core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Ah, it's my bad. Thanks for fixing this issue.

Reviewed-by: Sumit Garg <redacted>

-Sumit
quoted hunk ↗ jump to hunk
diff --git a/security/keys/trusted-keys/trusted_core.c b/security/keys/trusted-keys/trusted_core.c
index ec3a066a4b42..90774793f0b1 100644
--- a/security/keys/trusted-keys/trusted_core.c
+++ b/security/keys/trusted-keys/trusted_core.c
@@ -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;
 }

--
2.30.2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help