summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2010-07-07 08:31:14 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2010-07-07 08:31:14 +0200
commit58a20b797e5a987fc8f7c5bea3be24d754908bf5 (patch)
tree8f3d54711c4685da083826b3422f0d9dd46ae452
parentd12ecf68276ab0e57ea578d763f23b2143e57ed8 (diff)
downloadcryptodev-linux-58a20b797e5a987fc8f7c5bea3be24d754908bf5.tar.gz
cryptodev-linux-58a20b797e5a987fc8f7c5bea3be24d754908bf5.tar.xz
cryptodev-linux-58a20b797e5a987fc8f7c5bea3be24d754908bf5.zip
set_iv() function accepts argument from kernel memory.
-rw-r--r--cryptodev_cipher.c4
-rw-r--r--cryptodev_int.h2
-rw-r--r--cryptodev_main.c11
3 files changed, 11 insertions, 6 deletions
diff --git a/cryptodev_cipher.c b/cryptodev_cipher.c
index bbd79d9..0dd2f10 100644
--- a/cryptodev_cipher.c
+++ b/cryptodev_cipher.c
@@ -127,9 +127,9 @@ void cryptodev_cipher_deinit(struct cipher_data* cdata)
cdata->init = 0;
}
-int cryptodev_cipher_set_iv(struct cipher_data* cdata, void __user* iv, size_t iv_size)
+void cryptodev_cipher_set_iv(struct cipher_data* cdata, void __user* iv, size_t iv_size)
{
- return copy_from_user(cdata->async.iv, iv, min(iv_size,sizeof(cdata->async.iv)));
+ memcpy(cdata->async.iv, iv, min(iv_size,sizeof(cdata->async.iv)));
}
static inline int waitfor (struct cryptodev_result* cr, ssize_t ret)
diff --git a/cryptodev_int.h b/cryptodev_int.h
index c686150..2901d59 100644
--- a/cryptodev_int.h
+++ b/cryptodev_int.h
@@ -41,7 +41,7 @@ void cryptodev_cipher_deinit(struct cipher_data* cdata);
ssize_t cryptodev_cipher_decrypt( struct cipher_data* cdata, struct scatterlist *sg1, struct scatterlist *sg2, size_t len);
ssize_t cryptodev_cipher_encrypt( struct cipher_data* cdata, struct scatterlist *sg1, struct scatterlist *sg2, size_t len);
-int cryptodev_cipher_set_iv(struct cipher_data* cdata, void* iv, size_t iv_size);
+void cryptodev_cipher_set_iv(struct cipher_data* cdata, void* iv, size_t iv_size);
int _cryptodev_cipher_decrypt(struct cipher_data* cdata, const void* ciphertext,
size_t ciphertext_size, void* plaintext, size_t plaintext_size);
int _cryptodev_cipher_encrypt(struct cipher_data* cdata, const void* plaintext,
diff --git a/cryptodev_main.c b/cryptodev_main.c
index 00f598c..f99c71a 100644
--- a/cryptodev_main.c
+++ b/cryptodev_main.c
@@ -426,10 +426,15 @@ crypto_run(struct fcrypt *fcr, struct crypt_op *cop)
goto out_unlock;
}
- ivsize = ses_ptr->cdata.ivsize;
-
if (cop->iv) {
- cryptodev_cipher_set_iv(&ses_ptr->cdata, cop->iv, ivsize);
+ uint8_t iv[EALG_MAX_BLOCK_LEN];
+
+ ivsize = min((int)sizeof(iv), ses_ptr->cdata.ivsize);
+ ret = copy_from_user(iv, cop->iv, ivsize);
+ if (unlikely(ret))
+ goto out_unlock;
+
+ cryptodev_cipher_set_iv(&ses_ptr->cdata, iv, ivsize);
}
}