summaryrefslogtreecommitdiffstats
path: root/meta/recipes-kernel
diff options
context:
space:
mode:
authorHongzhi.Song <hongzhi.song@windriver.com>2018-08-22 01:37:12 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2018-08-23 07:50:00 +0100
commit01f70f02650221242d4ba629337c882ad28bf9a2 (patch)
tree9db347469df4fab01d7e7774809009b1a8a24085 /meta/recipes-kernel
parent744b05919127c1a5ab7501ad5630db575b0cda48 (diff)
downloadpoky-01f70f02650221242d4ba629337c882ad28bf9a2.tar.gz
cryptodev-linux: Fixes a kernel crash observed with cipher-gcm test
The crypto API for AEAD ciphers changed in recent kernels, so that associated data is now part of both source and destination scatter gathers. The source, destination and associated data buffers need to be stiched accordingly for the operations to succeed. (From OE-Core rev: 76da04571b8cb2241b3f46dec4935ff299639b7d) Signed-off-by: Hongzhi.Song <hongzhi.song@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-kernel')
-rw-r--r--meta/recipes-kernel/cryptodev/cryptodev-module_1.9.bb3
-rw-r--r--meta/recipes-kernel/cryptodev/files/0001-refactoring-split-big-function-to-simplify-maintaina.patch250
-rw-r--r--meta/recipes-kernel/cryptodev/files/0002-refactoring-relocate-code-to-simplify-later-patches.patch64
-rw-r--r--meta/recipes-kernel/cryptodev/files/0003-convert-to-new-AEAD-interface-in-kernels-v4.2.patch102
4 files changed, 419 insertions, 0 deletions
diff --git a/meta/recipes-kernel/cryptodev/cryptodev-module_1.9.bb b/meta/recipes-kernel/cryptodev/cryptodev-module_1.9.bb
index 6052650c95..ed4327d40d 100644
--- a/meta/recipes-kernel/cryptodev/cryptodev-module_1.9.bb
+++ b/meta/recipes-kernel/cryptodev/cryptodev-module_1.9.bb
@@ -11,6 +11,9 @@ SRC_URI += " \
11file://0001-Disable-installing-header-file-provided-by-another-p.patch \ 11file://0001-Disable-installing-header-file-provided-by-another-p.patch \
12file://0001-ioctl.c-Fix-build-with-linux-4.13.patch \ 12file://0001-ioctl.c-Fix-build-with-linux-4.13.patch \
13file://0001-ioctl.c-Fix-build-with-linux-4.17.patch \ 13file://0001-ioctl.c-Fix-build-with-linux-4.17.patch \
14file://0001-refactoring-split-big-function-to-simplify-maintaina.patch \
15file://0002-refactoring-relocate-code-to-simplify-later-patches.patch \
16file://0003-convert-to-new-AEAD-interface-in-kernels-v4.2.patch \
14" 17"
15 18
16EXTRA_OEMAKE='KERNEL_DIR="${STAGING_KERNEL_DIR}" PREFIX="${D}"' 19EXTRA_OEMAKE='KERNEL_DIR="${STAGING_KERNEL_DIR}" PREFIX="${D}"'
diff --git a/meta/recipes-kernel/cryptodev/files/0001-refactoring-split-big-function-to-simplify-maintaina.patch b/meta/recipes-kernel/cryptodev/files/0001-refactoring-split-big-function-to-simplify-maintaina.patch
new file mode 100644
index 0000000000..f557b5dff6
--- /dev/null
+++ b/meta/recipes-kernel/cryptodev/files/0001-refactoring-split-big-function-to-simplify-maintaina.patch
@@ -0,0 +1,250 @@
1From 20dcf071bc3076ee7db9d603cfbe6a06e86c7d5f Mon Sep 17 00:00:00 2001
2From: Cristian Stoica <cristian.stoica@nxp.com>
3Date: Thu, 4 May 2017 15:06:20 +0300
4Subject: [PATCH 1/3] refactoring: split big function to simplify maintainance
5
6The setup of auth_buf in tls and aead is now duplicated but this
7is temporary and allows necessary corrections for the aead case
8with v4.2+ kernels.
9
10Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com>
11
12Upstream-Status: Backport
13
14Commit ID: 20dcf071bc3076ee7db9d603c
15
16Signed-off-by: Hongzhi.Song <hongzhi.song@windriver.com>
17---
18 authenc.c | 197 ++++++++++++++++++++++++++++++++++++++++----------------------
19 1 file changed, 126 insertions(+), 71 deletions(-)
20
21diff --git a/authenc.c b/authenc.c
22index 1bd7377..28eb0f9 100644
23--- a/authenc.c
24+++ b/authenc.c
25@@ -609,96 +609,151 @@ auth_n_crypt(struct csession *ses_ptr, struct kernel_crypt_auth_op *kcaop,
26 return 0;
27 }
28
29-/* This is the main crypto function - zero-copy edition */
30-static int
31-__crypto_auth_run_zc(struct csession *ses_ptr, struct kernel_crypt_auth_op *kcaop)
32+static int crypto_auth_zc_srtp(struct csession *ses_ptr, struct kernel_crypt_auth_op *kcaop)
33 {
34- struct scatterlist *dst_sg, *auth_sg, *src_sg;
35+ struct scatterlist *dst_sg, *auth_sg;
36 struct crypt_auth_op *caop = &kcaop->caop;
37- int ret = 0;
38+ int ret;
39
40- if (caop->flags & COP_FLAG_AEAD_SRTP_TYPE) {
41- if (unlikely(ses_ptr->cdata.init != 0 &&
42- (ses_ptr->cdata.stream == 0 ||
43- ses_ptr->cdata.aead != 0))) {
44- derr(0, "Only stream modes are allowed in SRTP mode (but not AEAD)");
45- return -EINVAL;
46- }
47+ if (unlikely(ses_ptr->cdata.init != 0 &&
48+ (ses_ptr->cdata.stream == 0 || ses_ptr->cdata.aead != 0))) {
49+ derr(0, "Only stream modes are allowed in SRTP mode (but not AEAD)");
50+ return -EINVAL;
51+ }
52
53- ret = get_userbuf_srtp(ses_ptr, kcaop, &auth_sg, &dst_sg);
54- if (unlikely(ret)) {
55- derr(1, "get_userbuf_srtp(): Error getting user pages.");
56- return ret;
57- }
58+ ret = get_userbuf_srtp(ses_ptr, kcaop, &auth_sg, &dst_sg);
59+ if (unlikely(ret)) {
60+ derr(1, "get_userbuf_srtp(): Error getting user pages.");
61+ return ret;
62+ }
63
64- ret = srtp_auth_n_crypt(ses_ptr, kcaop, auth_sg, caop->auth_len,
65- dst_sg, caop->len);
66+ ret = srtp_auth_n_crypt(ses_ptr, kcaop, auth_sg, caop->auth_len,
67+ dst_sg, caop->len);
68
69- release_user_pages(ses_ptr);
70- } else { /* TLS and normal cases. Here auth data are usually small
71- * so we just copy them to a free page, instead of trying
72- * to map them.
73- */
74- unsigned char *auth_buf = NULL;
75- struct scatterlist tmp;
76+ release_user_pages(ses_ptr);
77
78- if (unlikely(caop->auth_len > PAGE_SIZE)) {
79- derr(1, "auth data len is excessive.");
80- return -EINVAL;
81- }
82+ return ret;
83+}
84
85- auth_buf = (char *)__get_free_page(GFP_KERNEL);
86- if (unlikely(!auth_buf)) {
87- derr(1, "unable to get a free page.");
88- return -ENOMEM;
89- }
90+static int crypto_auth_zc_tls(struct csession *ses_ptr, struct kernel_crypt_auth_op *kcaop)
91+{
92+ struct crypt_auth_op *caop = &kcaop->caop;
93+ struct scatterlist *dst_sg, *auth_sg;
94+ unsigned char *auth_buf = NULL;
95+ struct scatterlist tmp;
96+ int ret;
97
98- if (caop->auth_src && caop->auth_len > 0) {
99- if (unlikely(copy_from_user(auth_buf, caop->auth_src, caop->auth_len))) {
100- derr(1, "unable to copy auth data from userspace.");
101- ret = -EFAULT;
102- goto free_auth_buf;
103- }
104+ if (unlikely(ses_ptr->cdata.aead != 0)) {
105+ return -EINVAL;
106+ }
107+
108+ if (unlikely(caop->auth_len > PAGE_SIZE)) {
109+ derr(1, "auth data len is excessive.");
110+ return -EINVAL;
111+ }
112+
113+ auth_buf = (char *)__get_free_page(GFP_KERNEL);
114+ if (unlikely(!auth_buf)) {
115+ derr(1, "unable to get a free page.");
116+ return -ENOMEM;
117+ }
118
119- sg_init_one(&tmp, auth_buf, caop->auth_len);
120- auth_sg = &tmp;
121- } else {
122- auth_sg = NULL;
123+ if (caop->auth_src && caop->auth_len > 0) {
124+ if (unlikely(copy_from_user(auth_buf, caop->auth_src, caop->auth_len))) {
125+ derr(1, "unable to copy auth data from userspace.");
126+ ret = -EFAULT;
127+ goto free_auth_buf;
128 }
129
130- if (caop->flags & COP_FLAG_AEAD_TLS_TYPE && ses_ptr->cdata.aead == 0) {
131- ret = get_userbuf_tls(ses_ptr, kcaop, &dst_sg);
132- if (unlikely(ret)) {
133- derr(1, "get_userbuf_tls(): Error getting user pages.");
134- goto free_auth_buf;
135- }
136+ sg_init_one(&tmp, auth_buf, caop->auth_len);
137+ auth_sg = &tmp;
138+ } else {
139+ auth_sg = NULL;
140+ }
141
142- ret = tls_auth_n_crypt(ses_ptr, kcaop, auth_sg, caop->auth_len,
143- dst_sg, caop->len);
144- } else {
145- if (unlikely(ses_ptr->cdata.init == 0 ||
146- (ses_ptr->cdata.stream == 0 &&
147- ses_ptr->cdata.aead == 0))) {
148- derr(0, "Only stream and AEAD ciphers are allowed for authenc");
149- ret = -EINVAL;
150- goto free_auth_buf;
151- }
152+ ret = get_userbuf_tls(ses_ptr, kcaop, &dst_sg);
153+ if (unlikely(ret)) {
154+ derr(1, "get_userbuf_tls(): Error getting user pages.");
155+ goto free_auth_buf;
156+ }
157
158- ret = get_userbuf(ses_ptr, caop->src, caop->len, caop->dst, kcaop->dst_len,
159- kcaop->task, kcaop->mm, &src_sg, &dst_sg);
160- if (unlikely(ret)) {
161- derr(1, "get_userbuf(): Error getting user pages.");
162- goto free_auth_buf;
163- }
164+ ret = tls_auth_n_crypt(ses_ptr, kcaop, auth_sg, caop->auth_len,
165+ dst_sg, caop->len);
166+ release_user_pages(ses_ptr);
167+
168+free_auth_buf:
169+ free_page((unsigned long)auth_buf);
170+ return ret;
171+}
172+
173+static int crypto_auth_zc_aead(struct csession *ses_ptr, struct kernel_crypt_auth_op *kcaop)
174+{
175+ struct scatterlist *dst_sg, *auth_sg, *src_sg;
176+ struct crypt_auth_op *caop = &kcaop->caop;
177+ unsigned char *auth_buf = NULL;
178+ struct scatterlist tmp;
179+ int ret;
180
181- ret = auth_n_crypt(ses_ptr, kcaop, auth_sg, caop->auth_len,
182- src_sg, dst_sg, caop->len);
183+ if (unlikely(ses_ptr->cdata.init == 0 ||
184+ (ses_ptr->cdata.stream == 0 && ses_ptr->cdata.aead == 0))) {
185+ derr(0, "Only stream and AEAD ciphers are allowed for authenc");
186+ return -EINVAL;
187+ }
188+
189+ if (unlikely(caop->auth_len > PAGE_SIZE)) {
190+ derr(1, "auth data len is excessive.");
191+ return -EINVAL;
192+ }
193+
194+ auth_buf = (char *)__get_free_page(GFP_KERNEL);
195+ if (unlikely(!auth_buf)) {
196+ derr(1, "unable to get a free page.");
197+ return -ENOMEM;
198+ }
199+
200+ if (caop->auth_src && caop->auth_len > 0) {
201+ if (unlikely(copy_from_user(auth_buf, caop->auth_src, caop->auth_len))) {
202+ derr(1, "unable to copy auth data from userspace.");
203+ ret = -EFAULT;
204+ goto free_auth_buf;
205 }
206
207- release_user_pages(ses_ptr);
208+ sg_init_one(&tmp, auth_buf, caop->auth_len);
209+ auth_sg = &tmp;
210+ } else {
211+ auth_sg = NULL;
212+ }
213+
214+ ret = get_userbuf(ses_ptr, caop->src, caop->len, caop->dst, kcaop->dst_len,
215+ kcaop->task, kcaop->mm, &src_sg, &dst_sg);
216+ if (unlikely(ret)) {
217+ derr(1, "get_userbuf(): Error getting user pages.");
218+ goto free_auth_buf;
219+ }
220+
221+ ret = auth_n_crypt(ses_ptr, kcaop, auth_sg, caop->auth_len,
222+ src_sg, dst_sg, caop->len);
223+
224+ release_user_pages(ses_ptr);
225
226 free_auth_buf:
227- free_page((unsigned long)auth_buf);
228+ free_page((unsigned long)auth_buf);
229+
230+ return ret;
231+}
232+
233+static int
234+__crypto_auth_run_zc(struct csession *ses_ptr, struct kernel_crypt_auth_op *kcaop)
235+{
236+ struct crypt_auth_op *caop = &kcaop->caop;
237+ int ret;
238+
239+ if (caop->flags & COP_FLAG_AEAD_SRTP_TYPE) {
240+ ret = crypto_auth_zc_srtp(ses_ptr, kcaop);
241+ } else if (caop->flags & COP_FLAG_AEAD_TLS_TYPE) {
242+ ret = crypto_auth_zc_tls(ses_ptr, kcaop);
243+ } else {
244+ ret = crypto_auth_zc_aead(ses_ptr, kcaop);
245 }
246
247 return ret;
248--
2492.11.0
250
diff --git a/meta/recipes-kernel/cryptodev/files/0002-refactoring-relocate-code-to-simplify-later-patches.patch b/meta/recipes-kernel/cryptodev/files/0002-refactoring-relocate-code-to-simplify-later-patches.patch
new file mode 100644
index 0000000000..83d9005a06
--- /dev/null
+++ b/meta/recipes-kernel/cryptodev/files/0002-refactoring-relocate-code-to-simplify-later-patches.patch
@@ -0,0 +1,64 @@
1From c2bf0e42b1d9fda60cde4a3a682784d349ef1c0b Mon Sep 17 00:00:00 2001
2From: Cristian Stoica <cristian.stoica@nxp.com>
3Date: Thu, 4 May 2017 15:06:21 +0300
4Subject: [PATCH 2/3] refactoring: relocate code to simplify later patches
5
6This code move will simplify the conversion to new AEAD interface in
7next patches
8
9Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com>
10
11Upstream-Status: Backport
12
13Commit ID: c2bf0e42b1d9fda
14
15Signed-off-by: Hongzhi.Song <hongzhi.song@windriver.com>
16---
17 authenc.c | 17 +++++++++--------
18 1 file changed, 9 insertions(+), 8 deletions(-)
19
20diff --git a/authenc.c b/authenc.c
21index 28eb0f9..95727b4 100644
22--- a/authenc.c
23+++ b/authenc.c
24@@ -711,11 +711,18 @@ static int crypto_auth_zc_aead(struct csession *ses_ptr, struct kernel_crypt_aut
25 return -ENOMEM;
26 }
27
28+ ret = get_userbuf(ses_ptr, caop->src, caop->len, caop->dst, kcaop->dst_len,
29+ kcaop->task, kcaop->mm, &src_sg, &dst_sg);
30+ if (unlikely(ret)) {
31+ derr(1, "get_userbuf(): Error getting user pages.");
32+ goto free_auth_buf;
33+ }
34+
35 if (caop->auth_src && caop->auth_len > 0) {
36 if (unlikely(copy_from_user(auth_buf, caop->auth_src, caop->auth_len))) {
37 derr(1, "unable to copy auth data from userspace.");
38 ret = -EFAULT;
39- goto free_auth_buf;
40+ goto free_pages;
41 }
42
43 sg_init_one(&tmp, auth_buf, caop->auth_len);
44@@ -724,16 +731,10 @@ static int crypto_auth_zc_aead(struct csession *ses_ptr, struct kernel_crypt_aut
45 auth_sg = NULL;
46 }
47
48- ret = get_userbuf(ses_ptr, caop->src, caop->len, caop->dst, kcaop->dst_len,
49- kcaop->task, kcaop->mm, &src_sg, &dst_sg);
50- if (unlikely(ret)) {
51- derr(1, "get_userbuf(): Error getting user pages.");
52- goto free_auth_buf;
53- }
54-
55 ret = auth_n_crypt(ses_ptr, kcaop, auth_sg, caop->auth_len,
56 src_sg, dst_sg, caop->len);
57
58+free_pages:
59 release_user_pages(ses_ptr);
60
61 free_auth_buf:
62--
632.11.0
64
diff --git a/meta/recipes-kernel/cryptodev/files/0003-convert-to-new-AEAD-interface-in-kernels-v4.2.patch b/meta/recipes-kernel/cryptodev/files/0003-convert-to-new-AEAD-interface-in-kernels-v4.2.patch
new file mode 100644
index 0000000000..860230778b
--- /dev/null
+++ b/meta/recipes-kernel/cryptodev/files/0003-convert-to-new-AEAD-interface-in-kernels-v4.2.patch
@@ -0,0 +1,102 @@
1From a705360197260d28535746ae98c461ba2cfb7a9e Mon Sep 17 00:00:00 2001
2From: Cristian Stoica <cristian.stoica@nxp.com>
3Date: Thu, 4 May 2017 15:06:22 +0300
4Subject: [PATCH 3/3] convert to new AEAD interface in kernels v4.2+
5
6The crypto API for AEAD ciphers changed in recent kernels so that
7associated data is now part of both source and destination scatter
8gathers. The source, destination and associated data buffers need
9to be stiched accordingly for the operations to succeed:
10
11src_sg: auth_buf + src_buf
12dst_sg: auth_buf + (dst_buf + tag space)
13
14This patch fixes a kernel crash observed with cipher-gcm test.
15
16See also kernel patch: 81c4c35eb61a69c229871c490b011c1171511d5a
17 crypto: ccm - Convert to new AEAD interface
18
19Reported-by: Phil Sutter <phil@nwl.cc>
20Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com>
21
22Upstream-Status: Backport
23
24Commit ID: a705360197260d2853574
25
26Signed-off-by: Hongzhi.Song <hongzhi.song@windriver.com>
27---
28 authenc.c | 40 ++++++++++++++++++++++++++++++++++++++--
29 1 file changed, 38 insertions(+), 2 deletions(-)
30
31diff --git a/authenc.c b/authenc.c
32index 95727b4..692951f 100644
33--- a/authenc.c
34+++ b/authenc.c
35@@ -688,12 +688,20 @@ free_auth_buf:
36
37 static int crypto_auth_zc_aead(struct csession *ses_ptr, struct kernel_crypt_auth_op *kcaop)
38 {
39- struct scatterlist *dst_sg, *auth_sg, *src_sg;
40+ struct scatterlist *dst_sg;
41+ struct scatterlist *src_sg;
42 struct crypt_auth_op *caop = &kcaop->caop;
43 unsigned char *auth_buf = NULL;
44- struct scatterlist tmp;
45 int ret;
46
47+#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 2, 0))
48+ struct scatterlist tmp;
49+ struct scatterlist *auth_sg;
50+#else
51+ struct scatterlist auth1[2];
52+ struct scatterlist auth2[2];
53+#endif
54+
55 if (unlikely(ses_ptr->cdata.init == 0 ||
56 (ses_ptr->cdata.stream == 0 && ses_ptr->cdata.aead == 0))) {
57 derr(0, "Only stream and AEAD ciphers are allowed for authenc");
58@@ -718,6 +726,7 @@ static int crypto_auth_zc_aead(struct csession *ses_ptr, struct kernel_crypt_aut
59 goto free_auth_buf;
60 }
61
62+#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 2, 0))
63 if (caop->auth_src && caop->auth_len > 0) {
64 if (unlikely(copy_from_user(auth_buf, caop->auth_src, caop->auth_len))) {
65 derr(1, "unable to copy auth data from userspace.");
66@@ -733,6 +742,33 @@ static int crypto_auth_zc_aead(struct csession *ses_ptr, struct kernel_crypt_aut
67
68 ret = auth_n_crypt(ses_ptr, kcaop, auth_sg, caop->auth_len,
69 src_sg, dst_sg, caop->len);
70+#else
71+ if (caop->auth_src && caop->auth_len > 0) {
72+ if (unlikely(copy_from_user(auth_buf, caop->auth_src, caop->auth_len))) {
73+ derr(1, "unable to copy auth data from userspace.");
74+ ret = -EFAULT;
75+ goto free_pages;
76+ }
77+
78+ sg_init_table(auth1, 2);
79+ sg_set_buf(auth1, auth_buf, caop->auth_len);
80+ sg_chain(auth1, 2, src_sg);
81+
82+ if (src_sg == dst_sg) {
83+ src_sg = auth1;
84+ dst_sg = auth1;
85+ } else {
86+ sg_init_table(auth2, 2);
87+ sg_set_buf(auth2, auth_buf, caop->auth_len);
88+ sg_chain(auth2, 2, dst_sg);
89+ src_sg = auth1;
90+ dst_sg = auth2;
91+ }
92+ }
93+
94+ ret = auth_n_crypt(ses_ptr, kcaop, NULL, caop->auth_len,
95+ src_sg, dst_sg, caop->len);
96+#endif
97
98 free_pages:
99 release_user_pages(ses_ptr);
100--
1012.11.0
102