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_read - read() for /sys/kernel/security/tomoyo/ interface.
43 * @file: Pointer to "struct file".
44 * @buf: Pointer to buffer.
45 * @count: Size of @buf.
48 * Returns bytes read on success, negative value otherwise.
50 static ssize_t tomoyo_read(struct file *file, char __user *buf, size_t count,
53 return tomoyo_read_control(file, buf, count);
57 * tomoyo_write - write() for /sys/kernel/security/tomoyo/ interface.
59 * @file: Pointer to "struct file".
60 * @buf: Pointer to buffer.
61 * @count: Size of @buf.
64 * Returns @count on success, negative value otherwise.
66 static ssize_t tomoyo_write(struct file *file, const char __user *buf,
67 size_t count, loff_t *ppos)
69 return tomoyo_write_control(file, buf, count);
73 * tomoyo_operations is a "struct file_operations" which is used for handling
74 * /sys/kernel/security/tomoyo/ interface.
76 * Some files under /sys/kernel/security/tomoyo/ directory accept open(O_RDWR).
77 * See tomoyo_io_buffer for internals.
79 static const struct file_operations tomoyo_operations = {
81 .release = tomoyo_release,
83 .write = tomoyo_write,
87 * tomoyo_create_entry - Create interface files under /sys/kernel/security/tomoyo/ directory.
89 * @name: The name of the interface file.
90 * @mode: The permission of the interface file.
91 * @parent: The parent directory.
92 * @key: Type of interface.
96 static void __init tomoyo_create_entry(const char *name, const mode_t mode,
97 struct dentry *parent, const u8 key)
99 securityfs_create_file(name, mode, parent, ((u8 *) NULL) + key,
104 * tomoyo_initerface_init - Initialize /sys/kernel/security/tomoyo/ interface.
108 static int __init tomoyo_initerface_init(void)
110 struct dentry *tomoyo_dir;
112 /* Don't create securityfs entries unless registered. */
113 if (current_cred()->security != &tomoyo_kernel_domain)
116 tomoyo_dir = securityfs_create_dir("tomoyo", NULL);
117 tomoyo_create_entry("query", 0600, tomoyo_dir,
119 tomoyo_create_entry("domain_policy", 0600, tomoyo_dir,
120 TOMOYO_DOMAINPOLICY);
121 tomoyo_create_entry("exception_policy", 0600, tomoyo_dir,
122 TOMOYO_EXCEPTIONPOLICY);
123 tomoyo_create_entry("self_domain", 0400, tomoyo_dir,
125 tomoyo_create_entry(".domain_status", 0600, tomoyo_dir,
126 TOMOYO_DOMAIN_STATUS);
127 tomoyo_create_entry(".process_status", 0600, tomoyo_dir,
128 TOMOYO_PROCESS_STATUS);
129 tomoyo_create_entry("meminfo", 0600, tomoyo_dir,
131 tomoyo_create_entry("profile", 0600, tomoyo_dir,
133 tomoyo_create_entry("manager", 0600, tomoyo_dir,
135 tomoyo_create_entry("version", 0400, tomoyo_dir,
140 fs_initcall(tomoyo_initerface_init);