summaryrefslogtreecommitdiffstats
path: root/recipes-kernel/cryptodev/sdk_patches/0036-add-compat-for-CIOCHASH-operation.patch
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-kernel/cryptodev/sdk_patches/0036-add-compat-for-CIOCHASH-operation.patch')
-rw-r--r--recipes-kernel/cryptodev/sdk_patches/0036-add-compat-for-CIOCHASH-operation.patch120
1 files changed, 120 insertions, 0 deletions
diff --git a/recipes-kernel/cryptodev/sdk_patches/0036-add-compat-for-CIOCHASH-operation.patch b/recipes-kernel/cryptodev/sdk_patches/0036-add-compat-for-CIOCHASH-operation.patch
new file mode 100644
index 0000000..c206995
--- /dev/null
+++ b/recipes-kernel/cryptodev/sdk_patches/0036-add-compat-for-CIOCHASH-operation.patch
@@ -0,0 +1,120 @@
1From 711529cc7b8743ae8c9c0db4980ac15f7acb8618 Mon Sep 17 00:00:00 2001
2From: Alex Porosanu <alexandru.porosanu@nxp.com>
3Date: Tue, 12 Jan 2016 14:51:00 +0200
4Subject: [PATCH 36/38] add compat for CIOCHASH operation
5
6This patch adds the necessary ioctl for using the CIOCHASH
7operation for different userspace & kernel (i.e. 32b userspace
8and 64b kernel).
9
10Signed-off-by: Alex Porosanu <alexandru.porosanu@nxp.com>
11---
12 cryptodev_int.h | 14 +++++++++++++-
13 ioctl.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
14 2 files changed, 63 insertions(+), 1 deletion(-)
15
16diff --git a/cryptodev_int.h b/cryptodev_int.h
17index 74c295a..6dcfd69 100644
18--- a/cryptodev_int.h
19+++ b/cryptodev_int.h
20@@ -129,6 +129,18 @@ struct compat_crypt_auth_op {
21 uint32_t iv_len;
22 };
23
24+struct compat_hash_op_data {
25+ compat_uptr_t ses;
26+ uint32_t mac_op; /* cryptodev_crypto_op_t */
27+ compat_uptr_t mackey;
28+ uint32_t mackeylen;
29+
30+ uint16_t flags; /* see COP_FLAG_* */
31+ uint32_t len; /* length of source data */
32+ compat_uptr_t src; /* source data */
33+ compat_uptr_t mac_result;
34+};
35+
36 /* compat ioctls, defined for the above structs */
37 #define COMPAT_CIOCGSESSION _IOWR('c', 102, struct compat_session_op)
38 #define COMPAT_CIOCCRYPT _IOWR('c', 104, struct compat_crypt_op)
39@@ -139,7 +151,7 @@ struct compat_crypt_auth_op {
40 #define COMPAT_CIOCASYMASYNCRYPT _IOW('c', 110, struct compat_crypt_kop)
41 #define COMPAT_CIOCASYMFETCHCOOKIE _IOR('c', 111, \
42 struct compat_pkc_cookie_list_s)
43-
44+#define COMPAT_CIOCHASH _IOWR('c', 114, struct compat_hash_op_data)
45 #endif /* CONFIG_COMPAT */
46
47 /* kernel-internal extension to struct crypt_kop */
48diff --git a/ioctl.c b/ioctl.c
49index a052614..ff3de44 100644
50--- a/ioctl.c
51+++ b/ioctl.c
52@@ -1435,8 +1435,11 @@ cryptodev_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg_)
53 struct fcrypt *fcr;
54 struct session_op sop;
55 struct compat_session_op compat_sop;
56+ struct kernel_hash_op khop;
57 struct kernel_crypt_op kcop;
58 struct kernel_crypt_auth_op kcaop;
59+ struct compat_hash_op_data compat_hash_op_data;
60+
61 int ret;
62
63 if (unlikely(!pcr))
64@@ -1499,6 +1502,53 @@ cryptodev_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg_)
65
66 return compat_kcop_to_user(&kcop, fcr, arg);
67
68+ case COMPAT_CIOCHASH:
69+ /* get session */
70+ if (unlikely(copy_from_user(&compat_hash_op_data, arg,
71+ sizeof(struct compat_hash_op_data)))) {
72+ pr_err("copy from user fault\n");
73+ return -EFAULT;
74+ }
75+
76+ khop.task = current;
77+ khop.mm = current->mm;
78+
79+ khop.hash_op.mac_op = compat_hash_op_data.mac_op;
80+ khop.hash_op.mackey = compat_ptr(compat_hash_op_data.mackey);
81+ khop.hash_op.mackeylen = compat_hash_op_data.mackeylen;
82+ khop.hash_op.flags = compat_hash_op_data.flags;
83+ khop.hash_op.len = compat_hash_op_data.len;
84+ khop.hash_op.src = compat_ptr(compat_hash_op_data.src);
85+ khop.hash_op.mac_result =
86+ compat_ptr(compat_hash_op_data.mac_result);
87+
88+ ret = hash_create_session(&khop.hash_op);
89+ if (unlikely(ret)) {
90+ pr_err("can't get session\n");
91+ return ret;
92+ }
93+
94+ /* do hashing */
95+ ret = hash_run(&khop);
96+ if (unlikely(ret)) {
97+ dwarning(1, "Error in hash run");
98+ return ret;
99+ }
100+
101+ ret = copy_to_user(khop.hash_op.mac_result, khop.hash_output,
102+ khop.digestsize);
103+ if (unlikely(ret)) {
104+ dwarning(1, "Error in copy to user");
105+ return ret;
106+ }
107+
108+ copy_to_user(arg, &compat_hash_op_data,
109+ sizeof(struct compat_hash_op_data));
110+
111+ /* put session */
112+ hash_destroy_session(khop.hash_op.ses);
113+ return 0;
114+
115 case COMPAT_CIOCAUTHCRYPT:
116 if (unlikely(ret = compat_kcaop_from_user(&kcaop, fcr, arg))) {
117 dprintk(1, KERN_WARNING, "Error copying from user\n");
118--
1192.7.0
120