1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright 2019 Google LLC
4 */
5
6 /*
7 * Regression test for commit bb2964810233 ("crypto: vmac - separate tfm and
8 * request context"). This test verifies that a VMAC transform can be used by
9 * multiple concurrent hash requests without crashing the kernel. Based on the
10 * reproducer from the commit message.
11 */
12
13 #include <sys/wait.h>
14
15 #include "tst_test.h"
16 #include "tst_af_alg.h"
17
run(void)18 static void run(void)
19 {
20 int algfd, reqfd;
21 char buf[256] = { 0 };
22 pid_t pid;
23 int status;
24 int i;
25
26 if (tst_have_alg("hash", "vmac64(aes)"))
27 algfd = tst_alg_setup("hash", "vmac64(aes)", NULL, 16);
28 else
29 algfd = tst_alg_setup("hash", "vmac(aes)", NULL, 16);
30
31 tst_res(TINFO, "Starting vmac hashing test. May crash buggy kernels.");
32
33 pid = SAFE_FORK();
34
35 reqfd = tst_alg_accept(algfd);
36
37 for (i = 0; i < 500000; i++)
38 SAFE_WRITE(1, reqfd, buf, sizeof(buf));
39
40 close(reqfd);
41
42 if (pid != 0) {
43 SAFE_WAIT(&status);
44 if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
45 tst_res(TPASS, "didn't crash");
46 else if (WIFSIGNALED(status) && WTERMSIG(status) == SIGKILL)
47 tst_res(TFAIL, "crashed");
48 else
49 tst_brk(TBROK, "child %s", tst_strstatus(status));
50
51 close(algfd);
52 }
53 }
54
55 static struct tst_test test = {
56 .test_all = run,
57 .forks_child = 1,
58 .tags = (const struct tst_tag[]) {
59 {"linux-git", "bb2964810233"},
60 {}
61 }
62 };
63