aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorOndrej Mosnacek <omosnace@redhat.com>2019-02-22 15:57:16 +0100
committerPaul Moore <paul@paul-moore.com>2019-03-20 22:01:02 -0400
commitb230d5aba2d1a7b0636408889a75bf9eae6b8bc7 (patch)
tree57bacbcb8d8114c376cef0d23110a236af5e985a /fs
parentkernfs: use simple_xattrs for security attributes (diff)
downloadlinux-dev-b230d5aba2d1a7b0636408889a75bf9eae6b8bc7.tar.xz
linux-dev-b230d5aba2d1a7b0636408889a75bf9eae6b8bc7.zip
LSM: add new hook for kernfs node initialization
This patch introduces a new security hook that is intended for initializing the security data for newly created kernfs nodes, which provide a way of storing a non-default security context, but need to operate independently from mounts (and therefore may not have an associated inode at the moment of creation). The main motivation is to allow kernfs nodes to inherit the context of the parent under SELinux, similar to the behavior of security_inode_init_security(). Other LSMs may implement their own logic for handling the creation of new nodes. This patch also adds helper functions to <linux/kernfs.h> for getting/setting security xattrs of a kernfs node so that LSMs hooks are able to do their job. Other important attributes should be accessible direcly in the kernfs_node fields (in case there is need for more, then new helpers should be added to kernfs.h along with the patch that needs them). Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com> Acked-by: Casey Schaufler <casey@schaufler-ca.com> [PM: more manual merge fixes] Signed-off-by: Paul Moore <paul@paul-moore.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/kernfs/inode.c48
1 files changed, 39 insertions, 9 deletions
diff --git a/fs/kernfs/inode.c b/fs/kernfs/inode.c
index a365088caa3c..673ef598d97d 100644
--- a/fs/kernfs/inode.c
+++ b/fs/kernfs/inode.c
@@ -288,12 +288,11 @@ int kernfs_iop_permission(struct inode *inode, int mask)
return generic_permission(inode, mask);
}
-static int kernfs_xattr_get(const struct xattr_handler *handler,
- struct dentry *unused, struct inode *inode,
- const char *suffix, void *value, size_t size)
+static int kernfs_node_xattr_get(const struct xattr_handler *handler,
+ struct kernfs_node *kn, const char *suffix,
+ void *value, size_t size)
{
const char *name = xattr_full_name(handler, suffix);
- struct kernfs_node *kn = inode->i_private;
struct kernfs_iattrs *attrs;
attrs = kernfs_iattrs_noalloc(kn);
@@ -303,13 +302,11 @@ static int kernfs_xattr_get(const struct xattr_handler *handler,
return simple_xattr_get(&attrs->xattrs, name, value, size);
}
-static int kernfs_xattr_set(const struct xattr_handler *handler,
- struct dentry *unused, struct inode *inode,
- const char *suffix, const void *value,
- size_t size, int flags)
+static int kernfs_node_xattr_set(const struct xattr_handler *handler,
+ struct kernfs_node *kn, const char *suffix,
+ const void *value, size_t size, int flags)
{
const char *name = xattr_full_name(handler, suffix);
- struct kernfs_node *kn = inode->i_private;
struct kernfs_iattrs *attrs;
attrs = kernfs_iattrs(kn);
@@ -319,6 +316,25 @@ static int kernfs_xattr_set(const struct xattr_handler *handler,
return simple_xattr_set(&attrs->xattrs, name, value, size, flags);
}
+static int kernfs_xattr_get(const struct xattr_handler *handler,
+ struct dentry *unused, struct inode *inode,
+ const char *suffix, void *value, size_t size)
+{
+ struct kernfs_node *kn = inode->i_private;
+
+ return kernfs_node_xattr_get(handler, kn, suffix, value, size);
+}
+
+static int kernfs_xattr_set(const struct xattr_handler *handler,
+ struct dentry *unused, struct inode *inode,
+ const char *suffix, const void *value,
+ size_t size, int flags)
+{
+ struct kernfs_node *kn = inode->i_private;
+
+ return kernfs_node_xattr_set(handler, kn, suffix, value, size, flags);
+}
+
static const struct xattr_handler kernfs_trusted_xattr_handler = {
.prefix = XATTR_TRUSTED_PREFIX,
.get = kernfs_xattr_get,
@@ -336,3 +352,17 @@ const struct xattr_handler *kernfs_xattr_handlers[] = {
&kernfs_security_xattr_handler,
NULL
};
+
+int kernfs_security_xattr_get(struct kernfs_node *kn, const char *suffix,
+ void *value, size_t size)
+{
+ return kernfs_node_xattr_get(&kernfs_security_xattr_handler,
+ kn, suffix, value, size);
+}
+
+int kernfs_security_xattr_set(struct kernfs_node *kn, const char *suffix,
+ void *value, size_t size, int flags)
+{
+ return kernfs_node_xattr_set(&kernfs_security_xattr_handler,
+ kn, suffix, value, size, flags);
+}