<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small">Hi Christian,</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 7, 2019 at 2:56 PM Christian Amann <<a href="mailto:camann@suse.com">camann@suse.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On kernels < 4.14 (missing commit 2d97591ef43d) reading from<br>
the request socket does not return and the testcase does not<br>
finish.<br>
<br>
This fix moves the logic to a child thread in order for the<br>
parent to handle the timeout and report a message to the user.<br>
<br>
Signed-off-by: Christian Amann <<a href="mailto:camann@suse.com" target="_blank">camann@suse.com</a>><br>
---<br>
testcases/kernel/crypto/Makefile | 2 ++<br>
testcases/kernel/crypto/af_alg02.c | 36 +++++++++++++++++++++++++++++++++++-<br>
2 files changed, 37 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/testcases/kernel/crypto/Makefile b/testcases/kernel/crypto/Makefile<br>
index 76f9308c2..6547e1cb6 100644<br>
--- a/testcases/kernel/crypto/Makefile<br>
+++ b/testcases/kernel/crypto/Makefile<br>
@@ -20,3 +20,5 @@ include $(top_srcdir)/include/mk/<a href="http://testcases.mk" rel="noreferrer" target="_blank">testcases.mk</a><br>
CFLAGS += -D_GNU_SOURCE<br>
<br>
include $(top_srcdir)/include/mk/<a href="http://generic_leaf_target.mk" rel="noreferrer" target="_blank">generic_leaf_target.mk</a><br>
+<br>
+af_alg02: CFLAGS += -pthread<br>
diff --git a/testcases/kernel/crypto/af_alg02.c b/testcases/kernel/crypto/af_alg02.c<br>
index a9e820423..056511993 100644<br>
--- a/testcases/kernel/crypto/af_alg02.c<br>
+++ b/testcases/kernel/crypto/af_alg02.c<br>
@@ -7,12 +7,23 @@<br>
* Regression test for commit ecaaab564978 ("crypto: salsa20 - fix<br>
* blkcipher_walk API usage"), or CVE-2017-17805. This test verifies that an<br>
* empty message can be encrypted with Salsa20 without crashing the kernel.<br>
+ *<br>
+ * read() fix:<br>
+ * Calls read() in child thread in order to manually kill it after timeout.<br>
+ * With kernels missing commit 2d97591ef43d ("crypto: af_alg - consolidation<br>
+ * of duplicate code") read() does not return.<br>
*/<br>
<br>
#include "tst_test.h"<br>
#include "tst_af_alg.h"<br>
+#include "tst_safe_pthread.h"<br>
+#include <pthread.h><br>
+#include <time.h><br>
+#include <errno.h><br>
<br>
-static void run(void)<br>
+#define VERIFY_TIMEOUT (time(NULL) + 5)<br></blockquote><div><br></div><div class="gmail_default" style="font-size:small">It is very neccessary to take some action before process being killed in timeout. In LTP, we have an tst_timeout_remaining() function. Have a look?</div><div class="gmail_default" style="font-size:small"></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+void *verify_encrypt(void *arg)<br>
{<br>
char buf[16];<br>
int reqfd = tst_alg_setup_reqfd("skcipher", "salsa20", NULL, 16);<br>
@@ -22,6 +33,29 @@ static void run(void)<br>
tst_res(TPASS, "Successfully \"encrypted\" an empty message");<br>
else<br>
tst_res(TBROK, "read() didn't return 0");<br>
+ return arg;<br>
+}<br>
+<br>
+static void run(void)<br>
+{<br>
+ pthread_t thr;<br>
+ int join_ret;<br>
+ struct timespec read_timeout;<br>
+<br>
+ read_timeout.tv_sec = VERIFY_TIMEOUT;<br>
+ read_timeout.tv_nsec = 0;<br>
+<br>
+ SAFE_PTHREAD_CREATE(&thr, NULL, verify_encrypt, NULL);<br>
+ join_ret = pthread_timedjoin_np(thr, NULL, &read_timeout);<br>
+<br>
+ if (join_ret != 0) {<br>
+ if (join_ret == ETIMEDOUT)<br>
+ tst_brk(TBROK,<br>
+ "Timed out while reading from request socket.");<br>
+ else<br>
+ tst_brk(TBROK | TTERRNO,<br>
+ "Error while joining child thread");<br>
+ }<br>
}<br>
<br>
static struct tst_test test = {<br>
-- <br>
2.16.4<br>
<br>
<br>
-- <br>
Mailing list info: <a href="https://lists.linux.it/listinfo/ltp" rel="noreferrer" target="_blank">https://lists.linux.it/listinfo/ltp</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div></div></div>