blob: 073ddc9bce5ba14ad9af18f2cc4f569043016b98 [file] [log] [blame]
Petko Manolov41c89b62015-12-02 17:47:55 +02001/*
2 * Copyright (C) 2015 Juniper Networks, Inc.
3 *
4 * Author:
5 * Petko Manolov <petko.manolov@konsulko.com>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation, version 2 of the
10 * License.
11 *
12 */
13
14#include <linux/export.h>
15#include <linux/kernel.h>
16#include <linux/sched.h>
17#include <linux/cred.h>
18#include <linux/err.h>
Paul Gortmaker92cc9162015-12-09 17:37:16 -050019#include <linux/init.h>
Mat Martineau2b6aa412016-08-31 16:05:43 -070020#include <linux/slab.h>
David Howellsa511e1a2016-04-06 16:14:26 +010021#include <keys/system_keyring.h>
Petko Manolov41c89b62015-12-02 17:47:55 +020022
23
Petko Manolov41c89b62015-12-02 17:47:55 +020024struct key *ima_blacklist_keyring;
25
26/*
David Howells56104cf2016-04-07 09:45:23 +010027 * Allocate the IMA blacklist keyring
Petko Manolov41c89b62015-12-02 17:47:55 +020028 */
29__init int ima_mok_init(void)
30{
Mat Martineau2b6aa412016-08-31 16:05:43 -070031 struct key_restriction *restriction;
32
David Howells56104cf2016-04-07 09:45:23 +010033 pr_notice("Allocating IMA blacklist keyring.\n");
Petko Manolov41c89b62015-12-02 17:47:55 +020034
Mat Martineau2b6aa412016-08-31 16:05:43 -070035 restriction = kzalloc(sizeof(struct key_restriction), GFP_KERNEL);
36 if (!restriction)
37 panic("Can't allocate IMA blacklist restriction.");
38
39 restriction->check = restrict_link_by_builtin_trusted;
40
Petko Manolov41c89b62015-12-02 17:47:55 +020041 ima_blacklist_keyring = keyring_alloc(".ima_blacklist",
42 KUIDT_INIT(0), KGIDT_INIT(0), current_cred(),
43 (KEY_POS_ALL & ~KEY_POS_SETATTR) |
44 KEY_USR_VIEW | KEY_USR_READ |
45 KEY_USR_WRITE | KEY_USR_SEARCH,
David Howells5ac7eac2016-04-06 16:14:24 +010046 KEY_ALLOC_NOT_IN_QUOTA,
Mat Martineau2b6aa412016-08-31 16:05:43 -070047 restriction, NULL);
Petko Manolov41c89b62015-12-02 17:47:55 +020048
David Howells56104cf2016-04-07 09:45:23 +010049 if (IS_ERR(ima_blacklist_keyring))
50 panic("Can't allocate IMA blacklist keyring.");
Mimi Zohar501f1bd2015-11-10 09:00:38 -050051
Mimi Zohar501f1bd2015-11-10 09:00:38 -050052 set_bit(KEY_FLAG_KEEP, &ima_blacklist_keyring->flags);
Petko Manolov41c89b62015-12-02 17:47:55 +020053 return 0;
54}
Paul Gortmaker92cc9162015-12-09 17:37:16 -050055device_initcall(ima_mok_init);