2 * security/tomoyo/common.c
4 * Securityfs interface for TOMOYO.
6 * Copyright (C) 2005-2010 NTT DATA CORPORATION
9 #include <linux/security.h>
13 * tomoyo_open - open() for /sys/kernel/security/tomoyo/ interface.
15 * @inode: Pointer to "struct inode".
16 * @file: Pointer to "struct file".
18 * Returns 0 on success, negative value otherwise.
20 static int tomoyo_open(struct inode *inode, struct file *file)
22 const int key = ((u8 *) file->f_path.dentry->d_inode->i_private)
24 return tomoyo_open_control(key, file);
28 * tomoyo_release - close() for /sys/kernel/security/tomoyo/ interface.
30 * @inode: Pointer to "struct inode".
31 * @file: Pointer to "struct file".
33 * Returns 0 on success, negative value otherwise.
35 static int tomoyo_release(struct inode *inode, struct file *file)
37 return tomoyo_close_control(file);
41 * tomoyo_poll - poll() for /sys/kernel/security/tomoyo/ interface.
43 * @file: Pointer to "struct file".
44 * @wait: Pointer to "poll_table".
46 * Returns 0 on success, negative value otherwise.
48 static unsigned int tomoyo_poll(struct file *file, poll_table *wait)
50 return tomoyo_poll_control(file, wait);
54 * tomoyo_read - read() for /sys/kernel/security/tomoyo/ interface.
56 * @file: Pointer to "struct file".
57 * @buf: Pointer to buffer.
58 * @count: Size of @buf.
61 * Returns bytes read on success, negative value otherwise.
63 static ssize_t tomoyo_read(struct file *file, char __user *buf, size_t count,
66 return tomoyo_read_control(file, buf, count);
70 * tomoyo_write - write() for /sys/kernel/security/tomoyo/ interface.
72 * @file: Pointer to "struct file".
73 * @buf: Pointer to buffer.
74 * @count: Size of @buf.
77 * Returns @count on success, negative value otherwise.
79 static ssize_t tomoyo_write(struct file *file, const char __user *buf,
80 size_t count, loff_t *ppos)
82 return tomoyo_write_control(file, buf, count);
86 * tomoyo_operations is a "struct file_operations" which is used for handling
87 * /sys/kernel/security/tomoyo/ interface.
89 * Some files under /sys/kernel/security/tomoyo/ directory accept open(O_RDWR).
90 * See tomoyo_io_buffer for internals.
92 static const struct file_operations tomoyo_operations = {
94 .release = tomoyo_release,
97 .write = tomoyo_write,
98 .llseek = noop_llseek,
102 * tomoyo_create_entry - Create interface files under /sys/kernel/security/tomoyo/ directory.
104 * @name: The name of the interface file.
105 * @mode: The permission of the interface file.
106 * @parent: The parent directory.
107 * @key: Type of interface.
111 static void __init tomoyo_create_entry(const char *name, const mode_t mode,
112 struct dentry *parent, const u8 key)
114 securityfs_create_file(name, mode, parent, ((u8 *) NULL) + key,
119 * tomoyo_initerface_init - Initialize /sys/kernel/security/tomoyo/ interface.
123 static int __init tomoyo_initerface_init(void)
125 struct dentry *tomoyo_dir;
127 /* Don't create securityfs entries unless registered. */
128 if (current_cred()->security != &tomoyo_kernel_domain)
131 tomoyo_dir = securityfs_create_dir("tomoyo", NULL);
132 tomoyo_create_entry("query", 0600, tomoyo_dir,
134 tomoyo_create_entry("domain_policy", 0600, tomoyo_dir,
135 TOMOYO_DOMAINPOLICY);
136 tomoyo_create_entry("exception_policy", 0600, tomoyo_dir,
137 TOMOYO_EXCEPTIONPOLICY);
138 tomoyo_create_entry("self_domain", 0400, tomoyo_dir,
140 tomoyo_create_entry(".domain_status", 0600, tomoyo_dir,
141 TOMOYO_DOMAIN_STATUS);
142 tomoyo_create_entry(".process_status", 0600, tomoyo_dir,
143 TOMOYO_PROCESS_STATUS);
144 tomoyo_create_entry("meminfo", 0600, tomoyo_dir,
146 tomoyo_create_entry("profile", 0600, tomoyo_dir,
148 tomoyo_create_entry("manager", 0600, tomoyo_dir,
150 tomoyo_create_entry("version", 0400, tomoyo_dir,
155 fs_initcall(tomoyo_initerface_init);