Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Landlock LSM - Filesystem management and hooks
0004  *
0005  * Copyright © 2017-2020 Mickaël Salaün <mic@digikod.net>
0006  * Copyright © 2018-2020 ANSSI
0007  */
0008 
0009 #ifndef _SECURITY_LANDLOCK_FS_H
0010 #define _SECURITY_LANDLOCK_FS_H
0011 
0012 #include <linux/fs.h>
0013 #include <linux/init.h>
0014 #include <linux/rcupdate.h>
0015 
0016 #include "ruleset.h"
0017 #include "setup.h"
0018 
0019 /**
0020  * struct landlock_inode_security - Inode security blob
0021  *
0022  * Enable to reference a &struct landlock_object tied to an inode (i.e.
0023  * underlying object).
0024  */
0025 struct landlock_inode_security {
0026     /**
0027      * @object: Weak pointer to an allocated object.  All assignments of a
0028      * new object are protected by the underlying inode->i_lock.  However,
0029      * atomically disassociating @object from the inode is only protected
0030      * by @object->lock, from the time @object's usage refcount drops to
0031      * zero to the time this pointer is nulled out (cf. release_inode() and
0032      * hook_sb_delete()).  Indeed, such disassociation doesn't require
0033      * inode->i_lock thanks to the careful rcu_access_pointer() check
0034      * performed by get_inode_object().
0035      */
0036     struct landlock_object __rcu *object;
0037 };
0038 
0039 /**
0040  * struct landlock_superblock_security - Superblock security blob
0041  *
0042  * Enable hook_sb_delete() to wait for concurrent calls to release_inode().
0043  */
0044 struct landlock_superblock_security {
0045     /**
0046      * @inode_refs: Number of pending inodes (from this superblock) that
0047      * are being released by release_inode().
0048      * Cf. struct super_block->s_fsnotify_inode_refs .
0049      */
0050     atomic_long_t inode_refs;
0051 };
0052 
0053 static inline struct landlock_inode_security *
0054 landlock_inode(const struct inode *const inode)
0055 {
0056     return inode->i_security + landlock_blob_sizes.lbs_inode;
0057 }
0058 
0059 static inline struct landlock_superblock_security *
0060 landlock_superblock(const struct super_block *const superblock)
0061 {
0062     return superblock->s_security + landlock_blob_sizes.lbs_superblock;
0063 }
0064 
0065 __init void landlock_add_fs_hooks(void);
0066 
0067 int landlock_append_fs_rule(struct landlock_ruleset *const ruleset,
0068                 const struct path *const path,
0069                 access_mask_t access_hierarchy);
0070 
0071 #endif /* _SECURITY_LANDLOCK_FS_H */