diff mbox

crypto: testmgr - don't DMA map IV from stack in test_skcipher()

Message ID 1484290756-20868-1-git-send-email-horia.geanta@nxp.com (mailing list archive)
State Changes Requested
Delegated to: Herbert Xu
Headers show

Commit Message

Horia Geanta Jan. 13, 2017, 6:59 a.m. UTC
Fix the "DMA-API: device driver maps memory from stack" warning
generated when crypto accelerators map the IV.

Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
---
 crypto/testmgr.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Herbert Xu Jan. 13, 2017, 8:46 a.m. UTC | #1
On Fri, Jan 13, 2017 at 08:59:16AM +0200, Horia Geantă wrote:
> Fix the "DMA-API: device driver maps memory from stack" warning
> generated when crypto accelerators map the IV.
> 
> Signed-off-by: Horia Geantă <horia.geanta@nxp.com>

Hmm, the IV comes in as a pointer.  So you should not assume that
it can be DMAed at all.

Perhaps we should change the API so that it gets passed in as an
SG list.

Cheers,
Horia Geanta March 8, 2017, 1:04 p.m. UTC | #2
On 1/13/2017 10:46 AM, Herbert Xu wrote:
> On Fri, Jan 13, 2017 at 08:59:16AM +0200, Horia Geantă wrote:
>> Fix the "DMA-API: device driver maps memory from stack" warning
>> generated when crypto accelerators map the IV.
>>
>> Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
> 
> Hmm, the IV comes in as a pointer.  So you should not assume that
> it can be DMAed at all.
> 
That's correct, thanks for pointing it out.

> Perhaps we should change the API so that it gets passed in as an
> SG list.
> 
Since changing the API and converting the users looks pretty lengthy,
would it be acceptable to fix tcrypt for now?
Indeed, I've missed updating test_skcipher_speed, I can add this in v2.

Thanks,
Horia
Herbert Xu March 9, 2017, 4:18 a.m. UTC | #3
On Wed, Mar 08, 2017 at 01:04:14PM +0000, Horia Geantă wrote:
>
> Since changing the API and converting the users looks pretty lengthy,
> would it be acceptable to fix tcrypt for now?
> Indeed, I've missed updating test_skcipher_speed, I can add this in v2.

Might as well leave it there because at least it reminds us to
fix the problem.  With the API as it is any new kernel user could
potentially provide us with an IV off the stack.

Cheers,
diff mbox

Patch

diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index 500a5277cc22..64245aeef634 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -1081,12 +1081,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)
+		return ret;
+
 	if (testmgr_alloc_buf(xbuf))
 		goto out_nobuf;
 
@@ -1328,6 +1332,7 @@  static int __test_skcipher(struct crypto_skcipher *tfm, int enc,
 out_nooutbuf:
 	testmgr_free_buf(xbuf);
 out_nobuf:
+	kfree(iv);
 	return ret;
 }