<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Hi Li,</p>
<p>Thanks for having a look at my patch. To my knowledge <i>pthread_timedjoin_np</i>
does not kill the thread if it times out. It returns ETIMEDOUT
which, in this case, leads to the whole testcase terminating.</p>
<p>I chose this method over setting test.timeout because this way an
informative error-message can be printed.</p>
<p>I may be missing the problem here. Can you point me in the right
direction why this is bad practice?</p>
<p>Kind regards,</p>
<p>Christian<br>
</p>
<p><br>
</p>
<div class="moz-cite-prefix">On 07/05/2019 10:07, Li Wang wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAEemH2e=9J_7OtSsS5wq+4YgfOm1zj=PK5cnaBk69LKtdR71ZA@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<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" moz-do-not-send="true">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"
moz-do-not-send="true">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" moz-do-not-send="true">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" moz-do-not-send="true">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>
<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"
moz-do-not-send="true">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>
</blockquote>
</body>
</html>