Home | History | Annotate | Download | only in keyctl
      1 /*
      2  * Copyright (c) 2017 Fujitsu Ltd.
      3  *  Ported: Guangwen Feng <fenggw-fnst (at) 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 (at) 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 "config.h"
     32 #include <errno.h>
     33 #include <sys/types.h>
     34 #ifdef HAVE_KEYUTILS_H
     35 # include <keyutils.h>
     36 #endif
     37 #include "tst_test.h"
     38 
     39 #ifdef HAVE_KEYUTILS_H
     40 
     41 static void do_test(void)
     42 {
     43 	key_serial_t key;
     44 
     45 	key = add_key("user", "ltptestkey", "a", 1, KEY_SPEC_SESSION_KEYRING);
     46 	if (key == -1)
     47 		tst_brk(TBROK, "Failed to add key");
     48 
     49 	request_key("keyring", "foo", "bar", KEY_SPEC_THREAD_KEYRING);
     50 
     51 	TEST(keyctl(KEYCTL_UNLINK, key, KEY_SPEC_SESSION_KEYRING));
     52 	if (TEST_RETURN)
     53 		tst_res(TFAIL | TTERRNO, "keyctl unlink failed");
     54 	else
     55 		tst_res(TPASS, "Bug not reproduced");
     56 }
     57 
     58 static struct tst_test test = {
     59 	.tid = "keyctl03",
     60 	.test_all = do_test,
     61 };
     62 
     63 #else
     64 	TST_TEST_TCONF("keyutils.h does not exist");
     65 #endif /* HAVE_KEYUTILS_H */
     66