2 * Copyright (C) 2010 IBM Corporation
5 * Mimi Zohar <zohar@us.ibm.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, version 2 of the License.
12 * - Used to signal when key is on keyring
13 * - Get the key and enable EVM
16 #include <linux/uaccess.h>
17 #include <linux/module.h>
20 static struct dentry
*evm_init_tpm
;
23 * evm_read_key - read() for <securityfs>/evm
25 * @filp: file pointer, not actually used
26 * @buf: where to put the result
27 * @count: maximum to send along
28 * @ppos: where to start
30 * Returns number of bytes read or error code, as appropriate
32 static ssize_t
evm_read_key(struct file
*filp
, char __user
*buf
,
33 size_t count
, loff_t
*ppos
)
41 sprintf(temp
, "%d", evm_initialized
);
42 rc
= simple_read_from_buffer(buf
, count
, ppos
, temp
, strlen(temp
));
48 * evm_write_key - write() for <securityfs>/evm
49 * @file: file pointer, not actually used
50 * @buf: where to get the data from
52 * @ppos: where to start
54 * Used to signal that key is on the kernel key ring.
55 * - get the integrity hmac key from the kernel key ring
56 * - create list of hmac protected extended attributes
57 * Returns number of bytes written or error code, as appropriate
59 static ssize_t
evm_write_key(struct file
*file
, const char __user
*buf
,
60 size_t count
, loff_t
*ppos
)
65 if (!capable(CAP_SYS_ADMIN
) || evm_initialized
)
68 if (count
>= sizeof(temp
) || count
== 0)
71 if (copy_from_user(temp
, buf
, count
) != 0)
76 if ((sscanf(temp
, "%d", &i
) != 1) || (i
!= 1))
79 error
= evm_init_key();
82 pr_info("EVM: initialized\n");
84 pr_err("EVM: initialization failed\n");
88 static const struct file_operations evm_key_ops
= {
90 .write
= evm_write_key
,
93 int __init
evm_init_secfs(void)
97 evm_init_tpm
= securityfs_create_file("evm", S_IRUSR
| S_IRGRP
,
98 NULL
, NULL
, &evm_key_ops
);
99 if (!evm_init_tpm
|| IS_ERR(evm_init_tpm
))