All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] crypto_user02: Find a valid template
@ 2021-03-15 13:03 Joerg Vehlow
  2021-03-29  9:04 ` Petr Vorel
  2021-03-29 18:53 ` Eric Biggers
  0 siblings, 2 replies; 5+ messages in thread
From: Joerg Vehlow @ 2021-03-15 13:03 UTC (permalink / raw)
  To: ltp

From: Joerg Vehlow <joerg.vehlow@aox-tech.de>

The test requires a crypto template, that is not in use by someone else,
otherwise deleting it is not possible.
This adds a list of templates, that are tested in order, until one is found,
that can be used for the test, otherwise TCONF is returned.

Signed-off-by: Joerg Vehlow <joerg.vehlow@aox-tech.de>
---
 testcases/kernel/crypto/crypto_user02.c | 65 ++++++++++++++++++-------
 1 file changed, 47 insertions(+), 18 deletions(-)

diff --git a/testcases/kernel/crypto/crypto_user02.c b/testcases/kernel/crypto/crypto_user02.c
index 384e344f2..23dff5b5f 100644
--- a/testcases/kernel/crypto/crypto_user02.c
+++ b/testcases/kernel/crypto/crypto_user02.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Copyright 2019 Google LLC
+ * Copyright (c) 2019 Google LLC
+ * Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
  */
 
 /*
@@ -26,37 +27,65 @@
 #include "tst_crypto.h"
 #include "tst_timer.h"
 
+/*
+ * List of possible templates to use try (not exhaustive).
+ * The template has to be valid (i.e. the drivers must exists
+ * and be a valid combination) and it has to be deleteable.
+ * To be deletable it cannot be used by someone else.
+ * The first algorithm, that fullfils the criteria is used for the test.
+ */
+static const char* TEMPLATE_CANDIDATES[] = {
+	"hmac(sha1-generic)",
+	"hmac(sha224-generic)",
+	"hmac(sha256-generic)",
+	"hmac(sha384-generic)",
+	"hmac(md5-generic)"
+};
+
+static const char* template = NULL;
 static struct tst_crypto_session ses = TST_CRYPTO_SESSION_INIT;
 
+
 static void setup(void)
 {
+	int rc;
+	unsigned i;
+	struct crypto_user_alg alg, alg_out;
 	tst_crypto_open(&ses);
+
+	/* find an algorithm, that is not in use */
+	for (i = 0; i < ARRAY_SIZE(TEMPLATE_CANDIDATES); ++i) {
+		memset(&alg, 0, sizeof(alg));
+		strcpy(alg.cru_driver_name, TEMPLATE_CANDIDATES[i]);
+
+		/* try to add it, to see if it is valid */
+		rc = tst_crypto_add_alg(&ses, &alg);
+		if (rc != 0)
+			continue;
+
+		/* it also has to be deletable */
+		rc = tst_crypto_del_alg(&ses, &alg);
+		if (rc == 0) {
+			template = TEMPLATE_CANDIDATES[i];
+			break;
+		}
+	}
+	if (!template) {
+		tst_brk(TCONF, "No viable template found");
+	}
 }
 
 static void run(void)
 {
-	struct crypto_user_alg alg = {
-		/*
-		 * Any algorithm instantiated from a template can do here, but
-		 * choose something that's commonly available.
-		 */
-		.cru_driver_name = "hmac(sha256-generic)",
-	};
+	struct crypto_user_alg alg = {};
 	pid_t pid;
 	int status;
 
-	/* Check whether the algorithm is supported before continuing. */
-	TEST(tst_crypto_add_alg(&ses, &alg));
-	if (TST_RET != 0 && TST_RET != -EEXIST) {
-		if (TST_RET == -ENOENT)
-			tst_brk(TCONF, "%s not supported", alg.cru_driver_name);
-
-		tst_brk(TBROK | TRERRNO,
-			"unexpected error checking for algorithm support");
-	}
+	strcpy(alg.cru_driver_name, template);
 
 	tst_res(TINFO,
-		"Starting crypto_user larval deletion test.  May crash buggy kernels.");
+		"Starting crypto_user larval deletion test using template %s. May crash buggy kernels.",
+		template);
 
 	tst_timer_start(CLOCK_MONOTONIC);
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [LTP] [PATCH] crypto_user02: Find a valid template
  2021-03-15 13:03 [LTP] [PATCH] crypto_user02: Find a valid template Joerg Vehlow
@ 2021-03-29  9:04 ` Petr Vorel
  2021-03-29 18:53 ` Eric Biggers
  1 sibling, 0 replies; 5+ messages in thread
From: Petr Vorel @ 2021-03-29  9:04 UTC (permalink / raw)
  To: ltp

Hi,

LGTM. Eric, could you have look on this?

http://lists.linux.it/pipermail/ltp/2021-March/021495.html
https://patchwork.ozlabs.org/project/ltp/patch/20210315130349.1155389-1-lkml@jv-coder.de/

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [LTP] [PATCH] crypto_user02: Find a valid template
  2021-03-15 13:03 [LTP] [PATCH] crypto_user02: Find a valid template Joerg Vehlow
  2021-03-29  9:04 ` Petr Vorel
@ 2021-03-29 18:53 ` Eric Biggers
  2021-04-01  7:22   ` Petr Vorel
  2021-04-01  7:23   ` Petr Vorel
  1 sibling, 2 replies; 5+ messages in thread
From: Eric Biggers @ 2021-03-29 18:53 UTC (permalink / raw)
  To: ltp

On Mon, Mar 15, 2021 at 02:03:49PM +0100, Joerg Vehlow wrote:
> From: Joerg Vehlow <joerg.vehlow@aox-tech.de>
> 
> The test requires a crypto template, that is not in use by someone else,
> otherwise deleting it is not possible.
> This adds a list of templates, that are tested in order, until one is found,
> that can be used for the test, otherwise TCONF is returned.
> 
> Signed-off-by: Joerg Vehlow <joerg.vehlow@aox-tech.de>

Generally looks good.  A few nits below.

> +/*
> + * List of possible templates to use try (not exhaustive).
> + * The template has to be valid (i.e. the drivers must exists
> + * and be a valid combination) and it has to be deleteable.
> + * To be deletable it cannot be used by someone else.
> + * The first algorithm, that fullfils the criteria is used for the test.
> + */
> +static const char* TEMPLATE_CANDIDATES[] = {
> +	"hmac(sha1-generic)",
> +	"hmac(sha224-generic)",
> +	"hmac(sha256-generic)",
> +	"hmac(sha384-generic)",
> +	"hmac(md5-generic)"
> +};

"template" means something like "hmac" by itself.  This probably should be
called something like ALGORITHM_CANDIDATES, and similarly template => algorithm
in a couple places below.

Also it should be 'const char * const', not just 'const char *'.

>  static void setup(void)
>  {
> +	int rc;
> +	unsigned i;
> +	struct crypto_user_alg alg, alg_out;

alg_out is unused.

> +	if (!template) {
> +		tst_brk(TCONF, "No viable template found");
> +	}

Single-line statements shouldn't have braces like this.

- Eric

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [LTP] [PATCH] crypto_user02: Find a valid template
  2021-03-29 18:53 ` Eric Biggers
@ 2021-04-01  7:22   ` Petr Vorel
  2021-04-01  7:23   ` Petr Vorel
  1 sibling, 0 replies; 5+ messages in thread
From: Petr Vorel @ 2021-04-01  7:22 UTC (permalink / raw)
  To: ltp

Hi Joerg, Eric,

Implemented all Eric's suggestions and merged.
Thank you both!

> > +	if (!template) {
> > +		tst_brk(TCONF, "No viable template found");
> > +	}

> Single-line statements shouldn't have braces like this.
Oops, left this one, fixed in separated commit :(.

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [LTP] [PATCH] crypto_user02: Find a valid template
  2021-03-29 18:53 ` Eric Biggers
  2021-04-01  7:22   ` Petr Vorel
@ 2021-04-01  7:23   ` Petr Vorel
  1 sibling, 0 replies; 5+ messages in thread
From: Petr Vorel @ 2021-04-01  7:23 UTC (permalink / raw)
  To: ltp

Hi,

> "template" means something like "hmac" by itself.  This probably should be
> called something like ALGORITHM_CANDIDATES, and similarly template => algorithm
> in a couple places below.
Also left template in commit message. Silly mistake, I'm sorry.

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-04-01  7:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-15 13:03 [LTP] [PATCH] crypto_user02: Find a valid template Joerg Vehlow
2021-03-29  9:04 ` Petr Vorel
2021-03-29 18:53 ` Eric Biggers
2021-04-01  7:22   ` Petr Vorel
2021-04-01  7:23   ` Petr Vorel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.