Skip to content

Commit de3004c

Browse files
robertosassupcmoore
authored andcommitted
ocfs2: Switch to security_inode_init_security()
In preparation for removing security_old_inode_init_security(), switch to security_inode_init_security(). Extend the existing ocfs2_initxattrs() to take the ocfs2_security_xattr_info structure from fs_info, and populate the name/value/len triple with the first xattr provided by LSMs. As fs_info was not used before, ocfs2_initxattrs() can now handle the case of replicating the behavior of security_old_inode_init_security(), i.e. just obtaining the xattr, in addition to setting all xattrs provided by LSMs. Supporting multiple xattrs is not currently supported where security_old_inode_init_security() was called (mknod, symlink), as it requires non-trivial changes that can be done at a later time. Like for reiserfs, even if EVM is invoked, it will not provide an xattr (if it is not the first to set it, its xattr will be discarded; if it is the first, it does not have xattrs to calculate the HMAC on). Finally, since security_inode_init_security(), unlike security_old_inode_init_security(), returns zero instead of -EOPNOTSUPP if no xattrs were provided by LSMs or if inodes are private, additionally check in ocfs2_init_security_get() if the xattr name is set. If not, act as if security_old_inode_init_security() returned -EOPNOTSUPP, and set si->enable to zero to notify to the functions following ocfs2_init_security_get() that no xattrs are available. Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Reviewed-by: Casey Schaufler <casey@schaufler-ca.com> Acked-by: Joseph Qi <joseph.qi@linux.alibaba.com> Reviewed-by: Mimi Zohar <zohar@linux.ibm.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 52ca4b6 commit de3004c

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

fs/ocfs2/namei.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ static int ocfs2_mknod(struct mnt_idmap *idmap,
242242
int want_meta = 0;
243243
int xattr_credits = 0;
244244
struct ocfs2_security_xattr_info si = {
245+
.name = NULL,
245246
.enable = 1,
246247
};
247248
int did_quota_inode = 0;
@@ -1805,6 +1806,7 @@ static int ocfs2_symlink(struct mnt_idmap *idmap,
18051806
int want_clusters = 0;
18061807
int xattr_credits = 0;
18071808
struct ocfs2_security_xattr_info si = {
1809+
.name = NULL,
18081810
.enable = 1,
18091811
};
18101812
int did_quota = 0, did_quota_inode = 0;

fs/ocfs2/xattr.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7259,9 +7259,21 @@ static int ocfs2_xattr_security_set(const struct xattr_handler *handler,
72597259
static int ocfs2_initxattrs(struct inode *inode, const struct xattr *xattr_array,
72607260
void *fs_info)
72617261
{
7262+
struct ocfs2_security_xattr_info *si = fs_info;
72627263
const struct xattr *xattr;
72637264
int err = 0;
72647265

7266+
if (si) {
7267+
si->value = kmemdup(xattr_array->value, xattr_array->value_len,
7268+
GFP_KERNEL);
7269+
if (!si->value)
7270+
return -ENOMEM;
7271+
7272+
si->name = xattr_array->name;
7273+
si->value_len = xattr_array->value_len;
7274+
return 0;
7275+
}
7276+
72657277
for (xattr = xattr_array; xattr->name != NULL; xattr++) {
72667278
err = ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_SECURITY,
72677279
xattr->name, xattr->value,
@@ -7277,13 +7289,23 @@ int ocfs2_init_security_get(struct inode *inode,
72777289
const struct qstr *qstr,
72787290
struct ocfs2_security_xattr_info *si)
72797291
{
7292+
int ret;
7293+
72807294
/* check whether ocfs2 support feature xattr */
72817295
if (!ocfs2_supports_xattr(OCFS2_SB(dir->i_sb)))
72827296
return -EOPNOTSUPP;
7283-
if (si)
7284-
return security_old_inode_init_security(inode, dir, qstr,
7285-
&si->name, &si->value,
7286-
&si->value_len);
7297+
if (si) {
7298+
ret = security_inode_init_security(inode, dir, qstr,
7299+
&ocfs2_initxattrs, si);
7300+
/*
7301+
* security_inode_init_security() does not return -EOPNOTSUPP,
7302+
* we have to check the xattr ourselves.
7303+
*/
7304+
if (!ret && !si->name)
7305+
si->enable = 0;
7306+
7307+
return ret;
7308+
}
72877309

72887310
return security_inode_init_security(inode, dir, qstr,
72897311
&ocfs2_initxattrs, NULL);

0 commit comments

Comments
 (0)