2 * security/tomoyo/securityfs_if.c
4 * Copyright (C) 2005-2011 NTT DATA CORPORATION
7 #include <linux/security.h>
11 * tomoyo_open - open() for /sys/kernel/security/tomoyo/ interface.
13 * @inode: Pointer to "struct inode".
14 * @file: Pointer to "struct file".
16 * Returns 0 on success, negative value otherwise.
18 static int tomoyo_open(struct inode
*inode
, struct file
*file
)
20 const int key
= ((u8
*) file
->f_path
.dentry
->d_inode
->i_private
)
22 return tomoyo_open_control(key
, file
);
26 * tomoyo_release - close() for /sys/kernel/security/tomoyo/ interface.
28 * @inode: Pointer to "struct inode".
29 * @file: Pointer to "struct file".
31 * Returns 0 on success, negative value otherwise.
33 static int tomoyo_release(struct inode
*inode
, struct file
*file
)
35 return tomoyo_close_control(file
->private_data
);
39 * tomoyo_poll - poll() for /sys/kernel/security/tomoyo/ interface.
41 * @file: Pointer to "struct file".
42 * @wait: Pointer to "poll_table".
44 * Returns 0 on success, negative value otherwise.
46 static unsigned int tomoyo_poll(struct file
*file
, poll_table
*wait
)
48 return tomoyo_poll_control(file
, wait
);
52 * tomoyo_read - read() for /sys/kernel/security/tomoyo/ interface.
54 * @file: Pointer to "struct file".
55 * @buf: Pointer to buffer.
56 * @count: Size of @buf.
59 * Returns bytes read on success, negative value otherwise.
61 static ssize_t
tomoyo_read(struct file
*file
, char __user
*buf
, size_t count
,
64 return tomoyo_read_control(file
->private_data
, buf
, count
);
68 * tomoyo_write - write() for /sys/kernel/security/tomoyo/ interface.
70 * @file: Pointer to "struct file".
71 * @buf: Pointer to buffer.
72 * @count: Size of @buf.
75 * Returns @count on success, negative value otherwise.
77 static ssize_t
tomoyo_write(struct file
*file
, const char __user
*buf
,
78 size_t count
, loff_t
*ppos
)
80 return tomoyo_write_control(file
->private_data
, buf
, count
);
84 * tomoyo_operations is a "struct file_operations" which is used for handling
85 * /sys/kernel/security/tomoyo/ interface.
87 * Some files under /sys/kernel/security/tomoyo/ directory accept open(O_RDWR).
88 * See tomoyo_io_buffer for internals.
90 static const struct file_operations tomoyo_operations
= {
92 .release
= tomoyo_release
,
95 .write
= tomoyo_write
,
96 .llseek
= noop_llseek
,
100 * tomoyo_create_entry - Create interface files under /sys/kernel/security/tomoyo/ directory.
102 * @name: The name of the interface file.
103 * @mode: The permission of the interface file.
104 * @parent: The parent directory.
105 * @key: Type of interface.
109 static void __init
tomoyo_create_entry(const char *name
, const mode_t mode
,
110 struct dentry
*parent
, const u8 key
)
112 securityfs_create_file(name
, mode
, parent
, ((u8
*) NULL
) + key
,
117 * tomoyo_initerface_init - Initialize /sys/kernel/security/tomoyo/ interface.
121 static int __init
tomoyo_initerface_init(void)
123 struct dentry
*tomoyo_dir
;
125 /* Don't create securityfs entries unless registered. */
126 if (current_cred()->security
!= &tomoyo_kernel_domain
)
129 tomoyo_dir
= securityfs_create_dir("tomoyo", NULL
);
130 tomoyo_create_entry("query", 0600, tomoyo_dir
,
132 tomoyo_create_entry("domain_policy", 0600, tomoyo_dir
,
133 TOMOYO_DOMAINPOLICY
);
134 tomoyo_create_entry("exception_policy", 0600, tomoyo_dir
,
135 TOMOYO_EXCEPTIONPOLICY
);
136 tomoyo_create_entry("audit", 0400, tomoyo_dir
,
138 tomoyo_create_entry("self_domain", 0400, tomoyo_dir
,
140 tomoyo_create_entry(".process_status", 0600, tomoyo_dir
,
141 TOMOYO_PROCESS_STATUS
);
142 tomoyo_create_entry("stat", 0644, tomoyo_dir
,
144 tomoyo_create_entry("profile", 0600, tomoyo_dir
,
146 tomoyo_create_entry("manager", 0600, tomoyo_dir
,
148 tomoyo_create_entry("version", 0400, tomoyo_dir
,
153 fs_initcall(tomoyo_initerface_init
);