<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><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 7:41 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">@ Li Wang<br>
<br>
Okay, I think I understand it now. It looks much cleaner when done like<br>
you suggested. Thanks!<br></blockquote><div><br></div><div class="gmail_default" style="font-size:small">Thanks for your update, you could try add these additional info in patch note  via `git note add` next time.</div><div class="gmail_default" style="font-size:small">  # man git-notes</div><div class="gmail_default" style="font-size:small"><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Regards,<br>
<br>
Christian<br>
<br>
<br>
On 07/05/2019 13:38, Christian Amann wrote:<br>
> 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 | 29 ++++++++++++++++++++++++++++-<br>
>  2 files changed, 30 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..7f8c81b66 100644<br>
> --- a/testcases/kernel/crypto/af_alg02.c<br>
> +++ b/testcases/kernel/crypto/af_alg02.c<br>
> @@ -7,12 +7,20 @@<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 a timeout.<br></blockquote><div><br></div><div class="gmail_default" style="font-size:small">The comments should be updated too.</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">
> + * 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 <errno.h><br>
>  <br>
> -static void run(void)<br>
> +<span class="gmail_default" style="font-size:small"></span>void *verify_encrypt(void *arg)<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">We could set <span class="gmail_default"></span>LTP_ATTRIBUTE_UNUSED at the behind of unused parameter to get rid of compiling warning:</div></div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">void *verify_encrypt(void *arg LTP_ATTRIBUTE_UNUSED)<br></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>
>       char buf[16];<br></blockquote><div><br></div><div class="gmail_default" style="font-size:small">TST_CHECKPOINT_WAKE(0);</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">
>       int reqfd = tst_alg_setup_reqfd("skcipher", "salsa20", NULL, 16);<br>
> @@ -22,8 +30,27 @@ 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></blockquote><div><br></div><div class="gmail_default" style="font-size:small">Should use 'TFAIL' but 'TBROK' here. </div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">See test-writing-guidelines.txt:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default"><div class="gmail_default" style="font-size:small">   406  -------------------------------------------------------------------------------</div><div class="gmail_default" style="font-size:small">   407  void tst_res(int ttype, char *arg_fmt, ...);</div><div class="gmail_default" style="font-size:small">   408  -------------------------------------------------------------------------------</div><div class="gmail_default" style="font-size:small">   409  </div><div class="gmail_default" style="font-size:small">   410  Printf-like function to report test result, it's mostly used with ttype:</div><div class="gmail_default" style="font-size:small">   411  </div><div class="gmail_default" style="font-size:small">   412  |==============================</div><div class="gmail_default" style="font-size:small">   413  | 'TPASS' | Test has passed.</div><div class="gmail_default" style="font-size:small">   414  | 'TFAIL' | Test has failed.</div><div class="gmail_default" style="font-size:small">   415  | 'TINFO' | General message.</div><div class="gmail_default" style="font-size:small">   416  |==============================</div><div style="font-size:small">...</div><div><div>   422  -------------------------------------------------------------------------------</div><div>   423  void tst_brk(int ttype, char *arg_fmt, ...);</div><div>   424  -------------------------------------------------------------------------------</div><div>   425  </div><div>   426  Printf-like function to report error and exit the test, it can be used with ttype:</div><div>   427  </div><div>   428  |============================================================</div><div>   429  | 'TBROK' | Something has failed in test preparation phase.</div><div>   430  | 'TCONF' | Test is not appropriate for current configuration</div><div>   431              (syscall not implemented, unsupported arch, ...)</div><div>   432  |============================================================</div></div><div style="font-size:small"><br></div></div><div class="gmail_default" style="font-size:small"></div><div class="gmail_default" style="font-size:small"><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> +     return arg;<br>
> +}<br>
> +<br>
> +static void run(void)<br>
> +{<br>
> +     pthread_t thr;<br>
> +<br>
> +     pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);<br>
> +     SAFE_PTHREAD_CREATE(&thr, NULL, verify_encrypt, NULL);<br>
> +<br></blockquote><div><br></div><div class="gmail_default" style="font-size:small">A checkpoint is neccessary here, because we'd better confirm the thread has already running before check it by pthread_kill().</div><div class="gmail_default" style="font-size:small"></div><div><span class="gmail_default" style="font-size:small">TST_CHECKPOINT_WAIT(0);</span></div><div><span class="gmail_default" style="font-size:small"></span> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> +     while (pthread_kill(thr, 0) != ESRCH) {<br>
> +             if (tst_timeout_remaining() <= 10) {<br>
> +                     pthread_cancel(thr);<br>
> +                     tst_brk(TBROK,<br>
> +                             "Timed out while reading from request socket.");<br>
> +             }<br>
> +             usleep(1000);<br>
> +     }<br>
>  }<br>
>  <br>
>  static struct tst_test test = {<br>
>       .test_all = run,<br>
> +     .timeout = 20,<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></div></div></div></div></div>