/*1* security/tomoyo/common.c2*3* Securityfs interface for TOMOYO.4*5* Copyright (C) 2005-2010 NTT DATA CORPORATION6*/78#include <linux/security.h>9#include "common.h"1011/**12* tomoyo_open - open() for /sys/kernel/security/tomoyo/ interface.13*14* @inode: Pointer to "struct inode".15* @file: Pointer to "struct file".16*17* Returns 0 on success, negative value otherwise.18*/19static int tomoyo_open(struct inode *inode, struct file *file)20{21const int key = ((u8 *) file->f_path.dentry->d_inode->i_private)22- ((u8 *) NULL);23return tomoyo_open_control(key, file);24}2526/**27* tomoyo_release - close() for /sys/kernel/security/tomoyo/ interface.28*29* @inode: Pointer to "struct inode".30* @file: Pointer to "struct file".31*32* Returns 0 on success, negative value otherwise.33*/34static int tomoyo_release(struct inode *inode, struct file *file)35{36return tomoyo_close_control(file);37}3839/**40* tomoyo_poll - poll() for /proc/ccs/ interface.41*42* @file: Pointer to "struct file".43* @wait: Pointer to "poll_table".44*45* Returns 0 on success, negative value otherwise.46*/47static unsigned int tomoyo_poll(struct file *file, poll_table *wait)48{49return tomoyo_poll_control(file, wait);50}5152/**53* tomoyo_read - read() for /sys/kernel/security/tomoyo/ interface.54*55* @file: Pointer to "struct file".56* @buf: Pointer to buffer.57* @count: Size of @buf.58* @ppos: Unused.59*60* Returns bytes read on success, negative value otherwise.61*/62static ssize_t tomoyo_read(struct file *file, char __user *buf, size_t count,63loff_t *ppos)64{65return tomoyo_read_control(file, buf, count);66}6768/**69* tomoyo_write - write() for /sys/kernel/security/tomoyo/ interface.70*71* @file: Pointer to "struct file".72* @buf: Pointer to buffer.73* @count: Size of @buf.74* @ppos: Unused.75*76* Returns @count on success, negative value otherwise.77*/78static ssize_t tomoyo_write(struct file *file, const char __user *buf,79size_t count, loff_t *ppos)80{81return tomoyo_write_control(file, buf, count);82}8384/*85* tomoyo_operations is a "struct file_operations" which is used for handling86* /sys/kernel/security/tomoyo/ interface.87*88* Some files under /sys/kernel/security/tomoyo/ directory accept open(O_RDWR).89* See tomoyo_io_buffer for internals.90*/91static const struct file_operations tomoyo_operations = {92.open = tomoyo_open,93.release = tomoyo_release,94.poll = tomoyo_poll,95.read = tomoyo_read,96.write = tomoyo_write,97.llseek = noop_llseek,98};99100/**101* tomoyo_create_entry - Create interface files under /sys/kernel/security/tomoyo/ directory.102*103* @name: The name of the interface file.104* @mode: The permission of the interface file.105* @parent: The parent directory.106* @key: Type of interface.107*108* Returns nothing.109*/110static void __init tomoyo_create_entry(const char *name, const mode_t mode,111struct dentry *parent, const u8 key)112{113securityfs_create_file(name, mode, parent, ((u8 *) NULL) + key,114&tomoyo_operations);115}116117/**118* tomoyo_initerface_init - Initialize /sys/kernel/security/tomoyo/ interface.119*120* Returns 0.121*/122static int __init tomoyo_initerface_init(void)123{124struct dentry *tomoyo_dir;125126/* Don't create securityfs entries unless registered. */127if (current_cred()->security != &tomoyo_kernel_domain)128return 0;129130tomoyo_dir = securityfs_create_dir("tomoyo", NULL);131tomoyo_create_entry("query", 0600, tomoyo_dir,132TOMOYO_QUERY);133tomoyo_create_entry("domain_policy", 0600, tomoyo_dir,134TOMOYO_DOMAINPOLICY);135tomoyo_create_entry("exception_policy", 0600, tomoyo_dir,136TOMOYO_EXCEPTIONPOLICY);137tomoyo_create_entry("self_domain", 0400, tomoyo_dir,138TOMOYO_SELFDOMAIN);139tomoyo_create_entry(".domain_status", 0600, tomoyo_dir,140TOMOYO_DOMAIN_STATUS);141tomoyo_create_entry(".process_status", 0600, tomoyo_dir,142TOMOYO_PROCESS_STATUS);143tomoyo_create_entry("meminfo", 0600, tomoyo_dir,144TOMOYO_MEMINFO);145tomoyo_create_entry("profile", 0600, tomoyo_dir,146TOMOYO_PROFILE);147tomoyo_create_entry("manager", 0600, tomoyo_dir,148TOMOYO_MANAGER);149tomoyo_create_entry("version", 0400, tomoyo_dir,150TOMOYO_VERSION);151return 0;152}153154fs_initcall(tomoyo_initerface_init);155156157