crypto: skcipher - Fix skcipher_walk_aead_common
Subsystems (2)
PATCH 1/1 crypto: skcipher - Fix skcipher_walk_aead_common
The skcipher_walk_aead_common function calls scatterwalk_copychunks on the input and output walks to skip the associated data. If the AD end at an SG list entry boundary, then after these calls the walks will still be pointing to the end of the skipped region.
These offsets are later checked for alignment in skcipher_walk_next, so the skcipher_walk may detect the alignment incorrectly.
This patch fixes it by calling scatterwalk_done after the copychunks calls to ensure that the offsets refer to the right SG list entry.
--- crypto/skcipher.c | 3 +++ 1 file changed, 3 insertions(+)
crypto/skcipher.c +3 -0
@@ -517,6 +517,9 @@ static int skcipher_walk_aead_common(struct skcipher_walk *walk,scatterwalk_copychunks (NULL , &walk->in, req->assoclen,2 );scatterwalk_copychunks (NULL , &walk->out, req->assoclen,2 ); +scatterwalk_done (&walk->in,0 , walk->total); +scatterwalk_done (&walk->out,0 , walk->total); + walk->iv = req->iv; walk->oiv = req->iv;
Signature · 1 line
2.14.1
Herbert Xu
maintainerQuoted 8 lines · Ondrej Mosnacek
The
skcipher_walk_aead_commonfunction callsscatterwalk_copychunkson the input and output walks to skip the associated data. If the AD end at an SG list entry boundary, then after these calls the walks will still be pointing to the end of the skipped region.These offsets are later checked for alignment in
skcipher_walk_next, so theskcipher_walkmay detect the alignment incorrectly.
Quoted 6 lines
This patch fixes it by calling
scatterwalk_doneafter the copychunks calls to ensure that the offsets refer to the right SG list entry.Fixes b286d8b1a690 ("crypto: skcipher - Add skcipher walk interface")Cc <[email protected]>Signed-off-by Ondrej Mosnacek <[email protected]>
Good catch!
crypto/skcipher.c static int skcipher_walk_aead_common(struct skcipher_walk *walk, · line 521
Quoted 10 lines
crypto/skcipher.c +2
-0@@ -517,6 +517,9 @@ static int skcipher_walk_aead_common(struct skcipher_walk *walk,scatterwalk_copychunks (NULL , &walk->in, req->assoclen,2 );scatterwalk_copychunks (NULL , &walk->out, req->assoclen,2 ); +scatterwalk_done (&walk->in,0 , walk->total); +scatterwalk_done (&walk->out,0 , walk->total);
That should be 1 instead of 0 for walk->out.
Could you please fix and resubmit?
Thanks,
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
(I accidentally hit "reply" instead of "reply all", so resending)
2017-11-24 6:07 GMT+01:00 Herbert Xu <[email protected]>:
Quoted 9 lines · Ondrej Mosnacek
Quoted 8 lines
crypto/skcipher.c +0
-0@@ -517,6 +517,9 @@ static int skcipher_walk_aead_common(struct skcipher_walk *walk,scatterwalk_copychunks (NULL , &walk->in, req->assoclen,2 );scatterwalk_copychunks (NULL , &walk->out, req->assoclen,2 );
Quoted 6 lines
crypto/skcipher.c static int skcipher_walk_aead_common(struct skcipher_walk *walk, · line 521
Quoted 2 lines
crypto/skcipher.c +2
-0+scatterwalk_done (&walk->in,0 , walk->total); +scatterwalk_done (&walk->out,0 , walk->total);That should be 1 instead of 0 for
walk->out.Could you please fix and resubmit?
Since the associated data is not written, just skipped, I believe 0 is more appropriate. scatterwalk_copychunks(..., 2) also calls scatterwalk_pagedone() with out=0 internally.
O.M.
Herbert Xu
maintainerQuoted 17 lines · Ondrej Mosnáček
(I accidentally hit "reply" instead of "reply all", so resending)
2017-11-24 6:07 GMT+01:00 Herbert Xu <[email protected]>:
Quoted 14 lines · Ondrej Mosnacek
crypto/skcipher.c static int skcipher_walk_aead_common(struct skcipher_walk *walk, · line 521
Quoted 10 lines
crypto/skcipher.c +2
-0@@ -517,6 +517,9 @@ static int skcipher_walk_aead_common(struct skcipher_walk *walk,scatterwalk_copychunks (NULL , &walk->in, req->assoclen,2 );scatterwalk_copychunks (NULL , &walk->out, req->assoclen,2 ); +scatterwalk_done (&walk->in,0 , walk->total); +scatterwalk_done (&walk->out,0 , walk->total);That should be 1 instead of 0 for
walk->out.
Quoted 5 lines
Quoted 1 line
Could you please fix and resubmit?
Since the associated data is not written, just skipped, I believe 0 is more appropriate.
scatterwalk_copychunks(..., 2)also callsscatterwalk_pagedone()with out=0 internally.
Thanks for the explanation.
Patch applied.
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