crypto: s390/aes - Fix buffer overread in CTR mode
Subsystems (3)
Herbert Xu
maintainerWhen processing the last block, the s390 ctr code will always read a whole block, even if there isn't a whole block of data left. Fix this by using the actual length left and copy it into a buffer first for processing.
arch/s390/crypto/aes_s390.c +3 -1
@@ -597,7 +597,9 @@ static int ctr_aes_crypt(struct skcipher_request *req)* final block may be < AES_BLOCK_SIZE, copy only nbytes */ if (nbytes) { -cpacf_kmctr (sctx->fc, sctx->key, buf, walk.src.virt.addr, +memset (buf,0 ,AES_BLOCK_SIZE ); +memcpy (buf, walk.src.virt.addr, nbytes); +cpacf_kmctr (sctx->fc, sctx->key, buf, buf,AES_BLOCK_SIZE , walk.iv);memcpy (walk.dst.virt.addr, buf, nbytes);crypto_inc (walk.iv,AES_BLOCK_SIZE );
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Harald Freudenberger
maintainerQuoted 26 lines · Herbert Xu
When processing the last block, the s390 ctr code will always read a whole block, even if there isn't a whole block of data left. Fix this by using the actual length left and copy it into a buffer first for processing.
Fixes 0200f3ecc196 ("crypto: s390 - add System z hardware support forCTR mode")
Cc <[email protected]>Reported-by Guangwu Zhang <[email protected]>Signed-off-by Herbert Xu <[email protected]>arch/s390/crypto/aes_s390.c +3
-1@@ -597,7 +597,9 @@ static int ctr_aes_crypt(struct skcipher_request*req) * final block may be < AES_BLOCK_SIZE, copy only nbytes */ if (nbytes) { -cpacf_kmctr (sctx->fc, sctx->key, buf, walk.src.virt.addr, +memset (buf,0 ,AES_BLOCK_SIZE ); +memcpy (buf, walk.src.virt.addr, nbytes); +cpacf_kmctr (sctx->fc, sctx->key, buf, buf,AES_BLOCK_SIZE , walk.iv);memcpy (walk.dst.virt.addr, buf, nbytes);
Quoted 1 line
crypto_inc(walk.iv, AES_BLOCK_SIZE);
There is similar code in paes_s390.c. I'll send a patch for that.
Harald Freudenberger
maintainerQuoted 26 lines · Herbert Xu
When processing the last block, the s390 ctr code will always read a whole block, even if there isn't a whole block of data left. Fix this by using the actual length left and copy it into a buffer first for processing.
Fixes 0200f3ecc196 ("crypto: s390 - add System z hardware support forCTR mode")
Cc <[email protected]>Reported-by Guangwu Zhang <[email protected]>Signed-off-by Herbert Xu <[email protected]>arch/s390/crypto/aes_s390.c +3
-1@@ -597,7 +597,9 @@ static int ctr_aes_crypt(struct skcipher_request*req) * final block may be < AES_BLOCK_SIZE, copy only nbytes */ if (nbytes) { -cpacf_kmctr (sctx->fc, sctx->key, buf, walk.src.virt.addr, +memset (buf,0 ,AES_BLOCK_SIZE ); +memcpy (buf, walk.src.virt.addr, nbytes); +cpacf_kmctr (sctx->fc, sctx->key, buf, buf,AES_BLOCK_SIZE , walk.iv);memcpy (walk.dst.virt.addr, buf, nbytes);
Quoted 1 line
crypto_inc(walk.iv, AES_BLOCK_SIZE);
Here is a similar fix for the s390 paes ctr cipher. Compiles and is tested. You may merge this with your patch for the s390 aes cipher.
--------------------------------------------------------------------------------
arch/s390/crypto/paes_s390.c +3 -1
@@ -693,9 +693,11 @@ static int ctr_paes_crypt(struct skcipher_request *req)* final block may be < AES_BLOCK_SIZE, copy only nbytes */ if (nbytes) { +memset (buf,0 ,AES_BLOCK_SIZE ); +memcpy (buf, walk.src.virt.addr, nbytes);while (1 ) {if (cpacf_kmctr (ctx->fc, ¶m, buf, - walk.src.virt.addr,AES_BLOCK_SIZE , + buf,AES_BLOCK_SIZE , walk.iv) ==AES_BLOCK_SIZE )break ;if (__paes_convert_key (ctx))
Herbert Xu
maintainerQuoted 3 lines · Harald Freudenberger
Here is a similar fix for the s390 paes ctr cipher. Compiles and is tested. You may merge this with your patch for the s390 aes cipher.
Thank you. I had to apply this by hand so please check the result which I've just pushed out to cryptodev.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt