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