• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright 2019 Google LLC
4  */
5 
6 /*
7  * Regression test for commit 8f9c46934848 ("crypto: authenc - fix parsing key
8  * with misaligned rta_len").  Based on the reproducer from the commit message.
9  */
10 
11 #include <errno.h>
12 
13 #include "tst_test.h"
14 #include "tst_af_alg.h"
15 #include "lapi/socket.h"
16 
17 /*
18  * include after <sys/socket.h> (via tst_test.h), to work around dependency bug
19  * in old kernel headers (https://www.spinics.net/lists/netdev/msg171764.html)
20  */
21 #include <linux/rtnetlink.h>
22 
run(void)23 static void run(void)
24 {
25 	struct {
26 		struct rtattr attr;
27 		uint32_t enckeylen;
28 		char keys[1];
29 	} __attribute__((packed)) key = {
30 		.attr.rta_len = sizeof(key),
31 		.attr.rta_type = 1 /* CRYPTO_AUTHENC_KEYA_PARAM */,
32 	};
33 	int algfd;
34 
35 	algfd = tst_alg_setup("aead", "authenc(hmac(sha256),cbc(aes))",
36 			      NULL, 0);
37 	tst_res(TINFO,
38 		"Setting malformed authenc key. May crash buggy kernels.");
39 	TEST(setsockopt(algfd, SOL_ALG, ALG_SET_KEY, &key, sizeof(key)));
40 	if (TST_RET == 0)
41 		tst_res(TFAIL, "setting malformed key unexpectedly succeeded");
42 	else if (TST_ERR != EINVAL)
43 		tst_res(TFAIL | TTERRNO,
44 			"setting malformed key failed with unexpected error");
45 	else
46 		tst_res(TPASS, "didn't crash, and got EINVAL as expected");
47 }
48 
49 static struct tst_test test = {
50 	.test_all = run,
51 	.tags = (const struct tst_tag[]) {
52 		{"linux-git", "8f9c46934848"},
53 		{}
54 	}
55 };
56