1 /*
2 * Copyright (c) 2017 Fujitsu Ltd.
3 * Ported: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program, if not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /*
20 * This regression test can crash the buggy kernel,
21 * and the bug was fixed in:
22 *
23 * commit f05819df10d7b09f6d1eb6f8534a8f68e5a4fe61
24 * Author: David Howells <dhowells@redhat.com>
25 * Date: Thu Oct 15 17:21:37 2015 +0100
26 *
27 * KEYS: Fix crash when attempt to garbage collect
28 * an uninstantiated keyring
29 */
30
31 #include <errno.h>
32 #include <sys/types.h>
33
34 #include "tst_test.h"
35 #include "lapi/keyctl.h"
36
do_test(void)37 static void do_test(void)
38 {
39 key_serial_t key;
40
41 key = add_key("user", "ltptestkey", "a", 1, KEY_SPEC_SESSION_KEYRING);
42 if (key == -1)
43 tst_brk(TBROK, "Failed to add key");
44
45 request_key("keyring", "foo", "bar", KEY_SPEC_THREAD_KEYRING);
46
47 TEST(keyctl(KEYCTL_UNLINK, key, KEY_SPEC_SESSION_KEYRING));
48 if (TST_RET)
49 tst_res(TFAIL | TTERRNO, "keyctl unlink failed");
50 else
51 tst_res(TPASS, "Bug not reproduced");
52 }
53
54 static struct tst_test test = {
55 .test_all = do_test,
56 };
57