1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright 2019 Google LLC 4f08c3bdfSopenharmony_ci * Copyright (c) Linux Test Project, 2019-2021 5f08c3bdfSopenharmony_ci */ 6f08c3bdfSopenharmony_ci 7f08c3bdfSopenharmony_ci/* 8f08c3bdfSopenharmony_ci * Regression test for commit bb2964810233 ("crypto: vmac - separate tfm and 9f08c3bdfSopenharmony_ci * request context"). This test verifies that a VMAC transform can be used by 10f08c3bdfSopenharmony_ci * multiple concurrent hash requests without crashing the kernel. Based on the 11f08c3bdfSopenharmony_ci * reproducer from the commit message. 12f08c3bdfSopenharmony_ci */ 13f08c3bdfSopenharmony_ci 14f08c3bdfSopenharmony_ci#include <stdio.h> 15f08c3bdfSopenharmony_ci#include <sys/wait.h> 16f08c3bdfSopenharmony_ci 17f08c3bdfSopenharmony_ci#include "tst_test.h" 18f08c3bdfSopenharmony_ci#include "tst_af_alg.h" 19f08c3bdfSopenharmony_ci 20f08c3bdfSopenharmony_cistatic void test_with_symm_enc_algs(const char *symm_enc_algname) 21f08c3bdfSopenharmony_ci{ 22f08c3bdfSopenharmony_ci int algfd, reqfd; 23f08c3bdfSopenharmony_ci char buf[256] = { 0 }; 24f08c3bdfSopenharmony_ci char vmac_algname[64]; 25f08c3bdfSopenharmony_ci pid_t pid; 26f08c3bdfSopenharmony_ci int status; 27f08c3bdfSopenharmony_ci int i; 28f08c3bdfSopenharmony_ci 29f08c3bdfSopenharmony_ci sprintf(vmac_algname, "vmac64(%s)", symm_enc_algname); 30f08c3bdfSopenharmony_ci if (!tst_have_alg("hash", vmac_algname)) { 31f08c3bdfSopenharmony_ci sprintf(vmac_algname, "vmac(%s)", symm_enc_algname); 32f08c3bdfSopenharmony_ci if (!tst_have_alg("hash", vmac_algname)) 33f08c3bdfSopenharmony_ci return; 34f08c3bdfSopenharmony_ci } 35f08c3bdfSopenharmony_ci algfd = tst_alg_setup("hash", vmac_algname, NULL, 16); 36f08c3bdfSopenharmony_ci 37f08c3bdfSopenharmony_ci tst_res(TINFO, "Starting vmac hashing test. May crash buggy kernels."); 38f08c3bdfSopenharmony_ci 39f08c3bdfSopenharmony_ci pid = SAFE_FORK(); 40f08c3bdfSopenharmony_ci 41f08c3bdfSopenharmony_ci reqfd = tst_alg_accept(algfd); 42f08c3bdfSopenharmony_ci 43f08c3bdfSopenharmony_ci for (i = 0; i < 500000; i++) 44f08c3bdfSopenharmony_ci SAFE_WRITE(SAFE_WRITE_ALL, reqfd, buf, sizeof(buf)); 45f08c3bdfSopenharmony_ci 46f08c3bdfSopenharmony_ci close(reqfd); 47f08c3bdfSopenharmony_ci 48f08c3bdfSopenharmony_ci if (pid != 0) { 49f08c3bdfSopenharmony_ci SAFE_WAIT(&status); 50f08c3bdfSopenharmony_ci if (WIFEXITED(status) && WEXITSTATUS(status) == 0) 51f08c3bdfSopenharmony_ci tst_res(TPASS, "didn't crash"); 52f08c3bdfSopenharmony_ci else if (WIFSIGNALED(status) && WTERMSIG(status) == SIGKILL) 53f08c3bdfSopenharmony_ci tst_res(TFAIL, "crashed"); 54f08c3bdfSopenharmony_ci else 55f08c3bdfSopenharmony_ci tst_brk(TBROK, "child %s", tst_strstatus(status)); 56f08c3bdfSopenharmony_ci 57f08c3bdfSopenharmony_ci close(algfd); 58f08c3bdfSopenharmony_ci } 59f08c3bdfSopenharmony_ci} 60f08c3bdfSopenharmony_ci 61f08c3bdfSopenharmony_ci/* try several different symmetric encryption algorithms */ 62f08c3bdfSopenharmony_cistatic const char * const symm_enc_algs[] = { 63f08c3bdfSopenharmony_ci "aes", 64f08c3bdfSopenharmony_ci "sm4", 65f08c3bdfSopenharmony_ci "sm4-generic", 66f08c3bdfSopenharmony_ci}; 67f08c3bdfSopenharmony_ci 68f08c3bdfSopenharmony_cistatic void do_test(unsigned int i) 69f08c3bdfSopenharmony_ci{ 70f08c3bdfSopenharmony_ci test_with_symm_enc_algs(symm_enc_algs[i]); 71f08c3bdfSopenharmony_ci} 72f08c3bdfSopenharmony_ci 73f08c3bdfSopenharmony_cistatic struct tst_test test = { 74f08c3bdfSopenharmony_ci .test = do_test, 75f08c3bdfSopenharmony_ci .tcnt = ARRAY_SIZE(symm_enc_algs), 76f08c3bdfSopenharmony_ci .forks_child = 1, 77f08c3bdfSopenharmony_ci .tags = (const struct tst_tag[]) { 78f08c3bdfSopenharmony_ci {"linux-git", "bb2964810233"}, 79f08c3bdfSopenharmony_ci {} 80f08c3bdfSopenharmony_ci } 81f08c3bdfSopenharmony_ci}; 82