Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Roberto Sassu and committed by
Paul Moore
de3004c8 52ca4b64

+28 -4
+2
fs/ocfs2/namei.c
··· 242 242 int want_meta = 0; 243 243 int xattr_credits = 0; 244 244 struct ocfs2_security_xattr_info si = { 245 + .name = NULL, 245 246 .enable = 1, 246 247 }; 247 248 int did_quota_inode = 0; ··· 1806 1805 int want_clusters = 0; 1807 1806 int xattr_credits = 0; 1808 1807 struct ocfs2_security_xattr_info si = { 1808 + .name = NULL, 1809 1809 .enable = 1, 1810 1810 }; 1811 1811 int did_quota = 0, did_quota_inode = 0;
+26 -4
fs/ocfs2/xattr.c
··· 7259 7259 static int ocfs2_initxattrs(struct inode *inode, const struct xattr *xattr_array, 7260 7260 void *fs_info) 7261 7261 { 7262 + struct ocfs2_security_xattr_info *si = fs_info; 7262 7263 const struct xattr *xattr; 7263 7264 int err = 0; 7265 + 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 + } 7264 7276 7265 7277 for (xattr = xattr_array; xattr->name != NULL; xattr++) { 7266 7278 err = ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_SECURITY, ··· 7289 7277 const struct qstr *qstr, 7290 7278 struct ocfs2_security_xattr_info *si) 7291 7279 { 7280 + int ret; 7281 + 7292 7282 /* check whether ocfs2 support feature xattr */ 7293 7283 if (!ocfs2_supports_xattr(OCFS2_SB(dir->i_sb))) 7294 7284 return -EOPNOTSUPP; 7295 - if (si) 7296 - return security_old_inode_init_security(inode, dir, qstr, 7297 - &si->name, &si->value, 7298 - &si->value_len); 7285 + if (si) { 7286 + ret = security_inode_init_security(inode, dir, qstr, 7287 + &ocfs2_initxattrs, si); 7288 + /* 7289 + * security_inode_init_security() does not return -EOPNOTSUPP, 7290 + * we have to check the xattr ourselves. 7291 + */ 7292 + if (!ret && !si->name) 7293 + si->enable = 0; 7294 + 7295 + return ret; 7296 + } 7299 7297 7300 7298 return security_inode_init_security(inode, dir, qstr, 7301 7299 &ocfs2_initxattrs, NULL);