Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9d8f13ba authored by Mimi Zohar's avatar Mimi Zohar
Browse files

security: new security_inode_init_security API adds function callback



This patch changes the security_inode_init_security API by adding a
filesystem specific callback to write security extended attributes.
This change is in preparation for supporting the initialization of
multiple LSM xattrs and the EVM xattr.  Initially the callback function
walks an array of xattrs, writing each xattr separately, but could be
optimized to write multiple xattrs at once.

For existing security_inode_init_security() calls, which have not yet
been converted to use the new callback function, such as those in
reiserfs and ocfs2, this patch defines security_old_inode_init_security().

Signed-off-by: default avatarMimi Zohar <zohar@us.ibm.com>
parent 0f2a55d5
Loading
Loading
Loading
Loading
+25 −25
Original line number Original line Diff line number Diff line
@@ -360,36 +360,36 @@ int btrfs_removexattr(struct dentry *dentry, const char *name)
				XATTR_REPLACE);
				XATTR_REPLACE);
}
}


int btrfs_xattr_security_init(struct btrfs_trans_handle *trans,
int btrfs_initxattrs(struct inode *inode, const struct xattr *xattr_array,
			      struct inode *inode, struct inode *dir,
		     void *fs_info)
			      const struct qstr *qstr)
{
{
	int err;
	const struct xattr *xattr;
	size_t len;
	struct btrfs_trans_handle *trans = fs_info;
	void *value;
	char *suffix;
	char *name;
	char *name;
	int err = 0;


	err = security_inode_init_security(inode, dir, qstr, &suffix, &value,
	for (xattr = xattr_array; xattr->name != NULL; xattr++) {
					   &len);
		name = kmalloc(XATTR_SECURITY_PREFIX_LEN +
	if (err) {
			       strlen(xattr->name) + 1, GFP_NOFS);
		if (err == -EOPNOTSUPP)
			return 0;
		return err;
	}

	name = kmalloc(XATTR_SECURITY_PREFIX_LEN + strlen(suffix) + 1,
		       GFP_NOFS);
		if (!name) {
		if (!name) {
			err = -ENOMEM;
			err = -ENOMEM;
	} else {
			break;
		}
		strcpy(name, XATTR_SECURITY_PREFIX);
		strcpy(name, XATTR_SECURITY_PREFIX);
		strcpy(name + XATTR_SECURITY_PREFIX_LEN, suffix);
		strcpy(name + XATTR_SECURITY_PREFIX_LEN, xattr->name);
		err = __btrfs_setxattr(trans, inode, name, value, len, 0);
		err = __btrfs_setxattr(trans, inode, name,
				       xattr->value, xattr->value_len, 0);
		kfree(name);
		kfree(name);
		if (err < 0)
			break;
	}
	}

	kfree(suffix);
	kfree(value);
	return err;
	return err;
}
}

int btrfs_xattr_security_init(struct btrfs_trans_handle *trans,
			      struct inode *inode, struct inode *dir,
			      const struct qstr *qstr)
{
	return security_inode_init_security(inode, dir, qstr,
					    &btrfs_initxattrs, trans);
}
+18 −16
Original line number Original line Diff line number Diff line
@@ -46,28 +46,30 @@ ext2_xattr_security_set(struct dentry *dentry, const char *name,
			      value, size, flags);
			      value, size, flags);
}
}


int
int ext2_initxattrs(struct inode *inode, const struct xattr *xattr_array,
ext2_init_security(struct inode *inode, struct inode *dir,
		    void *fs_info)
		   const struct qstr *qstr)
{
{
	int err;
	const struct xattr *xattr;
	size_t len;
	int err = 0;
	void *value;
	char *name;


	err = security_inode_init_security(inode, dir, qstr, &name, &value, &len);
	for (xattr = xattr_array; xattr->name != NULL; xattr++) {
	if (err) {
		if (err == -EOPNOTSUPP)
			return 0;
		return err;
	}
		err = ext2_xattr_set(inode, EXT2_XATTR_INDEX_SECURITY,
		err = ext2_xattr_set(inode, EXT2_XATTR_INDEX_SECURITY,
			     name, value, len, 0);
				     xattr->name, xattr->value,
	kfree(name);
				     xattr->value_len, 0);
	kfree(value);
		if (err < 0)
			break;
	}
	return err;
	return err;
}
}


int
ext2_init_security(struct inode *inode, struct inode *dir,
		   const struct qstr *qstr)
{
	return security_inode_init_security(inode, dir, qstr,
					    &ext2_initxattrs, NULL);
}

const struct xattr_handler ext2_xattr_security_handler = {
const struct xattr_handler ext2_xattr_security_handler = {
	.prefix	= XATTR_SECURITY_PREFIX,
	.prefix	= XATTR_SECURITY_PREFIX,
	.list	= ext2_xattr_security_list,
	.list	= ext2_xattr_security_list,
+20 −16
Original line number Original line Diff line number Diff line
@@ -48,28 +48,32 @@ ext3_xattr_security_set(struct dentry *dentry, const char *name,
			      name, value, size, flags);
			      name, value, size, flags);
}
}


