crypto: make sure *blkcipher_walk_init properly initialises walk
PATCH RESEND 1/1 crypto: make sure *blkcipher_walk_init properly initialises walk
From: Michal Nazarewicz <[email protected]>
blkcipher_walk_init and ablkcipher_walk_init functions are called to initialise a walk structure allocated on stack, which is not initialised by the caller. This means, that the fields of the structure contain garbage when *_init is run.
The *_init functions do not initialise all of the fields though, and in particular leave flags field as is. This results in field containing unspecified value.
Zeroing the whole structure makes sure that all of the fields are initialised to the same value regardless of the values stored on the stack prior to the call to the *_init function.
--- crypto/blkcipher.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
crypto/blkcipher.c +3 -3
@@ -305,7 +305,7 @@ static inline int blkcipher_copy_iv(struct blkcipher_walk *walk,int blkcipher_walk_virt (struct blkcipher_desc *desc,struct blkcipher_walk *walk) { - walk->flags &= ~BLKCIPHER_WALK_PHYS ; + walk->flags =0 ; walk->blocksize =crypto_blkcipher_blocksize (desc->tfm);return blkcipher_walk_first (desc, walk); }
@@ -314,7 +314,7 @@ EXPORT_SYMBOL_GPL(blkcipher_walk_virt);int blkcipher_walk_phys (struct blkcipher_desc *desc,struct blkcipher_walk *walk) { - walk->flags |=BLKCIPHER_WALK_PHYS ; + walk->flags =BLKCIPHER_WALK_PHYS ; walk->blocksize =crypto_blkcipher_blocksize (desc->tfm);return blkcipher_walk_first (desc, walk); }
@@ -352,7 +352,7 @@ int blkcipher_walk_virt_block(struct blkcipher_desc *desc,struct blkcipher_walk *walk, unsigned int blocksize) { - walk->flags &= ~BLKCIPHER_WALK_PHYS; + walk->flags = 0; walk->blocksize = blocksize;return blkcipher_walk_first (desc, walk); }
Signature · 1 line
1.8.3.2
Quoted 11 lines · Michal Nazarewicz
From: Michal Nazarewicz <[email protected]>
blkcipher_walk_initandablkcipher_walk_initfunctions are called to initialise a walk structure allocated on stack, which is not initialised by the caller. This means, that the fields of the structure contain garbage when*_initis run.The
*_initfunctions do not initialise all of the fields though, and in particular leave flags field as is. This results in field containing unspecified value.
Quoted 5 lines
Zeroing the whole structure makes sure that all of the fields are initialised to the same value regardless of the values stored on the stack prior to the call to the
*_initfunction.Signed-off-by Michal Nazarewicz <[email protected]>
Nack. The field flags is used as a bit-field and all bits other than those initialised that you see are used internally by the walker function and will be initialised on demand.
Please do not just rely on tools such as coverity and actually read the code when submitting patches.
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
Quoted 6 lines · Herbert Xu
Nack. The field flags is used as a bit-field and all bits other than those initialised that you see are used internally by the walker function and will be initialised on demand.
Please do not just rely on tools such as coverity and actually read the code when submitting patches.
I have read the code which is why I concluded that it is safe to replace the bit operations with a simple assignment. Since, as you described, all other bit fields are initialised on demand anyway, there is no harm in setting them to zero here. Especially since I see no advantages of the current approach, but instead see two disadvantages: longer machine code (load-modiy-store vs. store) and confusion of tools such as Coverity.
But of course, if you want it as it is, I won't be bothering you.
Signature · 4 lines
Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michał “mina86” Nazarewicz (o o) ooo +--<[email protected]>--<xmpp:[email protected]>--ooO--(_)--Ooo--