From: Mimi Zohar <zohar@linux.ibm.com>
To: Roberto Sassu <roberto.sassu@huaweicloud.com>,
mark@fasheh.com, jlbec@evilplan.org, joseph.qi@linux.alibaba.com,
dmitry.kasatkin@gmail.com, paul@paul-moore.com,
jmorris@namei.org, serge@hallyn.com,
stephen.smalley.work@gmail.com, eparis@parisplace.org,
casey@schaufler-ca.com
Cc: ocfs2-devel@oss.oracle.com, reiserfs-devel@vger.kernel.org,
linux-integrity@vger.kernel.org,
linux-security-module@vger.kernel.org, selinux@vger.kernel.org,
linux-kernel@vger.kernel.org, keescook@chromium.org,
nicolas.bouchinet@clip-os.org,
Roberto Sassu <roberto.sassu@huawei.com>
Subject: Re: [PATCH v6 4/6] security: Allow all LSMs to provide xattrs for inode_init_security hook
Date: Tue, 29 Nov 2022 06:23:02 -0500 [thread overview]
Message-ID: <9859294adb0a9b9587ea7fb70a836a312aaf3c69.camel@linux.ibm.com> (raw)
In-Reply-To: <bb63eba9a9f24558f4a1acd9bf012b59b5c6e98e.camel@huaweicloud.com>
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?
> >
> > > + /*
> > > + * As the number of xattrs reserved by LSMs is not directly
> > > + * available, directly use the total number blob_sizes.lbs_xattr
> > > + * to keep the code simple, while being not the most efficient
> > > + * way.
> > > + */
> > > + ret = security_check_compact_filled_xattrs(new_xattrs,
> > > + blob_sizes.lbs_xattr,
> > > + &num_filled_xattrs);
> > > + if (ret < 0) {
> > > + ret = -ENOMEM;
> > > + goto out;
> > > + }
> > > + }
> > > +
> > > + if (!num_filled_xattrs)
> > > goto out;
> > >
> > > - evm_xattr = lsm_xattr + 1;
> > > - ret = evm_inode_init_security(inode, lsm_xattr, evm_xattr);
> > > + ret = evm_inode_init_security(inode, new_xattrs,
> > > + new_xattrs + num_filled_xattrs);
> > > if (ret)
> > > goto out;
> > > ret = initxattrs(inode, new_xattrs, fs_data);
> > > out:
> > > for (xattr = new_xattrs; xattr->value != NULL; xattr++)
> > > kfree(xattr->value);
> > > + kfree(new_xattrs);
> > > return (ret == -EOPNOTSUPP) ? 0 : ret;
> > > }
> > b
>
next prev parent reply other threads:[~2022-11-29 11:23 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-23 15:47 [PATCH v6 0/6] evm: Do HMAC of multiple per LSM xattrs for new inodes Roberto Sassu
2022-11-23 15:47 ` [PATCH v6 1/6] reiserfs: Switch to security_inode_init_security() Roberto Sassu
2022-11-23 15:47 ` [PATCH v6 2/6] ocfs2: " Roberto Sassu
2022-11-23 15:47 ` [PATCH v6 3/6] security: Remove security_old_inode_init_security() Roberto Sassu
2022-11-23 15:47 ` [PATCH v6 4/6] security: Allow all LSMs to provide xattrs for inode_init_security hook Roberto Sassu
2022-11-23 17:17 ` Casey Schaufler
2022-11-24 7:55 ` Roberto Sassu
2022-11-24 1:14 ` Mimi Zohar
2022-11-24 8:17 ` Roberto Sassu
2022-11-29 11:23 ` Mimi Zohar [this message]
2022-11-29 15:39 ` Casey Schaufler
2022-11-30 21:23 ` Mimi Zohar
2022-11-23 15:47 ` [PATCH v6 5/6] evm: Align evm_inode_init_security() definition with LSM infrastructure Roberto Sassu
2022-11-23 15:47 ` [PATCH v6 6/6] evm: Support multiple LSMs providing an xattr Roberto Sassu
2022-11-23 16:22 ` [PATCH v6 0/6] evm: Do HMAC of multiple per LSM xattrs for new inodes Mimi Zohar
2022-11-23 17:20 ` Casey Schaufler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9859294adb0a9b9587ea7fb70a836a312aaf3c69.camel@linux.ibm.com \
--to=zohar@linux.ibm.com \
--cc=casey@schaufler-ca.com \
--cc=dmitry.kasatkin@gmail.com \
--cc=eparis@parisplace.org \
--cc=jlbec@evilplan.org \
--cc=jmorris@namei.org \
--cc=joseph.qi@linux.alibaba.com \
--cc=keescook@chromium.org \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=mark@fasheh.com \
--cc=nicolas.bouchinet@clip-os.org \
--cc=ocfs2-devel@oss.oracle.com \
--cc=paul@paul-moore.com \
--cc=reiserfs-devel@vger.kernel.org \
--cc=roberto.sassu@huawei.com \
--cc=roberto.sassu@huaweicloud.com \
--cc=selinux@vger.kernel.org \
--cc=serge@hallyn.com \
--cc=stephen.smalley.work@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).