Skip to content

Commit

Permalink
security/keys: properly zero out sensitive key material in big_key
Browse files Browse the repository at this point in the history
Error paths forgot to zero out sensitive material, so this patch changes
some kfrees into a kzfrees.

Signed-off-by: Jason A. Donenfeld <[email protected]>
Signed-off-by: David Howells <[email protected]>
Reviewed-by: Eric Biggers <[email protected]>
Cc: Herbert Xu <[email protected]>
Cc: Kirill Marinushkin <[email protected]>
Cc: [email protected]
Cc: [email protected]
  • Loading branch information
zx2c4 authored and dhowells committed Sep 25, 2017
1 parent e007ce9 commit 9108018
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions security/keys/big_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ int big_key_preparse(struct key_preparsed_payload *prep)
*path = file->f_path;
path_get(path);
fput(file);
kfree(data);
kzfree(data);
} else {
/* Just store the data in a buffer */
void *data = kmalloc(datalen, GFP_KERNEL);
Expand All @@ -211,9 +211,9 @@ int big_key_preparse(struct key_preparsed_payload *prep)
err_fput:
fput(file);
err_enckey:
kfree(enckey);
kzfree(enckey);
error:
kfree(data);
kzfree(data);
return ret;
}

Expand All @@ -227,7 +227,7 @@ void big_key_free_preparse(struct key_preparsed_payload *prep)

path_put(path);
}
kfree(prep->payload.data[big_key_data]);
kzfree(prep->payload.data[big_key_data]);
}

/*
Expand Down Expand Up @@ -259,7 +259,7 @@ void big_key_destroy(struct key *key)
path->mnt = NULL;
path->dentry = NULL;
}
kfree(key->payload.data[big_key_data]);
kzfree(key->payload.data[big_key_data]);
key->payload.data[big_key_data] = NULL;
}

Expand Down Expand Up @@ -328,7 +328,7 @@ long big_key_read(const struct key *key, char __user *buffer, size_t buflen)
err_fput:
fput(file);
error:
kfree(data);
kzfree(data);
} else {
ret = datalen;
if (copy_to_user(buffer, key->payload.data[big_key_data],
Expand Down

0 comments on commit 9108018

Please sign in to comment.