mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] crypto: testmgr: don't allocate IV on stack
@ 2017-10-31  7:56 Gilad Ben-Yossef
  2017-10-31  7:59 ` Herbert Xu
  0 siblings, 1 reply; 5+ messages in thread
From: Gilad Ben-Yossef @ 2017-10-31  7:56 UTC (permalink / raw)
  To: Herbert Xu, David S. Miller; +Cc: Ofir Drang, linux-crypto, linux-kernel

The IV was allocated on the stack in testmgr skcipher tests.
Since HW based tfm providers need to DMA the IV to the HW,
this leads to problems and is detected by the DMA-API debug
code.

Fix it by allocating the IV using kmalloc instead.

Signed-off-by: Gilad Ben-Yossef <gilad@benyossef.com>
---
 crypto/testmgr.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index 7125ba3..88d0c57 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -1085,12 +1085,16 @@ static int __test_skcipher(struct crypto_skcipher *tfm, int enc,
 	const char *e, *d;
 	struct tcrypt_result result;
 	void *data;
-	char iv[MAX_IVLEN];
+	char *iv;
 	char *xbuf[XBUFSIZE];
 	char *xoutbuf[XBUFSIZE];
 	int ret = -ENOMEM;
 	unsigned int ivsize = crypto_skcipher_ivsize(tfm);
 
+	iv = kmalloc(MAX_IVLEN, GFP_KERNEL);
+	if (!iv)
+		goto out_nobuf;
+
 	if (testmgr_alloc_buf(xbuf))
 		goto out_nobuf;
 
@@ -1331,6 +1335,7 @@ static int __test_skcipher(struct crypto_skcipher *tfm, int enc,
 		testmgr_free_buf(xoutbuf);
 out_nooutbuf:
 	testmgr_free_buf(xbuf);
+	kfree(iv);
 out_nobuf:
 	return ret;
 }
-- 
2.7.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] crypto: testmgr: don't allocate IV on stack
  2017-10-31  7:56 [PATCH] crypto: testmgr: don't allocate IV on stack Gilad Ben-Yossef
@ 2017-10-31  7:59 ` Herbert Xu
  2017-10-31  8:05   ` Gilad Ben-Yossef
  2017-10-31  9:05   ` Horia Geantă
  0 siblings, 2 replies; 5+ messages in thread
From: Herbert Xu @ 2017-10-31  7:59 UTC (permalink / raw)
  To: Gilad Ben-Yossef; +Cc: David S. Miller, Ofir Drang, linux-crypto, linux-kernel

On Tue, Oct 31, 2017 at 07:56:26AM +0000, Gilad Ben-Yossef wrote:
> The IV was allocated on the stack in testmgr skcipher tests.
> Since HW based tfm providers need to DMA the IV to the HW,
> this leads to problems and is detected by the DMA-API debug
> code.
> 
> Fix it by allocating the IV using kmalloc instead.
> 
> Signed-off-by: Gilad Ben-Yossef <gilad@benyossef.com>

