From: Christian Brauner <christian.brauner@ubuntu.com>
To: Roberto Sassu <roberto.sassu@huawei.com>
Cc: "zohar@linux.ibm.com" <zohar@linux.ibm.com>,
"mjg59@google.com" <mjg59@google.com>,
"agruenba@redhat.com" <agruenba@redhat.com>,
"linux-integrity@vger.kernel.org"
<linux-integrity@vger.kernel.org>,
"linux-security-module@vger.kernel.org"
<linux-security-module@vger.kernel.org>,
"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v4 08/11] evm: Allow setxattr() and setattr() for unmodified metadata
Date: Thu, 25 Mar 2021 13:13:41 +0100 [thread overview]
Message-ID: <20210325121341.q2ufjhnqe3osjc7c@wittgenstein> (raw)
In-Reply-To: <ad33c998ee834a588e0ca1a31ee2a530@huawei.com>
On Thu, Mar 25, 2021 at 10:53:43AM +0000, Roberto Sassu wrote:
> > From: Roberto Sassu
> > Sent: Friday, March 5, 2021 4:19 PM
> > With the patch to allow xattr/attr operations if a portable signature
> > verification fails, cp and tar can copy all xattrs/attrs so that at the
> > end of the process verification succeeds.
> >
> > However, it might happen that the xattrs/attrs are already set to the
> > correct value (taken at signing time) and signature verification succeeds
> > before the copy has completed. For example, an archive might contains files
> > owned by root and the archive is extracted by root.
> >
> > Then, since portable signatures are immutable, all subsequent operations
> > fail (e.g. fchown()), even if the operation is legitimate (does not alter
> > the current value).
> >
> > This patch avoids this problem by reporting successful operation to user
> > space when that operation does not alter the current value of xattrs/attrs.
> >
> > Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
> > ---
> > security/integrity/evm/evm_main.c | 96
> > +++++++++++++++++++++++++++++++
> > 1 file changed, 96 insertions(+)
> >
> > diff --git a/security/integrity/evm/evm_main.c
> > b/security/integrity/evm/evm_main.c
> > index eab536fa260f..a07516dcb920 100644
> > --- a/security/integrity/evm/evm_main.c
> > +++ b/security/integrity/evm/evm_main.c
> > @@ -18,6 +18,7 @@
> > #include <linux/integrity.h>
> > #include <linux/evm.h>
> > #include <linux/magic.h>
> > +#include <linux/posix_acl_xattr.h>
> >
> > #include <crypto/hash.h>
> > #include <crypto/hash_info.h>
> > @@ -328,6 +329,79 @@ static enum integrity_status
> > evm_verify_current_integrity(struct dentry *dentry)
> > return evm_verify_hmac(dentry, NULL, NULL, 0, NULL);
> > }
> >
> > +/*
> > + * evm_xattr_acl_change - check if passed ACL changes the inode mode
> > + * @dentry: pointer to the affected dentry
> > + * @xattr_name: requested xattr
> > + * @xattr_value: requested xattr value
> > + * @xattr_value_len: requested xattr value length
> > + *
> > + * Check if passed ACL changes the inode mode, which is protected by
> > EVM.
> > + *
> > + * Returns 1 if passed ACL causes inode mode change, 0 otherwise.
> > + */
> > +static int evm_xattr_acl_change(struct dentry *dentry, const char
> > *xattr_name,
> > + const void *xattr_value, size_t
> > xattr_value_len)
> > +{
> > + umode_t mode;
> > + struct posix_acl *acl = NULL, *acl_res;
> > + struct inode *inode = d_backing_inode(dentry);
> > + int rc;
> > +
> > + /* UID/GID in ACL have been already converted from user to init ns
> > */
> > + acl = posix_acl_from_xattr(&init_user_ns, xattr_value,
> > xattr_value_len);
> > + if (!acl)
>
> Based on Mimi's review, I will change this to:
>
> if (IS_ERR_OR_NULL(acl))
>
> > + return 1;
> > +
> > + acl_res = acl;
> > + rc = posix_acl_update_mode(&init_user_ns, inode, &mode,
> > &acl_res);
>
> About this part, probably it is not correct.
>
> I'm writing a test for this patch that checks if operations
> that don't change the file mode succeed and those that
> do fail.
>
> mount-idmapped --map-mount b:3001:0:1 /mnt /mnt-idmapped
> pushd /mnt
> echo "test" > test-file
> chown 3001 test-file
> chgrp 3001 test-file
> chmod 2644 test-file
> <check enabled>
> setfacl --set u::rw,g::r,o::r,m:r test-file (expected to succeed, caller has CAP_FSETID, so S_ISGID is not dropped)
> setfacl --set u::rw,g::r,o::r,m:rw test-file (expected to fail)
> pushd /mnt-idmapped
> capsh --drop=cap_fsetid -- -c setfacl --set u::rw,g::r,o::r test-file (expected to succeed, caller is in the owning group of test-file, so S_ISGID is not dropped)
>
> After adding a debug line in posix_acl_update_mode():
> printk("%s: %d(%d) %d\n", __func__, in_group_p(i_gid_into_mnt(mnt_userns, inode)), __kgid_val(i_gid_into_mnt(mnt_userns, inode)), capable_wrt_inode_uidgid(mnt_userns, inode, CAP_FSETID));
>
> without passing mnt_userns:
> [ 748.262582] setfacl --set u::rw,g::r,o::r,m:r test-file
> [ 748.268021] posix_acl_update_mode: 0(3001) 1
> [ 748.268035] posix_acl_update_mode: 0(3001) 1
> [ 748.268570] setfacl --set u::rw,g::r,o::r,m:rw test-file
> [ 748.274193] posix_acl_update_mode: 0(3001) 1
> [ 748.279198] capsh --drop=cap_fsetid -- -c setfacl --set u::rw,g::r,o::r test-file
> [ 748.287894] posix_acl_update_mode: 0(3001) 0
>
> passing mnt_userns:
> [ 81.159766] setfacl --set u::rw,g::r,o::r,m:r test-file
> [ 81.165207] posix_acl_update_mode: 0(3001) 1
> [ 81.165226] posix_acl_update_mode: 0(3001) 1
> [ 81.165732] setfacl --set u::rw,g::r,o::r,m:rw test-file
> [ 81.170978] posix_acl_update_mode: 0(3001) 1
> [ 81.176014] capsh --drop=cap_fsetid -- -c setfacl --set u::rw,g::r,o::r test-file
> [ 81.184648] posix_acl_update_mode: 1(0) 0
> [ 81.184663] posix_acl_update_mode: 1(0) 0
>
> The difference is that, by passing mnt_userns, the caller (root) is
> in the owning group of the file (3001 -> 0). Without passing mnt_userns,
> it is not (3001 -> 3001).
>
> Christian, Andreas, could you confirm that this is correct?
Hey Robert,
Thanks for the Cc and thanks for testing this with and without idmapped
mounts; very much appreciated.
>
> If there are no objections, I will send an additional patch to pass
> mnt_userns to EVM.
Yes, since you're starting to verify attrs and posix_acl changes that
deal with uids/gids you need to account for the mnt_userns. I've pulled
and applied your patch locally and looked through it. I think you need
to change:
- evm_inode_setxattr()
- evm_inode_removexattr()
to take a mnt_userns. That should be straightforward. I already changed
security_inode_setxattr() to pass down the mnt_userns so you need to
simply pass that further down:
- security_inode_setxattr(mnt_userns, ...)
-> evm_inode_setxattr(mnt_userns, ...)
- security_inode_removexattr(mnt_userns, ...)
-> evm_inode_removexattr(mnt_userns, ...)
The rest looks sane to me.
Fwiw, I'm mainting a large test-suite that I wrote for idmapped mounts
but that aims to cover all vfs operations independent of them. It aims
for:
- test vfs feature x on regular mounts
- test vfs feature on idmapped mounts
- test vfs feature in user namespaces
- test vfs feature on idmapped mount in user namespaces
I'm in the process of upstreaming it for xfstests (cf. [1]). It also
includes tests for xattrs/acls and fscaps. if ima and evm want to add
something to this that'd be great but if you maintain your own testing
that's of course totally ok.
[1]: https://git.kernel.org/pub/scm/linux/kernel/git/brauner/xfstests-dev.git/log/?h=idmapped_mounts
Thanks!
Christian
next prev parent reply other threads:[~2021-03-25 12:14 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-05 15:19 [PATCH v4 00/11] evm: Improve usability of portable signatures Roberto Sassu
2021-03-05 15:19 ` [PATCH v4 01/11] evm: Execute evm_inode_init_security() only when an HMAC key is loaded Roberto Sassu
2021-03-05 15:19 ` [PATCH v4 02/11] evm: Load EVM key in ima_load_x509() to avoid appraisal Roberto Sassu
2021-03-05 15:19 ` [PATCH v4 03/11] evm: Refuse EVM_ALLOW_METADATA_WRITES only if an HMAC key is loaded Roberto Sassu
2021-03-05 15:19 ` [PATCH v4 04/11] ima: Move ima_reset_appraise_flags() call to post hooks Roberto Sassu
2021-03-05 17:30 ` Casey Schaufler
2021-04-26 19:49 ` Mimi Zohar
2021-04-27 9:25 ` Roberto Sassu
2021-04-27 15:34 ` Mimi Zohar
2021-04-27 15:57 ` Roberto Sassu
2021-04-27 16:03 ` Mimi Zohar
2021-04-27 16:39 ` Casey Schaufler
2021-04-27 16:48 ` Mimi Zohar
2021-04-28 7:48 ` Roberto Sassu
2021-04-28 15:35 ` Roberto Sassu
2021-04-30 18:00 ` Mimi Zohar
2021-05-03 7:41 ` Roberto Sassu
2021-05-03 13:21 ` Mimi Zohar
2021-03-05 15:19 ` [PATCH v4 05/11] evm: Introduce evm_status_revalidate() Roberto Sassu
2021-03-05 15:19 ` [PATCH v4 06/11] evm: Ignore INTEGRITY_NOLABEL/INTEGRITY_NOXATTRS if conditions are safe Roberto Sassu
2021-03-05 15:19 ` [PATCH v4 07/11] evm: Allow xattr/attr operations for portable signatures Roberto Sassu
2021-03-05 15:19 ` [PATCH v4 08/11] evm: Allow setxattr() and setattr() for unmodified metadata Roberto Sassu
2021-03-25 10:53 ` Roberto Sassu
2021-03-25 12:13 ` Christian Brauner [this message]
2021-03-25 12:21 ` Christian Brauner
2021-03-25 12:40 ` Roberto Sassu
2021-03-25 12:39 ` Roberto Sassu
2021-03-05 15:19 ` [PATCH v4 09/11] ima: Allow imasig requirement to be satisfied by EVM portable signatures Roberto Sassu
2021-03-05 15:19 ` [PATCH v4 10/11] ima: Introduce template field evmsig and write to field sig as fallback Roberto Sassu
2021-03-05 15:19 ` [PATCH v4 11/11] ima: Don't remove security.ima if file must not be appraised Roberto Sassu
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=20210325121341.q2ufjhnqe3osjc7c@wittgenstein \
--to=christian.brauner@ubuntu.com \
--cc=agruenba@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=mjg59@google.com \
--cc=roberto.sassu@huawei.com \
--cc=zohar@linux.ibm.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).