Thread (16 messages) 16 messages, 3 authors, 2022-11-30

Re: [PATCH v6 4/6] security: Allow all LSMs to provide xattrs for inode_init_security hook

From: Mimi Zohar <zohar@linux.ibm.com>
Date: 2022-11-30 21:24:36
Also in: linux-integrity, lkml, ocfs2-devel, selinux

On Tue, 2022-11-29 at 07:39 -0800, Casey Schaufler wrote:
On 11/29/2022 3:23 AM, Mimi Zohar wrote:
quoted
On Thu, 2022-11-24 at 09:17 +0100, Roberto Sassu wrote:
quoted
On Wed, 2022-11-23 at 20:14 -0500, Mimi Zohar wrote:
quoted
Hi Roberto,

On Wed, 2022-11-23 at 16:47 +0100, Roberto Sassu wrote:
quoted
 int security_inode_init_security(struct inode *inode, struct inode *dir,
                                 const struct qstr *qstr,
                                 const initxattrs initxattrs, void *fs_data)
 {
-       struct xattr new_xattrs[MAX_LSM_EVM_XATTR + 1];
-       struct xattr *lsm_xattr, *evm_xattr, *xattr;
-       int ret;
+       struct security_hook_list *P;
+       struct xattr *new_xattrs;
+       struct xattr *xattr;
+       int ret = -EOPNOTSUPP, num_filled_xattrs = 0;
 
        if (unlikely(IS_PRIVATE(inode)))
                return 0;
 
+       if (!blob_sizes.lbs_xattr)
+               return 0;
+
        if (!initxattrs)
                return call_int_hook(inode_init_security, -EOPNOTSUPP, inode,
-                                    dir, qstr, NULL, NULL, NULL);
-       memset(new_xattrs, 0, sizeof(new_xattrs));
-       lsm_xattr = new_xattrs;
-       ret = call_int_hook(inode_init_security, -EOPNOTSUPP, inode, dir, qstr,
-                                               &lsm_xattr->name,
-                                               &lsm_xattr->value,
-                                               &lsm_xattr->value_len);
-       if (ret)
+                                   dir, qstr, NULL);
+       /* Allocate +1 for EVM and +1 as terminator. */
+       new_xattrs = kcalloc(blob_sizes.lbs_xattr + 2, sizeof(*new_xattrs),
+                            GFP_NOFS);
+       if (!new_xattrs)
+               return -ENOMEM;
+
+       hlist_for_each_entry(P, &security_hook_heads.inode_init_security,
+                            list) {
+               ret = P->hook.inode_init_security(inode, dir, qstr, new_xattrs);
+               if (ret && ret != -EOPNOTSUPP)
+                       goto out;
+               if (ret == -EOPNOTSUPP)
+                       continue;
In this context, -EOPNOTSUPP originally signified that the filesystem
does not support writing xattrs.  Writing any xattr would fail. 
Returning -ENODATA for no LSM xattr(s) data would seem to be more
appropriate than -EOPNOTSUPP.
Hi Mimi

I thought about adding new return values. Currently only -EOPNOTSUPP
and -ENOMEM are expected as errors.

However, changing the conventions would mean revisiting the LSMs code
and ensuring that they follow the new conventions.

I would be more in favor of not touching it.
Casey, Paul, any comment?
I don't see value in adding -ENODATA as a value special to
the infrastructure. What would the infrastructure do differently?
The use of -EOPNOTSUPP isn't consistent throughout, and the amount
of "correctness" you get by returning -ENODATA is really small.
Agreed, it isn't worthwhile for this case.  Roberto, to ease code
review, could you document the overloading of the -EOPNOTSUPP meaning,
which results in the loop continuing?

thanks,

Mimi
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help