diff options
Diffstat (limited to 'recipes-kernel/cryptodev/sdk_patches/0004-Compat-versions-of-PKC-IOCTLs.patch')
-rw-r--r-- | recipes-kernel/cryptodev/sdk_patches/0004-Compat-versions-of-PKC-IOCTLs.patch | 200 |
1 files changed, 200 insertions, 0 deletions
diff --git a/recipes-kernel/cryptodev/sdk_patches/0004-Compat-versions-of-PKC-IOCTLs.patch b/recipes-kernel/cryptodev/sdk_patches/0004-Compat-versions-of-PKC-IOCTLs.patch new file mode 100644 index 0000000..e963f58 --- /dev/null +++ b/recipes-kernel/cryptodev/sdk_patches/0004-Compat-versions-of-PKC-IOCTLs.patch | |||
@@ -0,0 +1,200 @@ | |||
1 | From e0e5c1bfb21888bf9f87f72ac8cdf7eee951f619 Mon Sep 17 00:00:00 2001 | ||
2 | From: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
3 | Date: Fri, 7 Mar 2014 06:52:13 +0545 | ||
4 | Subject: [PATCH 04/38] Compat versions of PKC IOCTLs | ||
5 | |||
6 | Upstream-status: Pending | ||
7 | |||
8 | Signed-off-by: Yashpal Dutta <yashpal.dutta@freescale.com> | ||
9 | --- | ||
10 | cryptodev_int.h | 20 ++++++++++ | ||
11 | ioctl.c | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
12 | 2 files changed, 140 insertions(+) | ||
13 | |||
14 | diff --git a/cryptodev_int.h b/cryptodev_int.h | ||
15 | index fdbcc61..cf54dac 100644 | ||
16 | --- a/cryptodev_int.h | ||
17 | +++ b/cryptodev_int.h | ||
18 | @@ -75,6 +75,24 @@ struct compat_crypt_op { | ||
19 | compat_uptr_t iv;/* initialization vector for encryption operations */ | ||
20 | }; | ||
21 | |||
22 | +/* input of CIOCKEY */ | ||
23 | +struct compat_crparam { | ||
24 | + compat_uptr_t crp_p; | ||
25 | + uint32_t crp_nbits; | ||
26 | +}; | ||
27 | + | ||
28 | +struct compat_crypt_kop { | ||
29 | + uint32_t crk_op; /* cryptodev_crk_ot_t */ | ||
30 | + uint32_t crk_status; | ||
31 | + uint16_t crk_iparams; | ||
32 | + uint16_t crk_oparams; | ||
33 | + uint32_t crk_pad1; | ||
34 | + struct compat_crparam crk_param[CRK_MAXPARAM]; | ||
35 | + enum curve_t curve_type; /* 0 == Discrete Log, 1 = EC_PRIME, | ||
36 | + 2 = EC_BINARY */ | ||
37 | + compat_uptr_t cookie; | ||
38 | +}; | ||
39 | + | ||
40 | /* input of CIOCAUTHCRYPT */ | ||
41 | struct compat_crypt_auth_op { | ||
42 | uint32_t ses; /* session identifier */ | ||
43 | @@ -111,6 +129,8 @@ struct compat_crypt_auth_op { | ||
44 | #define COMPAT_CIOCASYNCCRYPT _IOW('c', 107, struct compat_crypt_op) | ||
45 | #define COMPAT_CIOCASYNCFETCH _IOR('c', 108, struct compat_crypt_op) | ||
46 | #define COMPAT_CIOCAUTHCRYPT _IOWR('c', 109, struct compat_crypt_auth_op) | ||
47 | +#define COMPAT_CIOCASYMASYNCRYPT _IOW('c', 110, struct compat_crypt_kop) | ||
48 | +#define COMPAT_CIOCASYMASYNFETCH _IOR('c', 111, struct compat_crypt_kop) | ||
49 | |||
50 | #endif /* CONFIG_COMPAT */ | ||
51 | |||
52 | diff --git a/ioctl.c b/ioctl.c | ||
53 | index 69980e3..9431025 100644 | ||
54 | --- a/ioctl.c | ||
55 | +++ b/ioctl.c | ||
56 | @@ -1081,6 +1081,68 @@ cryptodev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg_) | ||
57 | /* compatibility code for 32bit userlands */ | ||
58 | #ifdef CONFIG_COMPAT | ||
59 | |||
60 | +static inline void compat_to_crypt_kop(struct compat_crypt_kop *compat, | ||
61 | + struct crypt_kop *kop) | ||
62 | +{ | ||
63 | + int i; | ||
64 | + kop->crk_op = compat->crk_op; | ||
65 | + kop->crk_status = compat->crk_status; | ||
66 | + kop->crk_iparams = compat->crk_iparams; | ||
67 | + kop->crk_oparams = compat->crk_oparams; | ||
68 | + | ||
69 | + for (i = 0; i < CRK_MAXPARAM; i++) { | ||
70 | + kop->crk_param[i].crp_p = | ||
71 | + compat_ptr(compat->crk_param[i].crp_p); | ||
72 | + kop->crk_param[i].crp_nbits = compat->crk_param[i].crp_nbits; | ||
73 | + } | ||
74 | + | ||
75 | + kop->curve_type = compat->curve_type; | ||
76 | + kop->cookie = compat->cookie; | ||
77 | +} | ||
78 | + | ||
79 | +static int compat_kop_from_user(struct kernel_crypt_kop *kop, | ||
80 | + void __user *arg) | ||
81 | +{ | ||
82 | + struct compat_crypt_kop compat_kop; | ||
83 | + | ||
84 | + if (unlikely(copy_from_user(&compat_kop, arg, sizeof(compat_kop)))) | ||
85 | + return -EFAULT; | ||
86 | + | ||
87 | + compat_to_crypt_kop(&compat_kop, &kop->kop); | ||
88 | + return fill_kop_from_cop(kop); | ||
89 | +} | ||
90 | + | ||
91 | +static inline void crypt_kop_to_compat(struct crypt_kop *kop, | ||
92 | + struct compat_crypt_kop *compat) | ||
93 | +{ | ||
94 | + int i; | ||
95 | + | ||
96 | + compat->crk_op = kop->crk_op; | ||
97 | + compat->crk_status = kop->crk_status; | ||
98 | + compat->crk_iparams = kop->crk_iparams; | ||
99 | + compat->crk_oparams = kop->crk_oparams; | ||
100 | + | ||
101 | + for (i = 0; i < CRK_MAXPARAM; i++) { | ||
102 | + compat->crk_param[i].crp_p = | ||
103 | + ptr_to_compat(kop->crk_param[i].crp_p); | ||
104 | + compat->crk_param[i].crp_nbits = kop->crk_param[i].crp_nbits; | ||
105 | + } | ||
106 | + compat->cookie = kop->cookie; | ||
107 | + compat->curve_type = kop->curve_type; | ||
108 | +} | ||
109 | + | ||
110 | +static int compat_kop_to_user(struct kernel_crypt_kop *kop, void __user *arg) | ||
111 | +{ | ||
112 | + struct compat_crypt_kop compat_kop; | ||
113 | + | ||
114 | + crypt_kop_to_compat(&kop->kop, &compat_kop); | ||
115 | + if (unlikely(copy_to_user(arg, &compat_kop, sizeof(compat_kop)))) { | ||
116 | + dprintk(1, KERN_ERR, "Cannot copy to userspace\n"); | ||
117 | + return -EFAULT; | ||
118 | + } | ||
119 | + return 0; | ||
120 | +} | ||
121 | + | ||
122 | static inline void | ||
123 | compat_to_session_op(struct compat_session_op *compat, struct session_op *sop) | ||
124 | { | ||
125 | @@ -1208,7 +1270,26 @@ cryptodev_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg_) | ||
126 | return -EFAULT; | ||
127 | } | ||
128 | return ret; | ||
129 | + case COMPAT_CIOCKEY: | ||
130 | + { | ||
131 | + struct cryptodev_pkc *pkc = | ||
132 | + kzalloc(sizeof(struct cryptodev_pkc), GFP_KERNEL); | ||
133 | + | ||
134 | + if (!pkc) | ||
135 | + return -ENOMEM; | ||
136 | + | ||
137 | + ret = compat_kop_from_user(&pkc->kop, arg); | ||
138 | + | ||
139 | + if (unlikely(ret)) { | ||
140 | + kfree(pkc); | ||
141 | + return ret; | ||
142 | + } | ||
143 | |||
144 | + pkc->type = SYNCHRONOUS; | ||
145 | + ret = crypto_run_asym(pkc); | ||
146 | + kfree(pkc); | ||
147 | + } | ||
148 | + return ret; | ||
149 | case COMPAT_CIOCCRYPT: | ||
150 | ret = compat_kcop_from_user(&kcop, fcr, arg); | ||
151 | if (unlikely(ret)) | ||
152 | @@ -1247,6 +1328,45 @@ cryptodev_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg_) | ||
153 | |||
154 | return compat_kcop_to_user(&kcop, fcr, arg); | ||
155 | #endif | ||
156 | + case COMPAT_CIOCASYMASYNCRYPT: | ||
157 | + { | ||
158 | + struct cryptodev_pkc *pkc = | ||
159 | + kzalloc(sizeof(struct cryptodev_pkc), GFP_KERNEL); | ||
160 | + | ||
161 | + ret = compat_kop_from_user(&pkc->kop, arg); | ||
162 | + if (unlikely(ret)) | ||
163 | + return -EINVAL; | ||
164 | + | ||
165 | + /* Store associated FD priv data with asymmetric request */ | ||
166 | + pkc->priv = pcr; | ||
167 | + pkc->type = ASYNCHRONOUS; | ||
168 | + ret = crypto_run_asym(pkc); | ||
169 | + if (ret == -EINPROGRESS) | ||
170 | + ret = 0; | ||
171 | + } | ||
172 | + return ret; | ||
173 | + case COMPAT_CIOCASYMASYNFETCH: | ||
174 | + { | ||
175 | + struct cryptodev_pkc *pkc; | ||
176 | + unsigned long flags; | ||
177 | + | ||
178 | + spin_lock_irqsave(&pcr->completion_lock, flags); | ||
179 | + if (list_empty(&pcr->asym_completed_list)) { | ||
180 | + spin_unlock_irqrestore(&pcr->completion_lock, flags); | ||
181 | + return -ENOMEM; | ||
182 | + } | ||
183 | + pkc = list_first_entry(&pcr->asym_completed_list, | ||
184 | + struct cryptodev_pkc, list); | ||
185 | + list_del(&pkc->list); | ||
186 | + spin_unlock_irqrestore(&pcr->completion_lock, flags); | ||
187 | + ret = crypto_async_fetch_asym(pkc); | ||
188 | + | ||
189 | + /* Reflect the updated request to user-space */ | ||
190 | + if (!ret) | ||
191 | + compat_kop_to_user(&pkc->kop, arg); | ||
192 | + kfree(pkc); | ||
193 | + } | ||
194 | + return ret; | ||
195 | default: | ||
196 | return -EINVAL; | ||
197 | } | ||
198 | -- | ||
199 | 2.7.0 | ||
200 | |||