summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2010-07-26 01:29:04 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2010-07-26 01:30:24 +0200
commitbd29b1337fab4bb0ca41ff83271482bfe551d38b (patch)
tree19830e2fe93970f0861c5e21a936de36022d91f2
parent2c3943aab40b4c0b34809153c29f3a3a4eaebe72 (diff)
downloadkernel-crypto-bd29b1337fab4bb0ca41ff83271482bfe551d38b.tar.gz
kernel-crypto-bd29b1337fab4bb0ca41ff83271482bfe551d38b.tar.xz
kernel-crypto-bd29b1337fab4bb0ca41ff83271482bfe551d38b.zip
Corrected issue when finalizing sessions that hashed keys.
-rw-r--r--Makefile3
-rw-r--r--ncr-sessions-direct.c30
-rw-r--r--ncr-sessions.c62
-rw-r--r--ncr-sessions.h16
-rw-r--r--ncr.h4
5 files changed, 41 insertions, 74 deletions
diff --git a/Makefile b/Makefile
index 3b7ebf6bf8a..41c82c42e6a 100644
--- a/Makefile
+++ b/Makefile
@@ -67,8 +67,7 @@ TOMCRYPT_OBJECTS = libtomcrypt/misc/zeromem.o libtomcrypt/misc/crypt/crypt_argch
libtomcrypt/pk/asn1/der/x509/der_decode_subject_public_key_info.o
cryptodev-objs = cryptodev_main.o cryptodev_cipher.o ncr.o \
- ncr-key.o ncr-limits.o ncr-pk.o \
- ncr-sessions-direct.o ncr-sessions.o \
+ ncr-key.o ncr-limits.o ncr-pk.o ncr-sessions.o \
ncr-key-wrap.o ncr-key-storage.o $(TOMMATH_OBJECTS) \
$(TOMCRYPT_OBJECTS)
diff --git a/ncr-sessions-direct.c b/ncr-sessions-direct.c
deleted file mode 100644
index 3d41f1275cd..00000000000
--- a/ncr-sessions-direct.c
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * New driver for /dev/crypto device (aka CryptoDev)
-
- * Copyright (c) 2010 Nikos Mavrogiannopoulos <nmav@gnutls.org>
- *
- * This file is part of linux cryptodev.
- *
- * cryptodev is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * cryptodev is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <linux/crypto.h>
-#include "cryptodev.h"
-#include "ncr.h"
-#include "ncr-int.h"
-#include <linux/mm_types.h>
-#include <linux/scatterlist.h>
-#include <ncr-sessions.h>
-
-
diff --git a/ncr-sessions.c b/ncr-sessions.c
index 89863792327..f9043ec6ede 100644
--- a/ncr-sessions.c
+++ b/ncr-sessions.c
@@ -25,9 +25,9 @@
#include "ncr-int.h"
#include <linux/mm_types.h>
#include <linux/scatterlist.h>
-#include <ncr-sessions.h>
-static int _ncr_session_direct_update_key(struct ncr_lists* lists, struct ncr_session_op_st* op);
+static int _ncr_session_update_key(struct ncr_lists* lists, struct ncr_session_op_st* op);
+static void _ncr_session_remove(struct list_sem_st* lst, ncr_session_t desc);
void ncr_sessions_list_deinit(struct list_sem_st* lst)
{
@@ -491,16 +491,15 @@ void _ncr_session_remove(struct list_sem_st* lst, ncr_session_t desc)
/* Only the output buffer is given as scatterlist */
static int get_userbuf1(struct session_item_st* ses,
- struct ncr_session_op_st* op, struct scatterlist **dst_sg, unsigned *dst_cnt)
+ void __user * udata, size_t udata_size, struct scatterlist **dst_sg, unsigned *dst_cnt)
{
int pagecount = 0;
- if (op->data.udata.output == NULL) {
+ if (udata == NULL) {
return -EINVAL;
}
- pagecount = PAGECOUNT(op->data.udata.output, op->data.udata.output_size);
-
+ pagecount = PAGECOUNT(udata, udata_size);
ses->available_pages = pagecount;
@@ -520,7 +519,7 @@ static int get_userbuf1(struct session_item_st* ses,
}
}
- if (__get_userbuf(op->data.udata.output, op->data.udata.output_size, 1,
+ if (__get_userbuf(udata, udata_size, 1,
pagecount, ses->pages, ses->sg)) {
dprintk(1, KERN_ERR, "failed to get user pages for data input\n");
return -EINVAL;
@@ -608,7 +607,7 @@ static int get_userbuf2(struct session_item_st* ses,
}
/* Called when userspace buffers are used */
-int _ncr_session_direct_update(struct ncr_lists* lists, struct ncr_session_op_st* op)
+int _ncr_session_update(struct ncr_lists* lists, struct ncr_session_op_st* op)
{
int ret;
struct session_item_st* sess;
@@ -704,20 +703,20 @@ fail:
return ret;
}
-static int try_session_direct_update(struct ncr_lists* lists, struct ncr_session_op_st* op)
+static int try_session_update(struct ncr_lists* lists, struct ncr_session_op_st* op)
{
if (op->type == NCR_KEY_DATA) {
if (op->data.kdata.input != NCR_KEY_INVALID)
- return _ncr_session_direct_update_key(lists, op);
+ return _ncr_session_update_key(lists, op);
} else if (op->type == NCR_DIRECT_DATA) {
if (op->data.udata.input != NULL)
- return _ncr_session_direct_update(lists, op);
+ return _ncr_session_update(lists, op);
}
return 0;
}
-int _ncr_session_direct_final(struct ncr_lists* lists, struct ncr_session_op_st* op)
+int _ncr_session_final(struct ncr_lists* lists, struct ncr_session_op_st* op)
{
int ret;
struct session_item_st* sess;
@@ -728,6 +727,8 @@ int _ncr_session_direct_final(struct ncr_lists* lists, struct ncr_session_op_st*
unsigned osg_cnt=0;
size_t osg_size = 0;
size_t orig_osg_size;
+ void __user * udata = NULL;
+ size_t *udata_size;
sess = ncr_sessions_item_get( &lists->sessions, op->ses);
if (sess == NULL) {
@@ -735,7 +736,7 @@ int _ncr_session_direct_final(struct ncr_lists* lists, struct ncr_session_op_st*
return -EINVAL;
}
- ret = try_session_direct_update(lists, op);
+ ret = try_session_update(lists, op);
if (ret < 0) {
err();
_ncr_sessions_item_put(sess);
@@ -747,18 +748,30 @@ int _ncr_session_direct_final(struct ncr_lists* lists, struct ncr_session_op_st*
_ncr_sessions_item_put(sess);
return -ERESTARTSYS;
}
+
+ if (op->type == NCR_DIRECT_DATA) {
+ udata = op->data.udata.output;
+ udata_size = &op->data.udata.output_size;
+ } else if (op->type == NCR_KEY_DATA) {
+ udata = op->data.kdata.output;
+ udata_size = &op->data.kdata.output_size;
+ } else {
+ err();
+ ret = -EINVAL;
+ goto fail;
+ }
switch(sess->op) {
case NCR_OP_ENCRYPT:
case NCR_OP_DECRYPT:
break;
case NCR_OP_VERIFY:
- ret = get_userbuf1(sess, op, &osg, &osg_cnt);
+ ret = get_userbuf1(sess, udata, *udata_size, &osg, &osg_cnt);
if (ret < 0) {
err();
goto fail;
}
- orig_osg_size = osg_size = op->data.udata.output_size;
+ orig_osg_size = osg_size = *udata_size;
digest_size = sess->hash.digestsize;
if (digest_size == 0 || sizeof(digest) < digest_size) {
@@ -799,12 +812,12 @@ int _ncr_session_direct_final(struct ncr_lists* lists, struct ncr_session_op_st*
break;
case NCR_OP_SIGN:
- ret = get_userbuf1(sess, op, &osg, &osg_cnt);
+ ret = get_userbuf1(sess, udata, *udata_size, &osg, &osg_cnt);
if (ret < 0) {
err();
goto fail;
}
- orig_osg_size = osg_size = op->data.udata.output_size;
+ orig_osg_size = osg_size = *udata_size;
digest_size = sess->hash.digestsize;
if (digest_size == 0 || osg_size < digest_size) {
@@ -848,7 +861,7 @@ int _ncr_session_direct_final(struct ncr_lists* lists, struct ncr_session_op_st*
}
if (osg_size > 0)
- op->data.udata.output_size = osg_size;
+ *udata_size = osg_size;
ret = 0;
@@ -874,7 +887,7 @@ fail:
/* Direct with key: Allows to hash a key */
/* Called when userspace buffers are used */
-static int _ncr_session_direct_update_key(struct ncr_lists* lists, struct ncr_session_op_st* op)
+static int _ncr_session_update_key(struct ncr_lists* lists, struct ncr_session_op_st* op)
{
int ret;
struct session_item_st* sess;
@@ -908,7 +921,8 @@ static int _ncr_session_direct_update_key(struct ncr_lists* lists, struct ncr_se
return -ERESTARTSYS;
}
- ret = get_userbuf1(sess, op, &osg, &osg_cnt);
+ ret = get_userbuf1(sess, op->data.kdata.output, op->data.kdata.output_size,
+ &osg, &osg_cnt);
if (ret < 0) {
err();
goto fail;
@@ -962,9 +976,9 @@ int ncr_session_update(struct ncr_lists* lists, void __user* arg)
}
if (op.type == NCR_DIRECT_DATA)
- ret = _ncr_session_direct_update(lists, &op);
+ ret = _ncr_session_update(lists, &op);
else if (op.type == NCR_KEY_DATA)
- ret = _ncr_session_direct_update_key(lists, &op);
+ ret = _ncr_session_update_key(lists, &op);
else
ret = -EINVAL;
@@ -991,7 +1005,7 @@ int ncr_session_final(struct ncr_lists* lists, void __user* arg)
return -EFAULT;
}
- ret = _ncr_session_direct_final(lists, &op);
+ ret = _ncr_session_final(lists, &op);
if (unlikely(ret)) {
err();
return ret;
@@ -1021,7 +1035,7 @@ int ncr_session_once(struct ncr_lists* lists, void __user* arg)
}
kop.op.ses = kop.init.ses;
- ret = _ncr_session_direct_final(lists, &kop.op);
+ ret = _ncr_session_final(lists, &kop.op);
if (ret < 0) {
err();
return ret;
diff --git a/ncr-sessions.h b/ncr-sessions.h
deleted file mode 100644
index d6185aa5a04..00000000000
--- a/ncr-sessions.h
+++ /dev/null
@@ -1,16 +0,0 @@
-#ifndef NCR_SESSIONS_H
-# define NCR_SESSIONS_H
-
-int _ncr_session_direct_final(struct ncr_lists* lists, struct ncr_session_op_st* op);
-int _ncr_session_direct_update(struct ncr_lists* lists, struct ncr_session_op_st* op);
-
-int _ncr_session_encrypt(struct session_item_st* sess, const struct scatterlist* input, unsigned input_cnt,
- size_t input_size, void *output, unsigned output_cnt, size_t *output_size);
-
-int _ncr_session_decrypt(struct session_item_st* sess, const struct scatterlist* input,
- unsigned input_cnt, size_t input_size,
- struct scatterlist *output, unsigned output_cnt, size_t *output_size);
-
-void _ncr_session_remove(struct list_sem_st* lst, ncr_session_t desc);
-
-#endif
diff --git a/ncr.h b/ncr.h
index 3c87f591f9d..ccb0bb1d7a0 100644
--- a/ncr.h
+++ b/ncr.h
@@ -271,13 +271,13 @@ struct ncr_session_op_st {
* the place of the signature.
*/
size_t output_size;
- } kdata;
+ } kdata; /* NCR_KEY_DATA */
struct {
void* input;
size_t input_size;
void* output;
size_t output_size;
- } udata;
+ } udata; /* NCR_DIRECT_DATA */
} data;
ncr_data_type_t type;