path: root/common
diff options
authorSascha Hauer <>2019-10-01 23:36:26 +0200
committerSascha Hauer <>2019-10-15 14:55:11 +0200
commitd091a81f3ece732826dd4dec0b241624159ae1d6 (patch)
treed5b1cbb075851dc21c5009f9f7aeb1bf98790001 /common
parent128ad3cbe043d5153007a50f09208c25703257dd (diff)
rsa: let rsa_of_read_key() return a fully allocated key
Until now rsa_of_read_key() took a pointer to a key and filled the struct rsa_public_key members with allocated values. So far we have never freed these values. Change rsa_of_read_key() to always return a fully allocated key and provide rsa_key_free() to free it. Let the FIT image code free the key after usage. Signed-off-by: Sascha Hauer <>
Diffstat (limited to 'common')
1 files changed, 6 insertions, 4 deletions
diff --git a/common/image-fit.c b/common/image-fit.c
index 6ac4644..71053fb 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -269,7 +269,7 @@ static struct digest *fit_alloc_digest(struct device_node *sig_node,
static int fit_check_rsa_signature(struct device_node *sig_node,
enum hash_algo algo, void *hash)
- struct rsa_public_key key = {};
+ struct rsa_public_key *key;
const char *key_name;
char *key_path;
struct device_node *key_node;
@@ -296,18 +296,20 @@ static int fit_check_rsa_signature(struct device_node *sig_node,
- ret = rsa_of_read_key(key_node, &key);
- if (ret) {
+ key = rsa_of_read_key(key_node);
+ if (IS_ERR(key)) {
pr_info("failed to read key in %s\n", key_node->full_name);
return -ENOENT;
- ret = rsa_verify(&key, sig_value, sig_len, hash, algo);
+ ret = rsa_verify(key, sig_value, sig_len, hash, algo);
if (ret)
pr_err("image signature BAD\n");
pr_info("image signature OK\n");
+ rsa_key_free(key);
return ret;