mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-23 19:04:45 +03:00
ICP: AES-GCM: Refactor gcm_clear_ctx()
Currently the temporary buffer in which decryption takes place isn't cleared on context destruction. Further in some routines we fail to call gcm_clear_ctx() on error exit. Both flaws may result in leaking sensitive data. We follow best practices and zero out the plaintext buffer before freeing the memory holding it. Also move all cleanup into gcm_clear_ctx() and call it on any context destruction. The performance impact should be negligible. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Rob Norris <robn@despairlabs.com> Signed-off-by: Attila Fülöp <attila@fueloep.org> Closes #14528
This commit is contained in:
@@ -244,6 +244,38 @@ typedef struct gcm_ctx {
|
||||
#define AES_GMAC_IV_LEN 12
|
||||
#define AES_GMAC_TAG_BITS 128
|
||||
|
||||
/*
|
||||
* Clear sensitive data in the context and free allocated memory.
|
||||
*
|
||||
* ctx->gcm_remainder may contain a plaintext remainder. ctx->gcm_H and
|
||||
* ctx->gcm_Htable contain the hash sub key which protects authentication.
|
||||
* ctx->gcm_pt_buf contains the plaintext result of decryption.
|
||||
*
|
||||
* Although extremely unlikely, ctx->gcm_J0 and ctx->gcm_tmp could be used for
|
||||
* a known plaintext attack, they consists of the IV and the first and last
|
||||
* counter respectively. If they should be cleared is debatable.
|
||||
*/
|
||||
static inline void
|
||||
gcm_clear_ctx(gcm_ctx_t *ctx)
|
||||
{
|
||||
memset(ctx->gcm_remainder, 0, sizeof (ctx->gcm_remainder));
|
||||
memset(ctx->gcm_H, 0, sizeof (ctx->gcm_H));
|
||||
#if defined(CAN_USE_GCM_ASM)
|
||||
if (ctx->gcm_use_avx == B_TRUE) {
|
||||
ASSERT3P(ctx->gcm_Htable, !=, NULL);
|
||||
memset(ctx->gcm_Htable, 0, ctx->gcm_htab_len);
|
||||
kmem_free(ctx->gcm_Htable, ctx->gcm_htab_len);
|
||||
}
|
||||
#endif
|
||||
if (ctx->gcm_pt_buf != NULL) {
|
||||
memset(ctx->gcm_pt_buf, 0, ctx->gcm_pt_buf_len);
|
||||
vmem_free(ctx->gcm_pt_buf, ctx->gcm_pt_buf_len);
|
||||
}
|
||||
/* Optional */
|
||||
memset(ctx->gcm_J0, 0, sizeof (ctx->gcm_J0));
|
||||
memset(ctx->gcm_tmp, 0, sizeof (ctx->gcm_tmp));
|
||||
}
|
||||
|
||||
typedef struct aes_ctx {
|
||||
union {
|
||||
ecb_ctx_t acu_ecb;
|
||||
|
||||
Reference in New Issue
Block a user