The driver that is mapping the IV directly should be fixed instead.
Only input that is given in the form of SG lists can be mapped.
Everything else should be copied if they need to go over DMA.

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] crypto: testmgr: don't allocate IV on stack
  2017-10-31  7:59 ` Herbert Xu
@ 2017-10-31  8:05   ` Gilad Ben-Yossef
  2017-10-31  9:05   ` Horia Geantă
  1 sibling, 0 replies; 5+ messages in thread
From: Gilad Ben-Yossef @ 2017-10-31  8:05 UTC (permalink / raw)
  To: Herbert Xu
  Cc: David S. Miller, Ofir Drang, Linux Crypto Mailing List,
	Linux kernel mailing list

On Tue, Oct 31, 2017 at 9:59 AM, Herbert Xu <herbert@gondor.apana.org.au> wrote:
> On Tue, Oct 31, 2017 at 07:56:26AM +0000, Gilad Ben-Yossef wrote:
>> The IV was allocated on the stack in testmgr skcipher tests.
>> Since HW based tfm providers need to DMA the IV to the HW,
>> this leads to problems and is detected by the DMA-API debug
>> code.
>>
>> Fix it by allocating the IV using kmalloc instead.
>>
>> Signed-off-by: Gilad Ben-Yossef <gilad@benyossef.com>
>
> The driver that is mapping the IV directly should be fixed instead.
> Only input that is given in the form of SG lists can be mapped.
> Everything else should be copied if they need to go over DMA.

Got it. Will do.

Thanks,
Gilad

>
> Cheers,
> --
> Email: Herbert Xu <herbert@gondor.apana.org.au>
> Home Page: http://gondor.apana.org.au/~herbert/
> PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt



-- 
Gilad Ben-Yossef
Chief Coffee Drinker

"If you take a class in large-scale robotics, can you end up in a
situation where the homework eats your dog?"
 -- Jean-Baptiste Queru

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] crypto: testmgr: don't allocate IV on stack
  2017-10-31  7:59 ` Herbert Xu
  2017-10-31  8:05   ` Gilad Ben-Yossef
@ 2017-10-31  9:05   ` Horia Geantă
  2017-10-31 10:19     ` Herbert Xu
  1 sibling, 1 reply; 5+ messages in thread
From: Horia Geantă @ 2017-10-31  9:05 UTC (permalink / raw)
  To: Herbert Xu, Gilad Ben-Yossef
  Cc: David S. Miller, Ofir Drang, linux-crypto, linux-kernel

On 10/31/2017 10:00 AM, Herbert Xu wrote:
> On Tue, Oct 31, 2017 at 07:56:26AM +0000, Gilad Ben-Yossef wrote:
>> The IV was allocated on the stack in testmgr skcipher tests.
>> Since HW based tfm providers need to DMA the IV to the HW,
>> this leads to problems and is detected by the DMA-API debug
>> code.
>>
>> Fix it by allocating the IV using kmalloc instead.
>>
>> Signed-off-by: Gilad Ben-Yossef <gilad@benyossef.com>
Gilad, you're not the only one who bumped into this issue:
https://www.mail-archive.com/linux-crypto@vger.kernel.org/msg23074.html
not to mention previous patches that have been accepted:
96692a7305c4 crypto: tcrypt - do not allocate iv on stack for aead speed
tests
9bac019dad80 crypto: testmgr - Fix DMA-API warning
and so on.

> 
> The driver that is mapping the IV directly should be fixed instead.
> Only input that is given in the form of SG lists can be mapped.
> Everything else should be copied if they need to go over DMA.
> 
Herbert, wouldn't it make more sense to follow your previous suggestion:
"Perhaps we should change the API so that it gets passed in as an
SG list."
https://www.mail-archive.com/linux-crypto@vger.kernel.org/msg23082.html

Thanks,
Horia

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] crypto: testmgr: don't allocate IV on stack
  2017-10-31  9:05   ` Horia Geantă
@ 2017-10-31 10:19     ` Herbert Xu
  0 siblings, 0 replies; 5+ messages in thread
From: Herbert Xu @ 2017-10-31 10:19 UTC (permalink / raw)
  To: Horia Geantă
  Cc: Gilad Ben-Yossef, David S. Miller, Ofir Drang, linux-crypto,
	linux-kernel

On Tue, Oct 31, 2017 at 09:05:57AM +0000, Horia Geantă wrote:
> > 
> > The driver that is mapping the IV directly should be fixed instead.
> > Only input that is given in the form of SG lists can be mapped.
> > Everything else should be copied if they need to go over DMA.
> > 
> Herbert, wouldn't it make more sense to follow your previous suggestion:
> "Perhaps we should change the API so that it gets passed in as an
> SG list."
> https://www.mail-archive.com/linux-crypto@vger.kernel.org/msg23082.html

Unless someone is willing to work on that then we have to fix the
drivers to fit the current API.

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-10-31 10:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-31  7:56 [PATCH] crypto: testmgr: don't allocate IV on stack Gilad Ben-Yossef
2017-10-31  7:59 ` Herbert Xu
2017-10-31  8:05   ` Gilad Ben-Yossef
2017-10-31  9:05   ` Horia Geantă
2017-10-31 10:19     ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®