Skip to content

Commit

Permalink
KEYS: trusted: Fix missing null return from kzalloc call
Browse files Browse the repository at this point in the history
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: 830027e ("KEYS: trusted: Add generic trusted keys framework")
Signed-off-by: Colin Ian King <[email protected]>
Reviewed-by: Sumit Garg <[email protected]>
Reviewed-by: Jarkko Sakkinen <[email protected]>
Signed-off-by: Jarkko Sakkinen <[email protected]>
  • Loading branch information
Colin Ian King authored and jarkkojs committed Apr 14, 2021
1 parent 3d785d7 commit aec00aa
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions security/keys/trusted-keys/trusted_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit aec00aa

Please sign in to comment.