• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2017 Fujitsu Ltd.
4  *  Ported: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
5  */
6 
7 /*
8  * This regression test can crash the buggy kernel,
9  * and the bug was fixed in:
10  *
11  *  commit f05819df10d7b09f6d1eb6f8534a8f68e5a4fe61
12  *  Author: David Howells <dhowells@redhat.com>
13  *  Date:   Thu Oct 15 17:21:37 2015 +0100
14  *
15  *  KEYS: Fix crash when attempt to garbage collect
16  *        an uninstantiated keyring
17  */
18 
19 #include <errno.h>
20 #include <sys/types.h>
21 
22 #include "tst_test.h"
23 #include "lapi/keyctl.h"
24 
do_test(void)25 static void do_test(void)
26 {
27 	key_serial_t key;
28 
29 	key = add_key("user", "ltptestkey", "a", 1, KEY_SPEC_SESSION_KEYRING);
30 	if (key == -1)
31 		tst_brk(TBROK, "Failed to add key");
32 
33 	request_key("keyring", "foo", "bar", KEY_SPEC_THREAD_KEYRING);
34 
35 	TEST(keyctl(KEYCTL_UNLINK, key, KEY_SPEC_SESSION_KEYRING));
36 	if (TST_RET)
37 		tst_res(TFAIL | TTERRNO, "keyctl unlink failed");
38 	else
39 		tst_res(TPASS, "Bug not reproduced");
40 }
41 
42 static struct tst_test test = {
43 	.test_all = do_test,
44 	.tags = (const struct tst_tag[]) {
45 		{"linux-git", "f05819df10d7"},
46 		{}
47 	}
48 };
49