Skip to contentSkip to conversation

ceph: add selinux support

PATCH New Yan, Zheng 1 participant 1 message May 29, 2019 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

Yan, Zheng

author
#2 lore raw

PATCH 2/2 ceph: add selinux support

---------- Forwarded message ---------
From: Yan, Zheng <[email protected]>
Date: Mon, May 27, 2019 at 7:11 PM
Subject: [PATCH 2/2] ceph: add selinux support
To: <[email protected]>
Cc: <[email protected]>, <[email protected]>, Yan, Zheng <[email protected]>

When creating new file/directory, uses dentry_init_security() to prepare selinux context for the new inode, then sends openc/mkdir request to MDS, together with selinux xattr.

---
 fs/ceph/Kconfig |  12 +++++
 fs/ceph/caps.c  |   1 +
 fs/ceph/dir.c   |  12 +++++
 fs/ceph/file.c  |   3 ++
 fs/ceph/inode.c |   1 +
 fs/ceph/super.h |  19 +++++++
 fs/ceph/xattr.c | 141 ++++++++++++++++++++++++++++++++++++++++++------
 7 files changed, 172 insertions(+), 17 deletions(-)
fs/ceph/Kconfig +12 -0
index 52095f473464..5a665c126a7c 100644
@@ -35,3 +35,15 @@ config CEPH_FS_POSIX_ACL
          groups beyond the owner/group/world scheme.
 
          If you don't know what Access Control Lists are, say N
+
+config CEPH_FS_SECURITY_LABEL
+       bool "CephFS Security Labels"
+       depends on CEPH_FS && SECURITY
+       help
+         Security labels support alternative access control models
+         implemented by security modules like SELinux. This option
+         enables an extended attribute handler for file security
+         labels in the Ceph filesystem.
+
+         If you are not using a security module that requires using
+         extended attributes for file security labels, say N.
fs/ceph/caps.c +1 -0
index 7754d7679122..50409d9fdc90 100644
@@ -3156,6 +3156,7 @@ static void handle_cap_grant(struct inode *inode,
                        ci->i_xattrs.blob = ceph_buffer_get(xattr_buf);
                        ci->i_xattrs.version = version;
                        ceph_forget_all_cached_acls(inode);
+                       ceph_security_invalidate_secctx(inode);
                }
        }
 
fs/ceph/dir.c +0 -0
index 14d795e5fa73..b282d076dc9e 100644
@@ -839,6 +839,9 @@ static int ceph_mknod(struct inode *dir, struct

dentry *dentry,

        err = ceph_pre_init_acls(dir, &mode, &as_ctx);
        if (err < 0)
                goto out;

+ err = ceph_security_init_secctx(dentry, mode, &as_ctx);
+ if (err < 0)
+ goto out;

dout("mknod in dir %p dentry %p mode 0%ho rdev %d\n",
dir, dentry, mode, rdev);
@@ -884,6 +887,7 @@ static int ceph_symlink(struct inode *dir, struct dentry *dentry,

        struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb);
        struct ceph_mds_client *mdsc = fsc->mdsc;
        struct ceph_mds_request *req;
+       struct ceph_acl_sec_ctx as_ctx = {};
        int err;

        if (ceph_snap(dir) != CEPH_NOSNAP)
@@ -894,6 +898,10 @@ static int ceph_symlink(struct inode *dir, struct
dentry *dentry,
                goto out;
        }

+ err = ceph_security_init_secctx(dentry, S_IFLNK | S_IRWXUGO, &as_ctx);
+ if (err < 0)
+ goto out;
+

        dout("symlink in dir %p dentry %p to '%s'\n", dir, dentry, dest);
        req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_SYMLINK, USE_AUTH_MDS);
        if (IS_ERR(req)) {
@@ -919,6 +927,7 @@ static int ceph_symlink(struct inode *dir, struct
dentry *dentry,
 out:
        if (err)
                d_drop(dentry);
+       ceph_release_acl_sec_ctx(&as_ctx);
        return err;

}

@@ -953,6 +962,9 @@ static int ceph_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)

        err = ceph_pre_init_acls(dir, &mode, &as_ctx);
        if (err < 0)
                goto out;

