Skip to content

Commit 3ac34ca

Browse files
AttilaFueloepbehlendorf
authored andcommitted
ICP: Fix out of bounds write
If gcm_mode_encrypt_contiguous_blocks() is called more than once in succession, with the accumulated lengths being less than blocksize, ctx->copy_to will be incorrectly advanced. Later, if out is NULL, the bcopy at line 114 will overflow ctx->gcm_copy_to since ctx->gcm_remainder_len is larger than the ctx->gcm_copy_to buffer can hold. The fix is to set ctx->copy_to only if it's not already set. For ZoL the issue may be academic, since in all my testing I wasn't able to hit neither of both conditions needed to trigger it, but other consumers can easily do so. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Tom Caputi <[email protected]> Signed-off-by: Attila Fülöp <[email protected]> Closes #9660
1 parent f784828 commit 3ac34ca

File tree

1 file changed

+3
-1
lines changed
  • module/icp/algs/modes

1 file changed

+3
-1
lines changed

module/icp/algs/modes/gcm.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ gcm_mode_encrypt_contiguous_blocks(gcm_ctx_t *ctx, char *data, size_t length,
6767
(uint8_t *)ctx->gcm_remainder + ctx->gcm_remainder_len,
6868
length);
6969
ctx->gcm_remainder_len += length;
70-
ctx->gcm_copy_to = datap;
70+
if (ctx->gcm_copy_to == NULL) {
71+
ctx->gcm_copy_to = datap;
72+
}
7173
return (CRYPTO_SUCCESS);
7274
}
7375

0 commit comments

Comments
 (0)