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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2022-11-29 at 07:39 -0800, Casey Schaufler wrote:
> On 11/29/2022 3:23 AM, Mimi Zohar wrote:
> > On Thu, 2022-11-24 at 09:17 +0100, Roberto Sassu wrote:
> >> On Wed, 2022-11-23 at 20:14 -0500, Mimi Zohar wrote:
> >>> Hi Roberto,
> >>>
> >>> On Wed, 2022-11-23 at 16:47 +0100, Roberto Sassu wrote:
> >>>>  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




[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux