[PATCH v2 5/6] crypto/af_alg04: new regression test for vmac race conditions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Eric Biggers <ebiggers@xxxxxxxxxx>

Signed-off-by: Eric Biggers <ebiggers@xxxxxxxxxx>
---
 runtest/crypto                     |  1 +
 testcases/kernel/crypto/.gitignore |  1 +
 testcases/kernel/crypto/af_alg04.c | 56 ++++++++++++++++++++++++++++++
 3 files changed, 58 insertions(+)
 create mode 100644 testcases/kernel/crypto/af_alg04.c

diff --git a/runtest/crypto b/runtest/crypto
index 03a49df3a..b6180c417 100644
--- a/runtest/crypto
+++ b/runtest/crypto
@@ -1,5 +1,6 @@
 af_alg01 af_alg01
 af_alg02 af_alg02
 af_alg03 af_alg03
+af_alg04 af_alg04
 pcrypt_aead01 pcrypt_aead01
 crypto_user01 crypto_user01
diff --git a/testcases/kernel/crypto/.gitignore b/testcases/kernel/crypto/.gitignore
index 3e7936fc9..df6b7e73c 100644
--- a/testcases/kernel/crypto/.gitignore
+++ b/testcases/kernel/crypto/.gitignore
@@ -1,5 +1,6 @@
 af_alg01
 af_alg02
 af_alg03
+af_alg04
 pcrypt_aead01
 crypto_user01
diff --git a/testcases/kernel/crypto/af_alg04.c b/testcases/kernel/crypto/af_alg04.c
new file mode 100644
index 000000000..b8e494b87
--- /dev/null
+++ b/testcases/kernel/crypto/af_alg04.c
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright 2019 Google LLC
+ */
+
+/*
+ * Regression test for commit bb2964810233 ("crypto: vmac - separate tfm and
+ * request context").  This test verifies that a VMAC transform can be used by
+ * multiple concurrent hash requests without crashing the kernel.  Based on the
+ * reproducer from the commit message.
+ */
+
+#include <sys/wait.h>
+
+#include "tst_test.h"
+#include "tst_af_alg.h"
+
+static void run(void)
+{
+	int algfd, reqfd;
+	char buf[256] = { 0 };
+	pid_t pid;
+	int status;
+	int i;
+
+	if (tst_have_alg("hash", "vmac64(aes)"))
+		algfd = tst_alg_setup("hash", "vmac64(aes)", NULL, 16);
+	else
+		algfd = tst_alg_setup("hash", "vmac(aes)", NULL, 16);
+
+	pid = SAFE_FORK();
+
+	reqfd = tst_alg_accept(algfd);
+
+	for (i = 0; i < 500000; i++)
+		SAFE_WRITE(1, reqfd, buf, sizeof(buf));
+
+	close(reqfd);
+
+	if (pid != 0) {
+		SAFE_WAIT(&status);
+		if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
+			tst_res(TPASS, "didn't crash");
+		else if (WIFSIGNALED(status) && WTERMSIG(status) == SIGKILL)
+			tst_res(TFAIL, "crashed");
+		else
+			tst_brk(TBROK, "child %s", tst_strstatus(status));
+
+		close(algfd);
+	}
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.forks_child = 1,
+};
-- 
2.21.0.225.g810b269d1ac-goog




[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]

  Powered by Linux