From patchwork Wed May 8 07:16:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Amann X-Patchwork-Id: 1096788 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.com Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44zSTJ130jz9s3q for ; Wed, 8 May 2019 17:16:50 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 28844294AB9 for ; Wed, 8 May 2019 09:16:47 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [217.194.8.4]) by picard.linux.it (Postfix) with ESMTP id DF8EC3EADD1 for ; Wed, 8 May 2019 09:16:44 +0200 (CEST) Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id E710C1002049 for ; Wed, 8 May 2019 09:16:38 +0200 (CEST) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 74F40AEC6 for ; Wed, 8 May 2019 07:16:40 +0000 (UTC) From: Christian Amann To: ltp@lists.linux.it Date: Wed, 8 May 2019 09:16:36 +0200 Message-Id: <20190508071636.13804-1-camann@suse.com> X-Mailer: git-send-email 2.16.4 X-Virus-Scanned: clamav-milter 0.99.2 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH v3] crypto/af_alg02: fixed read() being stuck X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" On kernels < 4.14 (missing commit 2d97591ef43d) reading from the request socket does not return and the testcase does not finish. This fix moves the logic to a child thread in order for the parent to handle the timeout and report a message to the user. Signed-off-by: Christian Amann Reviewed-by: Li Wang --- Notes: Hi Li, > We could set LTP_ATTRIBUTE_UNUSED at the behind of unused parameter to get > rid of compiling warning Thats very useful but I couldn't find it anywhere in the documentation. IMHO it should be put in there, because I stumbled upon this problem a couple of times. Anyway, I implemented your suggestions. I hope it's an alright patch now. Thanks for your feedback! Regards, Christian testcases/kernel/crypto/Makefile | 2 ++ testcases/kernel/crypto/af_alg02.c | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/testcases/kernel/crypto/Makefile b/testcases/kernel/crypto/Makefile index 76f9308c2..6547e1cb6 100644 --- a/testcases/kernel/crypto/Makefile +++ b/testcases/kernel/crypto/Makefile @@ -20,3 +20,5 @@ include $(top_srcdir)/include/mk/testcases.mk CFLAGS += -D_GNU_SOURCE include $(top_srcdir)/include/mk/generic_leaf_target.mk + +af_alg02: CFLAGS += -pthread diff --git a/testcases/kernel/crypto/af_alg02.c b/testcases/kernel/crypto/af_alg02.c index a9e820423..1c725212a 100644 --- a/testcases/kernel/crypto/af_alg02.c +++ b/testcases/kernel/crypto/af_alg02.c @@ -7,23 +7,56 @@ * Regression test for commit ecaaab564978 ("crypto: salsa20 - fix * blkcipher_walk API usage"), or CVE-2017-17805. This test verifies that an * empty message can be encrypted with Salsa20 without crashing the kernel. + * + * Fix for kernels < 4.14: + * With kernels missing commit 2d97591ef43d ("crypto: af_alg - consolidation + * of duplicate code") read() does not return in this situation. The call is + * now moved to a child thread in order to cancel it in case read() takes an + * unusual long amount of time. */ #include "tst_test.h" #include "tst_af_alg.h" +#include "tst_safe_pthread.h" +#include +#include -static void run(void) +void *verify_encrypt(void *arg LTP_ATTRIBUTE_UNUSED) { char buf[16]; int reqfd = tst_alg_setup_reqfd("skcipher", "salsa20", NULL, 16); + TST_CHECKPOINT_WAKE(0); + /* With the bug the kernel crashed here */ if (read(reqfd, buf, 16) == 0) tst_res(TPASS, "Successfully \"encrypted\" an empty message"); else - tst_res(TBROK, "read() didn't return 0"); + tst_res(TFAIL, "read() didn't return 0"); + return arg; +} + +static void run(void) +{ + pthread_t thr; + + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + SAFE_PTHREAD_CREATE(&thr, NULL, verify_encrypt, NULL); + + TST_CHECKPOINT_WAIT(0); + + while (pthread_kill(thr, 0) != ESRCH) { + if (tst_timeout_remaining() <= 10) { + pthread_cancel(thr); + tst_brk(TBROK, + "Timed out while reading from request socket."); + } + usleep(1000); + } } static struct tst_test test = { .test_all = run, + .timeout = 20, + .needs_checkpoints = 1, };