@@ -35,6 +35,7 @@
#include <linux/ipc_namespace.h>
#include <linux/user_namespace.h>
#include <linux/slab.h>
+#include <linux/xattr.h>
#include <net/sock.h>
#include "util.h"
@@ -70,6 +71,7 @@ struct mqueue_inode_info {
struct rb_root msg_tree;
struct posix_msg_tree_node *node_cache;
struct mq_attr attr;
+ struct simple_xattrs xattrs; /* list of xattrs */
struct sigevent notify;
struct pid *notify_owner;
@@ -254,6 +256,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
info->attr.mq_maxmsg = attr->mq_maxmsg;
info->attr.mq_msgsize = attr->mq_msgsize;
}
+ simple_xattrs_init(&info->xattrs);
/*
* We used to allocate a static array of pointers and account
* the size of that array as well as one msg_msg struct per
@@ -418,7 +421,8 @@ static int mqueue_create(struct inode *dir, struct dentry *dentry,
{
struct inode *inode;
struct mq_attr *attr = dentry->d_fsdata;
- int error;
+ struct mqueue_inode_info *info;
+ int error = 0;
struct ipc_namespace *ipc_ns;
spin_lock(&mq_lock);
@@ -443,6 +447,18 @@ static int mqueue_create(struct inode *dir, struct dentry *dentry,
ipc_ns->mq_queues_count--;
goto out_unlock;
}
+ info = MQUEUE_I(inode);
+ if (info){
+ error = security_inode_init_security(inode, dir,
+ &dentry->d_name,
+ simple_xattr_initxattrs,
+ &info->xattrs);
+ }
+ if (error && error != -EOPNOTSUPP) {
+ spin_lock(&mq_lock);
+ ipc_ns->mq_queues_count--;
+ goto out_unlock;
+ }
put_ipc_ns(ipc_ns);
dir->i_size += DIRENT_SIZE;
Adds support for generic extended attributes within the POSIX message queues filesystem and setting them by consulting the LSM. This is needed so that the security.selinux extended attribute can be set via a SELinux named type transition on file inodes created within the filesystem. It allows a selinux policy to be created for a set of custom applications that use POSIX message queues for their IPC and uniquely labeling them based on the application that creates the mqueue eliminating the need for relabeling after the mqueue file is created. The implementation is based on tmpfs/shmem and uses the newly created simple_xattr_initxattrs() LSM callback function. Signed-off-by: David Graziano <david.graziano@rockwellcollins.com> --- ipc/mqueue.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)