1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) 2017 Fujitsu Ltd.
4 * Copyright (c) Linux Test Project, 2017-2024
5 * Ported: Guangwen Feng <[email protected]>
6 */
7
8 /*\
9 * [Description]
10 *
11 * Regression test for commit
12 * f05819df10d7 ("KEYS: Fix crash when attempt to garbage collect an uninstantiated keyring")
13 */
14
15 #include <errno.h>
16 #include <sys/types.h>
17
18 #include "tst_test.h"
19 #include "lapi/keyctl.h"
20
do_test(void)21 static void do_test(void)
22 {
23 key_serial_t key;
24
25 key = add_key("user", "ltptestkey", "a", 1, KEY_SPEC_SESSION_KEYRING);
26 if (key == -1)
27 tst_brk(TBROK, "Failed to add key");
28
29 request_key("keyring", "foo", "bar", KEY_SPEC_THREAD_KEYRING);
30
31 TEST(keyctl(KEYCTL_UNLINK, key, KEY_SPEC_SESSION_KEYRING));
32 if (TST_RET)
33 tst_res(TFAIL | TTERRNO, "keyctl unlink failed");
34 else
35 tst_res(TPASS, "Bug not reproduced");
36 }
37
38 static struct tst_test test = {
39 .test_all = do_test,
40 .tags = (const struct tst_tag[]) {
41 {"linux-git", "f05819df10d7"},
42 {}
43 }
44 };
45