int
int ext3_initxattrs(struct inode *inode, const struct xattr *xattr_array,
ext3_init_security(handle_t *handle, struct inode *inode, struct inode *dir,
		    void *fs_info)
		   const struct qstr *qstr)
{
{
	int err;
	const struct xattr *xattr;
	size_t len;
	handle_t *handle = fs_info;
	void *value;
	int err = 0;
	char *name;


	err = security_inode_init_security(inode, dir, qstr, &name, &value, &len);
	for (xattr = xattr_array; xattr->name != NULL; xattr++) {
	if (err) {
		err = ext3_xattr_set_handle(handle, inode,
		if (err == -EOPNOTSUPP)
					    EXT3_XATTR_INDEX_SECURITY,
			return 0;
					    xattr->name, xattr->value,
		return err;
					    xattr->value_len, 0);
		if (err < 0)
			break;
	}
	}
	err = ext3_xattr_set_handle(handle, inode, EXT3_XATTR_INDEX_SECURITY,
				    name, value, len, 0);
	kfree(name);
	kfree(value);
	return err;
	return err;
}
}


int
ext3_init_security(handle_t *handle, struct inode *inode, struct inode *dir,
		   const struct qstr *qstr)
{
	return security_inode_init_security(inode, dir, qstr,
					    &ext3_initxattrs, handle);
}

const struct xattr_handler ext3_xattr_security_handler = {
const struct xattr_handler ext3_xattr_security_handler = {
	.prefix	= XATTR_SECURITY_PREFIX,
	.prefix	= XATTR_SECURITY_PREFIX,
	.list	= ext3_xattr_security_list,
	.list	= ext3_xattr_security_list,
+20 −16
Original line number Original line Diff line number Diff line
@@ -48,28 +48,32 @@ ext4_xattr_security_set(struct dentry *dentry, const char *name,
			      name, value, size, flags);
			      name, value, size, flags);
}
}


int
int ext4_initxattrs(struct inode *inode, const struct xattr *xattr_array,
ext4_init_security(handle_t *handle, struct inode *inode, struct inode *dir,
		    void *fs_info)
		   const struct qstr *qstr)
{
{
	int err;
	const struct xattr *xattr;
	size_t len;
	handle_t *handle = fs_info;
	void *value;
	int err = 0;
	char *name;


	err = security_inode_init_security(inode, dir, qstr, &name, &value, &len);
	for (xattr = xattr_array; xattr->name != NULL; xattr++) {
	if (err) {
		err = ext4_xattr_set_handle(handle, inode,
		if (err == -EOPNOTSUPP)
					    EXT4_XATTR_INDEX_SECURITY,
			return 0;
					    xattr->name, xattr->value,
		return err;
					    xattr->value_len, 0);
		if (err < 0)
			break;
	}
	}
	err = ext4_xattr_set_handle(handle, inode, EXT4_XATTR_INDEX_SECURITY,
				    name, value, len, 0);
	kfree(name);
	kfree(value);
	return err;
	return err;
}
}


int
ext4_init_security(handle_t *handle, struct inode *inode, struct inode *dir,
		   const struct qstr *qstr)
{
	return security_inode_init_security(inode, dir, qstr,
					    &ext4_initxattrs, handle);
}

const struct xattr_handler ext4_xattr_security_handler = {
const struct xattr_handler ext4_xattr_security_handler = {
	.prefix	= XATTR_SECURITY_PREFIX,
	.prefix	= XATTR_SECURITY_PREFIX,
	.list	= ext4_xattr_security_list,
	.list	= ext4_xattr_security_list,
+18 −20
Original line number Original line Diff line number Diff line
@@ -624,29 +624,27 @@ fail:
	return error;
	return error;
}
}


static int gfs2_security_init(struct gfs2_inode *dip, struct gfs2_inode *ip,
int gfs2_initxattrs(struct inode *inode, const struct xattr *xattr_array,
			      const struct qstr *qstr)
		    void *fs_info)
{
{
	int err;
	const struct xattr *xattr;
	size_t len;
	int err = 0;
	void *value;
	char *name;


	err = security_inode_init_security(&ip->i_inode, &dip->i_inode, qstr,
	for (xattr = xattr_array; xattr->name != NULL; xattr++) {
					   &name, &value, &len);
		err = __gfs2_xattr_set(inode, xattr->name, xattr->value,

				       xattr->value_len, 0,
	if (err) {
				       GFS2_EATYPE_SECURITY);
		if (err == -EOPNOTSUPP)
		if (err < 0)
			return 0;
			break;
	}
	return err;
	return err;
}
}


	err = __gfs2_xattr_set(&ip->i_inode, name, value, len, 0,
static int gfs2_security_init(struct gfs2_inode *dip, struct gfs2_inode *ip,
			       GFS2_EATYPE_SECURITY);
			      const struct qstr *qstr)
	kfree(value);
{
	kfree(name);
	return security_inode_init_security(&ip->i_inode, &dip->i_inode, qstr,

					    &gfs2_initxattrs, NULL);
	return err;
}
}


/**
/**
Loading