+ err = ceph_security_init_secctx(dentry, mode, &as_ctx);
+ if (err < 0)
+ goto out;

        req = ceph_mdsc_create_request(mdsc, op, USE_AUTH_MDS);
        if (IS_ERR(req)) {
fs/ceph/file.c +0 -0
index 5975345753d7..a7080783fe20 100644
@@ -453,6 +453,9 @@ int ceph_atomic_open(struct inode *dir, struct

dentry *dentry,

                err = ceph_pre_init_acls(dir, &mode, &as_ctx);
                if (err < 0)
                        return err;
+               err = ceph_security_init_secctx(dentry, mode, &as_ctx);
+               if (err < 0)
+                       goto out_ctx;
        }

        /* do the open */
fs/ceph/inode.c +0 -0
index 30d0cdc21035..125ac54b5841 100644
@@ -891,6 +891,7 @@ static int fill_inode(struct inode *inode, struct

page *locked_page,

                               iinfo->xattr_data, iinfo->xattr_len);
                ci->i_xattrs.version = le64_to_cpu(info->xattr_version);
                ceph_forget_all_cached_acls(inode);
+               ceph_security_invalidate_secctx(inode);
                xattr_blob = NULL;
        }
fs/ceph/super.h +4 -0
index d7520ccf27e9..9c82d213a5ab 100644
@@ -932,6 +932,10 @@ struct ceph_acl_sec_ctx {
 #ifdef CONFIG_CEPH_FS_POSIX_ACL
        void *default_acl;
        void *acl;
+#endif
+#ifdef CONFIG_CEPH_FS_SECURITY_LABEL
+       void *sec_ctx;
+       u32 sec_ctxlen;
 #endif
        struct ceph_pagelist *pagelist;
 };
@@ -950,6 +954,21 @@ static inline bool

ceph_security_xattr_wanted(struct inode *in)
}
#endif

+#ifdef CONFIG_CEPH_FS_SECURITY_LABEL
+extern int ceph_security_init_secctx(struct dentry *dentry, umode_t mode,
+ struct ceph_acl_sec_ctx *ctx);
+extern void ceph_security_invalidate_secctx(struct inode *inode); +#else
+static inline int ceph_security_init_secctx(struct dentry *dentry, umode_t mode,
+ struct ceph_acl_sec_ctx *ctx)
+{
+ return 0;
+}
+static inline void ceph_security_invalidate_secctx(struct inode *inode) +{
+}
+#endif
+
void ceph_release_acl_sec_ctx(struct ceph_acl_sec_ctx *as_ctx);

/* acl.c */

fs/ceph/xattr.c +105 -17

143 lines not on this page · raw message

ceph_acl_sec_ctx *as_ctx)

 #ifdef CONFIG_CEPH_FS_POSIX_ACL
        posix_acl_release(as_ctx->acl);
        posix_acl_release(as_ctx->default_acl);
+#endif
+#ifdef CONFIG_CEPH_FS_SECURITY_LABEL
+       security_release_secctx(as_ctx->sec_ctx, as_ctx->sec_ctxlen);
 #endif
        if (as_ctx->pagelist)
                ceph_pagelist_release(as_ctx->pagelist);

}
+
+/*
+ * List of handlers for synthetic system.* attributes. Other
+ * attributes are handled directly.
+ */
+const struct xattr_handler *ceph_xattr_handlers[] = { +#ifdef CONFIG_CEPH_FS_POSIX_ACL
+ &posix_acl_access_xattr_handler,
+ &posix_acl_default_xattr_handler,
+#endif
+#ifdef CONFIG_CEPH_FS_SECURITY_LABEL
+ &ceph_security_label_handler,
+#endif
+ &ceph_other_xattr_handler,
+ NULL,
+};
--
2.17.2