linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] KEYS: trusted: Fix missing null return from kzalloc call
@ 2021-04-12 16:01 Colin King
  2021-04-12 16:48 ` James Bottomley
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Colin King @ 2021-04-12 16:01 UTC (permalink / raw)
  To: James Bottomley, Jarkko Sakkinen, Mimi Zohar, David Howells,
	James Morris, Serge E . Hallyn, Sumit Garg, linux-integrity,
	keyrings, linux-security-module
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

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>
---
 security/keys/trusted-keys/trusted_core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-04-14 11:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-12 16:01 [PATCH][next] KEYS: trusted: Fix missing null return from kzalloc call Colin King
2021-04-12 16:48 ` James Bottomley
2021-04-12 17:04   ` Colin Ian King
2021-04-13  5:42     ` Sumit Garg
2021-04-13  5:28 ` Sumit Garg
2021-04-14 11:07 ` Jarkko Sakkinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).