X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=security%2Finode.c;h=7a8793d9efd8b2fe26807173c8907237c89d6416;hb=0b97ae72bc054da8f9af736dac51611307133890;hp=c83db05c15aba95801c49418d51728d5774bfdf0;hpb=f29b909db9df7e7e0bdd0b2c41e3c9d6c7db41a3;p=mirror_ubuntu-zesty-kernel.git diff --git a/security/inode.c b/security/inode.c index c83db05c15ab..7a8793d9efd8 100644 --- a/security/inode.c +++ b/security/inode.c @@ -46,8 +46,42 @@ static struct file_system_type fs_type = { .kill_sb = kill_litter_super, }; +int securityfs_pin_fs(void) +{ + return simple_pin_fs(&fs_type, &mount, &mount_count); +} + +int __securityfs_setup_d_inode(struct inode *dir, struct dentry *dentry, + umode_t mode, void *data, + const struct file_operations *fops, + const struct inode_operations *iops) +{ + bool is_dir = S_ISDIR(mode); + struct inode *inode = new_inode(dir->i_sb); + if (!inode) + return -ENOMEM; + + inode->i_ino = get_next_ino(); + inode->i_mode = mode; + inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; + inode->i_private = data; + if (is_dir) { + inode->i_op = iops ? iops : &simple_dir_inode_operations; + inode->i_fop = &simple_dir_operations; + inc_nlink(inode); + inc_nlink(dir); + } else { + inode->i_fop = fops; + } + d_instantiate(dentry, inode); + dget(dentry); + + return 0; +} +EXPORT_SYMBOL_GPL(__securityfs_setup_d_inode); + /** - * securityfs_create_file - create a file in the securityfs filesystem + * securityfs_create_dentry - create a file/dir in the securityfs filesystem * * @name: a pointer to a string containing the name of the file to create. * @mode: the permission that the file should have @@ -59,8 +93,10 @@ static struct file_system_type fs_type = { * the open() call. * @fops: a pointer to a struct file_operations that should be used for * this file. + * @iops: a point to a struct of inode_operations that should be used for + * this file/dir * - * This is the basic "create a file" function for securityfs. It allows for a + * This is the basic "create a xxx" function for securityfs. It allows for a * wide range of flexibility in creating a file, or a directory (if you * want to create a directory, the securityfs_create_dir() function is * recommended to be used instead). @@ -74,13 +110,14 @@ static struct file_system_type fs_type = { * If securityfs is not enabled in the kernel, the value %-ENODEV is * returned. */ -struct dentry *securityfs_create_file(const char *name, umode_t mode, - struct dentry *parent, void *data, - const struct file_operations *fops) +struct dentry *securityfs_create_dentry(const char *name, umode_t mode, + struct dentry *parent, void *data, + const struct file_operations *fops, + const struct inode_operations *iops) { struct dentry *dentry; int is_dir = S_ISDIR(mode); - struct inode *dir, *inode; + struct inode *dir; int error; if (!is_dir) { @@ -109,26 +146,9 @@ struct dentry *securityfs_create_file(const char *name, umode_t mode, goto out1; } - inode = new_inode(dir->i_sb); - if (!inode) { - error = -ENOMEM; + error = __securityfs_setup_d_inode(dir, dentry, mode, data, fops, iops); + if (error) goto out1; - } - - inode->i_ino = get_next_ino(); - inode->i_mode = mode; - inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode); - inode->i_private = data; - if (is_dir) { - inode->i_op = &simple_dir_inode_operations; - inode->i_fop = &simple_dir_operations; - inc_nlink(inode); - inc_nlink(dir); - } else { - inode->i_fop = fops; - } - d_instantiate(dentry, inode); - dget(dentry); inode_unlock(dir); return dentry; @@ -140,6 +160,39 @@ out: simple_release_fs(&mount, &mount_count); return dentry; } +EXPORT_SYMBOL_GPL(securityfs_create_dentry); + +/** + * securityfs_create_file - create a file in the securityfs filesystem + * + * @name: a pointer to a string containing the name of the file to create. + * @mode: the permission that the file should have + * @parent: a pointer to the parent dentry for this file. This should be a + * directory dentry if set. If this parameter is %NULL, then the + * file will be created in the root of the securityfs filesystem. + * @data: a pointer to something that the caller will want to get to later + * on. The inode.i_private pointer will point to this value on + * the open() call. + * @fops: a pointer to a struct file_operations that should be used for + * this file. + * + * This function creates a file in securityfs with the given @name. + * + * This function returns a pointer to a dentry if it succeeds. This + * pointer must be passed to the securityfs_remove() function when the file is + * to be removed (no automatic cleanup happens if your module is unloaded, + * you are responsible here). If an error occurs, the function will return + * the error value (via ERR_PTR). + * + * If securityfs is not enabled in the kernel, the value %-ENODEV is + * returned. + */ +struct dentry *securityfs_create_file(const char *name, umode_t mode, + struct dentry *parent, void *data, + const struct file_operations *fops) +{ + return securityfs_create_dentry(name, mode, parent, data, fops, NULL); +} EXPORT_SYMBOL_GPL(securityfs_create_file); /**